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