Skip to content

Commit

Permalink
fix: jest --watch fails to reload (argos-ci#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyuhen authored and gregberge committed Jan 13, 2019
1 parent d2355a1 commit cc9bbfa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"test:integration": "jest -c integration/jest.config.js",
"test:integrationWithWatch": "jest -c integration/jest.config.js --watch",
"eject": "react-scripts eject"
},
"devDependencies": {
Expand Down
22 changes: 13 additions & 9 deletions packages/jest-environment-puppeteer/src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import readConfig from './readConfig'

let browser

export async function setup() {
export async function setup(jestConfig) {
const config = await readConfig()
if (config.connect) {
browser = await puppeteer.connect(config.connect)
Expand All @@ -20,6 +20,8 @@ export async function setup() {
}
process.env.PUPPETEER_WS_ENDPOINT = browser.wsEndpoint()

if (jestConfig.watch || jestConfig.watchAll) return

if (config.server) {
try {
await setupServer(config.server)
Expand Down Expand Up @@ -49,13 +51,15 @@ export async function setup() {
}
}

export async function teardown() {
await teardownServer()

const config = await readConfig()
if (config.connect) {
await browser.disconnect();
} else {
await browser.close()
export async function teardown(jestConfig) {
if (!jestConfig.watch && !jestConfig.watchAll) {
await teardownServer()

const config = await readConfig()
if (config.connect) {
await browser.disconnect()
} else {
await browser.close()
}
}
}

0 comments on commit cc9bbfa

Please sign in to comment.