-
Notifications
You must be signed in to change notification settings - Fork 331
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
Fix Jest setup/teardown for test server awaiting SIGTERM
#2880
Conversation
5679937
to
9010d5a
Compare
9010d5a
to
9b9241e
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.
Morning @romaricpascal this PR is now ready for review again
@@ -1,6 +1,6 @@ | |||
module.exports = { | |||
browserContext: 'incognito', | |||
dumpio: true, |
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've taken this out as it's supposed to be in launch
so wasn't working. Can be useful for debugging but adds a lot of noise
config/jest/server/start.mjs
Outdated
// Server already running? Wait for exit | ||
if (servers.some(({ signalCode }) => signalCode === 'SIGTERM')) { | ||
await serverStop() | ||
timeout = 0 |
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.
We don't need to wait for the port to open when we know it's just closed
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.
That's probably worth putting a reminder in the code for the future
timeout = 0 | |
// We don't need to wait for the port to open when we know it's just closed | |
timeout = 0 |
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've put the comments together like this:
await serverStop() // Wait for server to stop
timeout = 0 // No need to wait for start
await serverStart() // Wait for web server | ||
await setup() // Open browser | ||
await setup(jestConfig) // Open browser |
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 enables Jest to open multiple Chrome pages, one per worker
@@ -59,8 +59,8 @@ describe('/components/button', () => { | |||
* | |||
* Examples don't do this and we need it to have something to submit | |||
*/ | |||
async function trackClicks () { | |||
page.evaluate(() => { | |||
function trackClicks (page) { |
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.
With (potentially) multiple pages or tabs open at once, we need to pass in which one we use
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.
Sounds great that both the watch and test stepping on each other's tabs will be fixed by that 😄
config/jest/server/start.mjs
Outdated
// Server already running? Wait for exit | ||
if (servers.some(({ signalCode }) => signalCode === 'SIGTERM')) { | ||
await serverStop() | ||
timeout = 0 |
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.
That's probably worth putting a reminder in the code for the future
timeout = 0 | |
// We don't need to wait for the port to open when we know it's just closed | |
timeout = 0 |
b8ca5c5
to
7a08cbb
Compare
This PR fixes an issue with Jest in watch mode:
npx jest --watch src/govuk/components/button/button.test.js
When watching JavaScript component tests project files the array returned via
getServers()
from jest-dev-server appears to list processes that have terminated (or are currently awaiting termination).We should check for
signalCode: 'SIGTERM'
processes before assuming the test site is running