-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WNMGDS-2722] New browser testing wrapper script (#3006)
* Start to a wrapper script for browser tests * This is readable, but using exec crashes because the buffer fills up Really I need to use spawn, but that means all my args need to be in array form * This works! * Build prereqs first unless `--no-build` is passed * Update all the browser test commands Updating any of these is as simple as passing `-u` now. We can even use one of these aliases and pass `--no-docker` to it, like `yarn test:browser:examples --no-docker`, and it will work * Update the unit test commands to match * Rewrite the README content on browser testingRewrite the README content on browser testingRewrite the README content on browser testingRewrite the README content on browser testingRewrite the README content on browser testingRewrite the README content on browser testingRewrite the README content on browser testingRewrite the README content on browser testingRewrite the README content on browser testing * Add an example debug command
- Loading branch information
Showing
5 changed files
with
131 additions
and
35 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
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,90 @@ | ||
import yargs from 'yargs'; | ||
import { hideBin } from 'yargs/helpers'; | ||
import { sh, shI } from './utils'; | ||
|
||
const DOCKER_IMAGE = 'mcr.microsoft.com/playwright:v1.31.0-focal'; | ||
|
||
function verifyPlaywrightInstalled() { | ||
try { | ||
sh('yarn playwright --version'); | ||
} catch (error) { | ||
console.log('Playwright command is unavailable. Install it with `npx playwright install`.'); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
(async () => { | ||
// Get command line args | ||
const argv = await yargs(hideBin(process.argv)) | ||
.scriptName('yarn test:browser') | ||
.parserConfiguration({ 'unknown-options-as-args': true }) | ||
.options({ | ||
// Note that you can negate it with --no-build | ||
build: { | ||
boolean: true, | ||
description: 'Builds storybook first', | ||
default: true, | ||
}, | ||
config: { | ||
string: true, | ||
description: 'Path to Playwright config file', | ||
default: 'tests/browser/playwright.config.ts', | ||
}, | ||
docker: { | ||
boolean: true, | ||
description: 'Runs tests inside Playwright Docker container', | ||
default: true, | ||
}, | ||
smoke: { | ||
boolean: true, | ||
description: 'Runs only the smoke tests', | ||
default: false, | ||
}, | ||
}) | ||
.help().argv; | ||
|
||
// Build whatever is necessary to run these tests | ||
if (argv.build) { | ||
if (argv.config.includes('examples.config.ts')) { | ||
shI('yarn', ['build:examples']); | ||
} else { | ||
shI('yarn', ['build:storybook']); | ||
} | ||
} | ||
|
||
// Create the array of args for the playwright command | ||
const configArgs = ['--config', argv.config]; | ||
const extraArgs = argv._.map((v) => '' + v); | ||
const playwrightArgs = ['test', ...configArgs, ...extraArgs]; | ||
|
||
if (argv.docker) { | ||
// Create the array of args for the docker command | ||
const dockerArgs = [ | ||
...['run', '--rm', '--network', 'host', '-v', `${process.cwd()}:/work/`, '-w', '/work/'], | ||
// Environment vars need to be passed to the docker container | ||
...(argv.smoke ? ['--env', 'SMOKE=true'] : []), | ||
DOCKER_IMAGE, | ||
...['yarn', 'playwright', ...playwrightArgs], | ||
]; | ||
|
||
// And run docker | ||
shI('docker', dockerArgs); | ||
} else { | ||
// To run outside of docker, we need to have Playwright installed separately | ||
verifyPlaywrightInstalled(); | ||
|
||
// Environment vars need to be passed to the spawned process through the config object | ||
let config; | ||
if (argv.smoke) { | ||
config = { | ||
env: { | ||
...process.env, | ||
SMOKE: 'true', | ||
}, | ||
}; | ||
} | ||
|
||
// Run Playwright directly through yarn | ||
shI('yarn', ['playwright', ...playwrightArgs], config); | ||
} | ||
})(); |
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