-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: replace spectron with playwright #4305
Conversation
d7da7e0
to
be0848b
Compare
69b4355
to
41457d6
Compare
41457d6
to
ed4aa13
Compare
9e75651
to
ed4aa13
Compare
Thank you for your thoughts and concerns I hear you and hope to address them to your satisfaction.
Playwright and Spectron are not a 1:1 API match, there are new playwright specific conventions to learn and adapt, and it is unwise to learn and adapt to them as one contributor in a single PR.
The reason this code uses playwright recordings for its runs are to separate any of my personal opinions about test structuring from the replacement effort, while creating an opportunity to revisit existing conventions, I agree the modules were very useful in making readable spectron tests possible, and we will certainly want to pull in some of the ideas with playwright. However I strongly believe the introduction of abstractions over test structure should happen carefully as these tests have a huge impact on the contribution experience, so we have a duty to keep them as lean and fast as possible to maximise return on investment.
Readability is subjective and not something I aim to improve in this PR, only to provide us with a starting point to build confidence in our e2e testing.
We can build on top by writing new tests ourselves on top of this minimal safety net, to show the value of required abstractions. My goal is to eliminate barriers to contribution, to me this means making it intuitive, easy to change and with as little indirection as possible. |
21a796c
to
13e6bfe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking this as approved, seems to work ok, just some minor comments:
- Tests were passing earlier now are failing, I suspect due to a missing click on the
can send requests
scenario - Left some notes of stuff we might want to look at in the future - like spinning up gRPC and Websocket test servers like you did for http, and also we might want to explore tests where we purposely import insomnia data folder that are in a weird state.
@@ -39,7 +39,6 @@ test('can send requests', async ({ playwright }) => { | |||
await electronApp.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text); | |||
|
|||
await page.click('button:has-text("Clipboard")'); | |||
await page.click('text=Smoke tests'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jackkav by removing this the tests seem to be failing now, since playwright can't open the collection to try and issue the requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can confirm this locally as well, adding this line back in makes the test pass for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was seeing import from clipboard go straight to the send request view, so I assumed it had been changed in a recent PR after rebase. Not sure though.
@@ -61,6 +61,12 @@ jobs: | |||
- name: Run tests | |||
run: npm test | |||
|
|||
- name: Build app for smoke tests | |||
run: npm run app-build:smoke |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To pick on something @dimitropoulos had mentioned a while back, I think we could just try and also change the commands both here and in the package.json
to something that is more readable and simpler.
Related to this ticket: https://linear.app/insomnia/issue/INS-1276/improve-npm-script-experience
Perhaps reducing all our smoke commands to just 2, something like npm run smoke:build
and npm run smoke:test
? (Not sure about the naming though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in so many places in the code base and meant to exist alongside many other contexts so I'll scope it out for now, but worth a later PR to look for ways to clarify the wording of app-build:smoke
and test:smoke:build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this to try and increase clarity! There are a few variations hence the confusion:
- build the app
- build the app for smoke tests
- package the app
- package the app for smoke tests
- run smoke tests against build artifacts
- run smoke tests against the packaged binaries
Building the app is faster than packaging the app. But certain things (such as testing plugin installation) requires the test to be run against a packaged binary instead of build artifacts. Testing against the packaged app is also more realistic, so it's just weighing up the pros and cons.
Additionally, the first four bulletpoints can become two bulletpoints if we can remove/address the requirement for a gitref in the build script:
insomnia/packages/insomnia-app/scripts/getBuildContext.ts
Lines 38 to 51 in 5f4c19d
export const getBuildContext = (forceFromGitRef: boolean) => { | |
if (forceFromGitRef) { | |
return fromGitRef(); | |
} | |
if (process.env.SMOKE_TEST) { | |
return { | |
smokeTest: true, | |
version: '0.0.1', | |
} as const; | |
} | |
return fromGitRef(); | |
}; |
/* eslint-disable filenames/match-exported */ | ||
import { PlaywrightTestConfig } from '@playwright/test'; | ||
const config: PlaywrightTestConfig = { | ||
webServer: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same opinion as @develohpanda on this, this is awesome. There's probably a way for us to mimic this and add one for gRPC, and later on websockets , etc. Really cool stuff 👍
}; | ||
|
||
test('can send requests', async ({ playwright }) => { | ||
const options = { INSOMNIA_DATA_PATH: randomDataPath() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is giving me an idea - let's say we get a bug that is only reproducible with someone's backup of a data folder, we could make it so folks can point to a data path for the test they want to run - which we would fetch locally or maybe download from S3 bucket where we store weird data folder backups.
await electronApp.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text); | ||
|
||
await page.click('button:has-text("Clipboard")'); | ||
await page.click('button:has-text("GETsend JSON request")'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if my other comment will be visible, but here we're missing the step before this one where we click to open the collection after importing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 👍
Found two remaining references to Spectron, not sure if we have the same issue with the tsconfig
with Playwright as we did for Spectron?
"skipLibCheck": true, // this is required because spectron depends on electron but it is not locatable by typescript for the purpose of types |
Line 60 in b2c94eb
to write our unit tests, and [Spectron](https://www.electronjs.org/spectron) for integration tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your thoughts as well! Readability is subjective but readability helps with code reviews, and while the contribution experience is important, maintainability is also important when tests break and someone goes in with fresh eyes, and over time I hope we can reach a balance between all of these factors.
One action item: could you please make follow-up tasks to go to the existing smoke tests and migrate many of the assertions across?
For example, the PDF viewer assertion, or the XML filter assertion are both regression tests and we shouldn't lose those learnings.
insomnia/packages/insomnia-smoke-test/core/app.test.ts
Lines 81 to 94 in b2c94eb
await debug.expect200(app); | |
const responseViewer = await debug.getResponseViewer(app); | |
const partialExpectedResponse = '<LoginResult>xxx-777-xxx-123</LoginResult>'; | |
await debug.expectContainsText(responseViewer, partialExpectedResponse); | |
await debug.typeInResponseFilter(app, "//*[local-name(.)='LoginResult']/text()"); | |
await waitUntilTextDisappears(app, responseViewer, partialExpectedResponse); | |
await debug.expectContainsText( | |
responseViewer, | |
'<result>xxx-777-xxx-123</result>', | |
); |
Another example is the Basic Auth test. Instead of simply testing basic auth works through a header, it's purpose is to use the Auth tab within Insomnia to simulate a user typing into the fields, enabling and disabling auth and verifying the expected response.
tl;dr through this PR we lose a lot of coverage, and we should make an effort to bring across the existing tests once this has merged to reinstate that coverage, hence follow-up tasks.
Related: electron-userland/spectron#1045
The primary goal of this PR is to unblock our electron upgrade PR #4232 which is blocked by spectron flaking out on windows and blocking future upgrades due to its deprecation.
Improvements
Scoped out
Notes:
users who may have been using the undocumented env var INSOMNIA_DATA_PATH may get logged out because of the setPath fallback used for controlling migration context.broke this out into a separate issueConsidered in this scope
Closes INS-1300
Closes INS-1147