nan-spec-runner.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const cp = require('child_process');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const BASE = path.resolve(__dirname, '../..');
  5. const NAN_DIR = path.resolve(BASE, 'third_party', 'nan');
  6. const NPX_CMD = process.platform === 'win32' ? 'npx.cmd' : 'npx';
  7. const utils = require('./lib/utils');
  8. const { YARN_VERSION } = require('./yarn');
  9. if (!process.mainModule) {
  10. throw new Error('Must call the nan spec runner directly');
  11. }
  12. async function main () {
  13. const nodeDir = path.resolve(BASE, `out/${utils.OUT_DIR}/gen/node_headers`);
  14. const env = Object.assign({}, process.env, {
  15. npm_config_nodedir: nodeDir,
  16. npm_config_msvs_version: '2017',
  17. npm_config_arch: process.env.NPM_CONFIG_ARCH
  18. });
  19. const { status: buildStatus } = cp.spawnSync(NPX_CMD, ['node-gyp', 'rebuild', '--directory', 'test'], {
  20. env,
  21. cwd: NAN_DIR,
  22. stdio: 'inherit'
  23. });
  24. if (buildStatus !== 0) {
  25. console.error('Failed to build nan test modules');
  26. return process.exit(buildStatus);
  27. }
  28. const { status: installStatus } = cp.spawnSync(NPX_CMD, [`yarn@${YARN_VERSION}`, 'install'], {
  29. env,
  30. cwd: NAN_DIR,
  31. stdio: 'inherit'
  32. });
  33. if (installStatus !== 0) {
  34. console.error('Failed to install nan node_modules');
  35. return process.exit(installStatus);
  36. }
  37. const DISABLED_TESTS = ['nannew-test.js'];
  38. const testsToRun = fs.readdirSync(path.resolve(NAN_DIR, 'test', 'js'))
  39. .filter(test => !DISABLED_TESTS.includes(test))
  40. .map(test => `test/js/${test}`);
  41. const testChild = cp.spawn(utils.getAbsoluteElectronExec(), ['node_modules/.bin/tap', ...testsToRun], {
  42. env: {
  43. ...process.env,
  44. ELECTRON_RUN_AS_NODE: 'true'
  45. },
  46. cwd: NAN_DIR,
  47. stdio: 'inherit'
  48. });
  49. testChild.on('exit', (testCode) => {
  50. process.exit(testCode);
  51. });
  52. }
  53. main().catch((err) => {
  54. console.error('An unhandled error occurred in the nan spec runner', err);
  55. process.exit(1);
  56. });