Skip to content

Commit cc9bbfa

Browse files
xiaoyuhengregberge
authored andcommitted
fix: jest --watch fails to reload (#182)
1 parent d2355a1 commit cc9bbfa

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

examples/create-react-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"build": "react-scripts build",
1313
"test": "react-scripts test --env=jsdom",
1414
"test:integration": "jest -c integration/jest.config.js",
15+
"test:integrationWithWatch": "jest -c integration/jest.config.js --watch",
1516
"eject": "react-scripts eject"
1617
},
1718
"devDependencies": {

packages/jest-environment-puppeteer/src/global.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import readConfig from './readConfig'
1111

1212
let browser
1313

14-
export async function setup() {
14+
export async function setup(jestConfig) {
1515
const config = await readConfig()
1616
if (config.connect) {
1717
browser = await puppeteer.connect(config.connect)
@@ -20,6 +20,8 @@ export async function setup() {
2020
}
2121
process.env.PUPPETEER_WS_ENDPOINT = browser.wsEndpoint()
2222

23+
if (jestConfig.watch || jestConfig.watchAll) return
24+
2325
if (config.server) {
2426
try {
2527
await setupServer(config.server)
@@ -49,13 +51,15 @@ export async function setup() {
4951
}
5052
}
5153

52-
export async function teardown() {
53-
await teardownServer()
54-
55-
const config = await readConfig()
56-
if (config.connect) {
57-
await browser.disconnect();
58-
} else {
59-
await browser.close()
54+
export async function teardown(jestConfig) {
55+
if (!jestConfig.watch && !jestConfig.watchAll) {
56+
await teardownServer()
57+
58+
const config = await readConfig()
59+
if (config.connect) {
60+
await browser.disconnect()
61+
} else {
62+
await browser.close()
63+
}
6064
}
6165
}

0 commit comments

Comments
 (0)