Repository: electron/electron
File: script/nan-spec-runner.js (JavaScript)

Code before:
  const nodeGypVersion = getNodeGypVersion();
  const { status: buildStatus, signal } = cp.spawnSync(NPX_CMD, [`node-gyp@${nodeGypVersion}`, 'rebuild', '--verbose', '--directory', 'test', '-j', 'max'], {
    env,
    cwd: NAN_DIR,
    stdio: 'inherit',
    shell: process.platform === 'win32'
  });

  if (buildStatus !== 0 || signal != null) {
    console.error('Failed to build nan test modules');
    return process.exit(buildStatus !== 0 ? buildStatus : signal);
  }

  const { status: installStatus } = cp.spawnSync(NPX_CMD, [`yarn@${YARN_VERSION}`, 'install'], {
    env,
    cwd: NAN_DIR,
    stdio: 'inherit',
    shell: process.platform === 'win32'
  });

  if (installStatus !== 0 || signal != null) {
    console.error('Failed to install nan node_modules');
    return process.exit(installStatus !== 0 ? installStatus : signal);
  }

  const onlyTests = args?.only.split(',');

  const DISABLED_TESTS = new Set([
    'nannew-test.js',
    'buffer-test.js',
    // we can't patch this test because it uses CRLF line endings
    'methodswithdata-test.js',
    // these two are incompatible with crrev.com/c/4733273
    'weak-test.js',
    'weak2-test.js'
  ]);
  const testsToRun = fs.readdirSync(path.resolve(NAN_DIR, 'test', 'js'))
    .filter(test => !DISABLED_TESTS.has(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'
  });

Review comment (bug):
```suggestion
  const onlyTests = args.only?.split(',');
```

Think the question mark migrated a little too far left, CI is failing on this line.

Code after:
  const nodeGypVersion = getNodeGypVersion();
  const { status: buildStatus, signal } = cp.spawnSync(NPX_CMD, [`node-gyp@${nodeGypVersion}`, 'rebuild', '--verbose', '--directory', 'test', '-j', 'max'], {
    env,
    cwd: NAN_DIR,
    stdio: 'inherit',
    shell: process.platform === 'win32'
  });

  if (buildStatus !== 0 || signal != null) {
    console.error('Failed to build nan test modules');
    return process.exit(buildStatus !== 0 ? buildStatus : signal);
  }

  const { status: installStatus } = cp.spawnSync(NPX_CMD, [`yarn@${YARN_VERSION}`, 'install'], {
    env,
    cwd: NAN_DIR,
    stdio: 'inherit',
    shell: process.platform === 'win32'
  });

  if (installStatus !== 0 || signal != null) {
    console.error('Failed to install nan node_modules');
    return process.exit(installStatus !== 0 ? installStatus : signal);
  }

  const onlyTests = args.only?.split(',');

  const DISABLED_TESTS = new Set([
    'nannew-test.js',
    'buffer-test.js',
    // we can't patch this test because it uses CRLF line endings
    'methodswithdata-test.js',
    // these two are incompatible with crrev.com/c/4733273
    'weak-test.js',
    'weak2-test.js'
  ]);
  const testsToRun = fs.readdirSync(path.resolve(NAN_DIR, 'test', 'js'))
    .filter(test => !DISABLED_TESTS.has(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'
  });