forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnan-spec-runner.js
More file actions
89 lines (77 loc) · 2.87 KB
/
nan-spec-runner.js
File metadata and controls
89 lines (77 loc) · 2.87 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const cp = require('child_process');
const fs = require('fs');
const path = require('path');
const BASE = path.resolve(__dirname, '../..');
const NAN_DIR = path.resolve(BASE, 'third_party', 'nan');
const NPX_CMD = process.platform === 'win32' ? 'npx.cmd' : 'npx';
const utils = require('./lib/utils');
const { YARN_VERSION } = require('./yarn');
if (!process.mainModule) {
throw new Error('Must call the nan spec runner directly');
}
const args = require('minimist')(process.argv.slice(2), {
string: ['only']
});
function getSDKRoot () {
if (process.env.SDKROOT) return process.env.SDKROOT;
const output = cp.execFileSync('xcrun', ['--sdk', 'macosx', '--show-sdk-path']);
return output.toString().trim();
}
async function main () {
const nodeDir = path.resolve(BASE, `out/${utils.getOutDir({ shouldLog: true })}/gen/node_headers`);
const env = Object.assign({}, process.env, {
npm_config_nodedir: nodeDir,
npm_config_msvs_version: '2019',
npm_config_arch: process.env.NPM_CONFIG_ARCH
});
const clangArgs = [];
if (process.platform === 'darwin') {
clangArgs.push('-isysroot', getSDKRoot());
}
clangArgs.push('-std=c++14', '-stdlib=libc++');
if (process.platform !== 'win32') {
env.CC = `"${path.resolve(__dirname, '..', '../third_party/llvm-build/Release+Asserts/bin/clang')}" ${clangArgs.join(' ')}`;
env.CXX = `"${path.resolve(__dirname, '..', '../third_party/llvm-build/Release+Asserts/bin/clang++')}" ${clangArgs.join(' ')}`;
}
const { status: buildStatus } = cp.spawnSync(NPX_CMD, ['node-gyp', 'rebuild', '--directory', 'test', '-j', 'max'], {
env,
cwd: NAN_DIR,
stdio: 'inherit'
});
if (buildStatus !== 0) {
console.error('Failed to build nan test modules');
return process.exit(buildStatus);
}
const { status: installStatus } = cp.spawnSync(NPX_CMD, [`yarn@${YARN_VERSION}`, 'install'], {
env,
cwd: NAN_DIR,
stdio: 'inherit'
});
if (installStatus !== 0) {
console.error('Failed to install nan node_modules');
return process.exit(installStatus);
}
const onlyTests = args.only && args.only.split(',');
const DISABLED_TESTS = ['nannew-test.js'];
const testsToRun = fs.readdirSync(path.resolve(NAN_DIR, 'test', 'js'))
.filter(test => !DISABLED_TESTS.includes(test))
.filter(test => {
return !onlyTests || onlyTests.includes(test) || onlyTests.includes(test.replace('.js', '')) || onlyTests.includes(test.replace('-test.js', ''));
})
.map(test => `test/js/${test}`);
const testChild = cp.spawn(utils.getAbsoluteElectronExec(), ['node_modules/.bin/tap', ...testsToRun], {
env: {
...process.env,
ELECTRON_RUN_AS_NODE: 'true'
},
cwd: NAN_DIR,
stdio: 'inherit'
});
testChild.on('exit', (testCode) => {
process.exit(testCode);
});
}
main().catch((err) => {
console.error('An unhandled error occurred in the nan spec runner', err);
process.exit(1);
});