node-spec-runner.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const cp = require('child_process');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const BASE = path.resolve(__dirname, '../..');
  5. const NODE_DIR = path.resolve(BASE, 'third_party', 'electron_node');
  6. const NPX_CMD = process.platform === 'win32' ? 'npx.cmd' : 'npx';
  7. const JUNIT_DIR = process.argv[2] ? path.resolve(process.argv[2]) : null;
  8. const TAP_FILE_NAME = 'test.tap';
  9. const utils = require('./lib/utils');
  10. const { YARN_VERSION } = require('./yarn');
  11. if (!process.mainModule) {
  12. throw new Error('Must call the node spec runner directly');
  13. }
  14. async function main () {
  15. const DISABLED_TESTS = require('./node-disabled-tests.json');
  16. const testChild = cp.spawn('python', ['tools/test.py', '--verbose', '-p', 'tap', '--logfile', TAP_FILE_NAME, '--mode=debug', 'default', `--skip-tests=${DISABLED_TESTS.join(',')}`, '--shell', utils.getAbsoluteElectronExec(), '-J'], {
  17. env: {
  18. ...process.env,
  19. ELECTRON_RUN_AS_NODE: 'true'
  20. },
  21. cwd: NODE_DIR,
  22. stdio: 'inherit'
  23. });
  24. testChild.on('exit', (testCode) => {
  25. if (JUNIT_DIR) {
  26. fs.mkdirSync(JUNIT_DIR);
  27. const converterStream = require('tap-xunit')();
  28. fs.createReadStream(
  29. path.resolve(NODE_DIR, TAP_FILE_NAME)
  30. ).pipe(converterStream).pipe(
  31. fs.createWriteStream(path.resolve(JUNIT_DIR, 'nodejs.xml'))
  32. ).on('close', () => {
  33. process.exit(testCode);
  34. });
  35. }
  36. });
  37. }
  38. main().catch((err) => {
  39. console.error('An unhandled error occurred in the node spec runner', err);
  40. process.exit(1);
  41. });