2020-03-20 20:28:31 +00:00
|
|
|
const cp = require('child_process');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2019-07-23 18:40:06 +00:00
|
|
|
|
2020-02-21 20:19:25 +00:00
|
|
|
const args = require('minimist')(process.argv.slice(2), {
|
|
|
|
boolean: ['default'],
|
|
|
|
string: ['jUnitDir']
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2020-02-21 20:19:25 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const BASE = path.resolve(__dirname, '../..');
|
|
|
|
const DISABLED_TESTS = require('./node-disabled-tests.json');
|
|
|
|
const NODE_DIR = path.resolve(BASE, 'third_party', 'electron_node');
|
|
|
|
const JUNIT_DIR = args.jUnitDir ? path.resolve(args.jUnitDir) : null;
|
|
|
|
const TAP_FILE_NAME = 'test.tap';
|
2019-07-23 18:40:06 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const utils = require('./lib/utils');
|
2019-07-23 18:40:06 +00:00
|
|
|
|
|
|
|
if (!process.mainModule) {
|
2020-03-20 20:28:31 +00:00
|
|
|
throw new Error('Must call the node spec runner directly');
|
2019-07-23 18:40:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 20:19:25 +00:00
|
|
|
const defaultOptions = [
|
|
|
|
'tools/test.py',
|
|
|
|
'-p',
|
|
|
|
'tap',
|
|
|
|
'--logfile',
|
|
|
|
TAP_FILE_NAME,
|
|
|
|
'--mode=debug',
|
|
|
|
'default',
|
|
|
|
`--skip-tests=${DISABLED_TESTS.join(',')}`,
|
2022-06-20 19:54:52 +00:00
|
|
|
'--flaky-tests=dontcare',
|
2020-02-21 20:19:25 +00:00
|
|
|
'--shell',
|
|
|
|
utils.getAbsoluteElectronExec(),
|
|
|
|
'-J'
|
2020-03-20 20:28:31 +00:00
|
|
|
];
|
2020-02-21 20:19:25 +00:00
|
|
|
|
|
|
|
const getCustomOptions = () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let customOptions = ['tools/test.py'];
|
2020-02-21 20:19:25 +00:00
|
|
|
|
|
|
|
// Add all custom arguments.
|
2020-03-20 20:28:31 +00:00
|
|
|
const extra = process.argv.slice(2);
|
2020-02-21 20:19:25 +00:00
|
|
|
if (extra) {
|
2020-03-20 20:28:31 +00:00
|
|
|
customOptions = customOptions.concat(extra);
|
2020-02-21 20:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We need this unilaterally or Node.js will try
|
|
|
|
// to run from out/Release/node.
|
|
|
|
customOptions = customOptions.concat([
|
|
|
|
'--shell',
|
|
|
|
utils.getAbsoluteElectronExec()
|
2020-03-20 20:28:31 +00:00
|
|
|
]);
|
2020-02-21 20:19:25 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
return customOptions;
|
|
|
|
};
|
2020-02-21 20:19:25 +00:00
|
|
|
|
2019-07-23 18:40:06 +00:00
|
|
|
async function main () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const options = args.default ? defaultOptions : getCustomOptions();
|
2019-07-23 18:40:06 +00:00
|
|
|
|
2022-05-10 21:26:53 +00:00
|
|
|
const testChild = cp.spawn('python3', options, {
|
2019-07-23 18:40:06 +00:00
|
|
|
env: {
|
|
|
|
...process.env,
|
2020-01-15 07:07:03 +00:00
|
|
|
ELECTRON_RUN_AS_NODE: 'true',
|
|
|
|
ELECTRON_EAGER_ASAR_HOOK_FOR_TESTING: 'true'
|
2019-07-23 18:40:06 +00:00
|
|
|
},
|
|
|
|
cwd: NODE_DIR,
|
|
|
|
stdio: 'inherit'
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-07-23 18:40:06 +00:00
|
|
|
testChild.on('exit', (testCode) => {
|
2019-07-23 20:00:02 +00:00
|
|
|
if (JUNIT_DIR) {
|
2020-03-20 20:28:31 +00:00
|
|
|
fs.mkdirSync(JUNIT_DIR);
|
|
|
|
const converterStream = require('tap-xunit')();
|
2019-07-23 20:00:02 +00:00
|
|
|
fs.createReadStream(
|
|
|
|
path.resolve(NODE_DIR, TAP_FILE_NAME)
|
|
|
|
).pipe(converterStream).pipe(
|
|
|
|
fs.createWriteStream(path.resolve(JUNIT_DIR, 'nodejs.xml'))
|
|
|
|
).on('close', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
process.exit(testCode);
|
|
|
|
});
|
2019-07-23 20:00:02 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-07-23 18:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((err) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.error('An unhandled error occurred in the node spec runner', err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|