-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: enable watch mode for puppeteer tests
- Loading branch information
Showing
7 changed files
with
120 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ module.exports = { | |
launch: { | ||
dumpio: debug, | ||
headless: !debug, | ||
timeout: 120000, | ||
}, | ||
browser, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,6 @@ | ||
import { Config } from '@jest/types'; | ||
import { JestDevServerOptions, setup as setupDevServer } from 'jest-dev-server'; | ||
|
||
const { setup: setupPuppeteer } = require('jest-environment-puppeteer'); | ||
const { STORYBOOK_ONLY } = process.env; | ||
import { startServer } from './puppeteer'; | ||
|
||
export default async function globalSetup(globalConfig: Config.GlobalConfig) { | ||
const servers: JestDevServerOptions[] = [ | ||
{ | ||
command: 'yarn storybook:ci', | ||
port: 3002, | ||
usedPortAction: 'kill', | ||
launchTimeout: 60000, | ||
}, | ||
]; | ||
if (!STORYBOOK_ONLY) { | ||
servers.push( | ||
{ | ||
command: 'yarn next:ci', | ||
port: 3001, | ||
usedPortAction: 'kill', | ||
launchTimeout: 60000, | ||
}, | ||
{ | ||
command: 'yarn dev:docs', | ||
port: 3000, | ||
usedPortAction: 'kill', | ||
launchTimeout: 60000, | ||
}, | ||
); | ||
} | ||
await setupDevServer(servers); | ||
|
||
await setupPuppeteer(globalConfig); | ||
await startServer(globalConfig); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import { Config } from '@jest/types'; | ||
import { teardown as teardownDevServer } from 'jest-dev-server'; | ||
|
||
const { teardown: teardownPuppeteer } = require('jest-environment-puppeteer'); | ||
import { destroyServer } from './puppeteer'; | ||
|
||
export default async function globalTeardown(globalConfig: Config.GlobalConfig) { | ||
await teardownDevServer(); | ||
await teardownPuppeteer(globalConfig); | ||
await destroyServer(globalConfig); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Config } from '@jest/types'; | ||
import { JestDevServerOptions, setup, teardown } from 'jest-dev-server'; | ||
import onExit from 'signal-exit'; | ||
|
||
const { teardown: teardownPuppeteer } = require('jest-environment-puppeteer'); | ||
|
||
const { setup: setupPuppeteer } = require('jest-environment-puppeteer'); | ||
const { PUPPETEER_SERVERS } = process.env; | ||
|
||
type Server = 'next' | 'storybook' | 'docz'; | ||
|
||
const servers: Server[] = (PUPPETEER_SERVERS | ||
? PUPPETEER_SERVERS.split(',') | ||
: ['next', 'storybook', 'docz']) as any; | ||
|
||
const serverConfig: Record<Server, JestDevServerOptions> = { | ||
storybook: { | ||
command: 'yarn storybook:ci', | ||
port: 3002, | ||
usedPortAction: 'kill', | ||
launchTimeout: 60000, | ||
}, | ||
next: { | ||
command: 'yarn next:ci', | ||
port: 3001, | ||
usedPortAction: 'kill', | ||
launchTimeout: 60000, | ||
}, | ||
docz: { | ||
command: 'yarn dev:docs', | ||
port: 3000, | ||
usedPortAction: 'kill', | ||
launchTimeout: 60000, | ||
}, | ||
}; | ||
|
||
let serverSetupPromise: Promise<void> | undefined; | ||
|
||
export async function setupServer(globalConfig: Config.GlobalConfig) { | ||
await setup(servers.map(server => serverConfig[server])); | ||
|
||
onExit(() => | ||
Promise.all([teardown(), teardownPuppeteer()]).then(() => { | ||
process.exit(); | ||
}), | ||
); | ||
|
||
await setupPuppeteer(globalConfig); | ||
} | ||
|
||
export async function startServer(globalConfig: Config.GlobalConfig) { | ||
if (serverSetupPromise) { | ||
return serverSetupPromise; | ||
} else { | ||
serverSetupPromise = setupServer(globalConfig); | ||
return serverSetupPromise; | ||
} | ||
} | ||
export async function destroyServer(globalConfig: Config.GlobalConfig) { | ||
serverSetupPromise = undefined; | ||
await teardown(); | ||
await teardownPuppeteer(globalConfig); | ||
} |