2020-03-20 20:28:31 +00:00
|
|
|
const cp = require('child_process');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2019-05-29 19:38:17 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const BASE = path.resolve(__dirname, '../..');
|
|
|
|
const NAN_DIR = path.resolve(BASE, 'third_party', 'nan');
|
|
|
|
const NPX_CMD = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
2019-05-29 19:38:17 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const utils = require('./lib/utils');
|
|
|
|
const { YARN_VERSION } = require('./yarn');
|
2019-05-29 19:38:17 +00:00
|
|
|
|
|
|
|
if (!process.mainModule) {
|
2020-03-20 20:28:31 +00:00
|
|
|
throw new Error('Must call the nan spec runner directly');
|
2019-05-29 19:38:17 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 23:37:14 +00:00
|
|
|
const args = require('minimist')(process.argv.slice(2), {
|
|
|
|
string: ['only']
|
|
|
|
});
|
|
|
|
|
2019-05-29 19:38:17 +00:00
|
|
|
async function main () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const nodeDir = path.resolve(BASE, `out/${utils.getOutDir({ shouldLog: true })}/gen/node_headers`);
|
2019-05-29 19:38:17 +00:00
|
|
|
const env = Object.assign({}, process.env, {
|
|
|
|
npm_config_nodedir: nodeDir,
|
2019-10-28 22:12:35 +00:00
|
|
|
npm_config_msvs_version: '2019',
|
2020-11-24 05:26:54 +00:00
|
|
|
npm_config_arch: process.env.NPM_CONFIG_ARCH,
|
|
|
|
npm_config_yes: 'true'
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2020-09-21 23:37:14 +00:00
|
|
|
const { status: buildStatus } = cp.spawnSync(NPX_CMD, ['node-gyp', 'rebuild', '--directory', 'test', '-j', 'max'], {
|
2019-05-29 19:38:17 +00:00
|
|
|
env,
|
|
|
|
cwd: NAN_DIR,
|
|
|
|
stdio: 'inherit'
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-05-29 19:38:17 +00:00
|
|
|
if (buildStatus !== 0) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.error('Failed to build nan test modules');
|
|
|
|
return process.exit(buildStatus);
|
2019-05-29 19:38:17 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 23:30:39 +00:00
|
|
|
const { status: installStatus } = cp.spawnSync(NPX_CMD, [`yarn@${YARN_VERSION}`, 'install'], {
|
2019-05-29 19:38:17 +00:00
|
|
|
env,
|
|
|
|
cwd: NAN_DIR,
|
|
|
|
stdio: 'inherit'
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-05-29 19:38:17 +00:00
|
|
|
if (installStatus !== 0) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.error('Failed to install nan node_modules');
|
|
|
|
return process.exit(installStatus);
|
2019-05-29 19:38:17 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 23:37:14 +00:00
|
|
|
const onlyTests = args.only && args.only.split(',');
|
|
|
|
|
2021-03-26 22:34:57 +00:00
|
|
|
const DISABLED_TESTS = [
|
|
|
|
'nannew-test.js',
|
|
|
|
'typedarrays-test.js' // TODO(nornagon): https://github.com/electron/electron/issues/28414
|
|
|
|
];
|
2019-05-29 19:38:17 +00:00
|
|
|
const testsToRun = fs.readdirSync(path.resolve(NAN_DIR, 'test', 'js'))
|
|
|
|
.filter(test => !DISABLED_TESTS.includes(test))
|
2020-09-21 23:37:14 +00:00
|
|
|
.filter(test => {
|
|
|
|
return !onlyTests || onlyTests.includes(test) || onlyTests.includes(test.replace('.js', '')) || onlyTests.includes(test.replace('-test.js', ''));
|
|
|
|
})
|
2020-03-20 20:28:31 +00:00
|
|
|
.map(test => `test/js/${test}`);
|
2019-05-29 19:38:17 +00:00
|
|
|
|
|
|
|
const testChild = cp.spawn(utils.getAbsoluteElectronExec(), ['node_modules/.bin/tap', ...testsToRun], {
|
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
ELECTRON_RUN_AS_NODE: 'true'
|
|
|
|
},
|
|
|
|
cwd: NAN_DIR,
|
|
|
|
stdio: 'inherit'
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-05-29 19:38:17 +00:00
|
|
|
testChild.on('exit', (testCode) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
process.exit(testCode);
|
|
|
|
});
|
2019-05-29 19:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((err) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.error('An unhandled error occurred in the nan spec runner', err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|