2020-04-02 13:41:06 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const { spawnSync } = require( 'child_process' );
|
|
|
|
const program = require( 'commander' );
|
|
|
|
const path = require( 'path' );
|
|
|
|
const fs = require( 'fs' );
|
|
|
|
const getAppPath = require( '../utils/app-root' );
|
|
|
|
|
|
|
|
program
|
|
|
|
.usage( '<file ...> [options]' )
|
|
|
|
.option( '--dev', 'Development mode' )
|
|
|
|
.parse( process.argv );
|
|
|
|
|
2020-04-15 17:07:32 +00:00
|
|
|
const appPath = getAppPath();
|
|
|
|
|
|
|
|
const nodeConfigDirs = [
|
|
|
|
path.resolve( __dirname, '../config' ),
|
|
|
|
];
|
|
|
|
|
|
|
|
if ( appPath ) {
|
|
|
|
nodeConfigDirs.unshift(
|
2020-04-28 20:14:11 +00:00
|
|
|
path.resolve( appPath, 'tests/e2e/config' )
|
2020-04-15 17:07:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-02 13:41:06 +00:00
|
|
|
const testEnvVars = {
|
2020-04-29 14:22:11 +00:00
|
|
|
NODE_ENV: 'test-e2e',
|
2020-04-02 13:41:06 +00:00
|
|
|
JEST_PUPPETEER_CONFIG: path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../config/jest-puppeteer.config.js'
|
|
|
|
),
|
2020-04-15 17:07:32 +00:00
|
|
|
NODE_CONFIG_DIR: nodeConfigDirs.join( ':' ),
|
2020-05-04 17:37:25 +00:00
|
|
|
node_config_dev: program.dev ? 'yes' : 'no',
|
2020-05-05 16:56:00 +00:00
|
|
|
jest_test_timeout: program.dev ? 120000 : 30000,
|
2020-04-02 13:41:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let jestCommand = 'jest';
|
|
|
|
const jestArgs = [
|
|
|
|
'--maxWorkers=1',
|
|
|
|
'--rootDir=./',
|
|
|
|
'--verbose',
|
|
|
|
...program.args,
|
|
|
|
];
|
|
|
|
|
|
|
|
if ( program.dev ) {
|
|
|
|
jestCommand = 'npx';
|
|
|
|
jestArgs.unshift( 'ndb', 'jest' );
|
|
|
|
}
|
|
|
|
|
|
|
|
const envVars = Object.assign( {}, process.env, testEnvVars );
|
|
|
|
|
|
|
|
let configPath = path.resolve( __dirname, '../config/jest.config.js' );
|
|
|
|
|
|
|
|
// Look for a Jest config in the dependent app's path.
|
|
|
|
if ( appPath ) {
|
2020-04-28 20:14:11 +00:00
|
|
|
const appConfig = path.resolve( appPath, 'tests/e2e/config/jest.config.js' );
|
2020-04-02 13:41:06 +00:00
|
|
|
|
|
|
|
if ( fs.existsSync( appConfig ) ) {
|
|
|
|
configPath = appConfig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jestArgs.push( '--config=' + configPath );
|
|
|
|
|
|
|
|
const jestProcess = spawnSync(
|
|
|
|
jestCommand,
|
|
|
|
jestArgs,
|
|
|
|
{
|
|
|
|
stdio: 'inherit',
|
|
|
|
env: envVars,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log( 'Jest exit code: ' + jestProcess.status );
|
|
|
|
|
|
|
|
// Pass Jest exit code to npm
|
|
|
|
process.exit( jestProcess.status );
|