| 1 |
const { spawn, exec } = require( 'child_process' ); |
| 2 |
const packageJson = require( './package.json' ); |
| 3 |
|
| 4 |
function isDockerExist() { |
| 5 |
return new Promise( ( resolve ) => { |
| 6 |
exec( 'docker -v', ( error ) => { |
| 7 |
resolve( ! error ); |
| 8 |
} ); |
| 9 |
} ); |
| 10 |
} |
| 11 |
|
| 12 |
async function run( tag ) { |
| 13 |
const playwrightVersion = packageJson.devDependencies[ '@playwright/test' ]; |
| 14 |
const workingDir = process.cwd(); |
| 15 |
|
| 16 |
const command = 'docker run'; |
| 17 |
const options = [ |
| 18 |
'--rm', |
| 19 |
'--network host', |
| 20 |
`--volume ${ workingDir }:/work`, |
| 21 |
'--workdir /work/', |
| 22 |
'--interactive', |
| 23 |
process.env.CI ? '' : '--tty', |
| 24 |
]; |
| 25 |
const image = `mcr.microsoft.com/playwright:v${ playwrightVersion.replace( '^', '' ) }-jammy`; |
| 26 |
const commandToRun = `/bin/bash -c "npm run test:playwright -- --grep="${ tag }""`; |
| 27 |
|
| 28 |
spawn( `${ command } ${ options.join( ' ' ) } ${ image } ${ commandToRun }`, { |
| 29 |
stdio: 'inherit', |
| 30 |
stderr: 'inherit', |
| 31 |
shell: true, |
| 32 |
} ); |
| 33 |
} |
| 34 |
|
| 35 |
( async () => { |
| 36 |
if ( ! await isDockerExist() ) { |
| 37 |
// eslint-disable-next-line no-console |
| 38 |
console.error( 'Docker is not installed, please install it first.' ); |
| 39 |
|
| 40 |
process.exit( 1 ); |
| 41 |
} |
| 42 |
|
| 43 |
await run( process.argv.slice( 2 ) ); |
| 44 |
} )(); |
| 45 |
|