run-tests.js 1.12 KB
Newer Older
1
/* eslint-disable no-console */
偏右's avatar
偏右 committed
2 3 4 5 6
const { spawn } = require('child_process');
const { kill } = require('cross-port-killer');

const env = Object.create(process.env);
env.BROWSER = 'none';
sorrycc's avatar
sorrycc committed
7
env.TEST = true;
8 9 10
// flag to prevent multiple test
let once = false;

偏右's avatar
偏右 committed
11
const startServer = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['start'], {
偏右's avatar
偏右 committed
12 13 14
  env,
});

jim's avatar
jim committed
15
startServer.stderr.on('data', data => {
偏右's avatar
偏右 committed
16
  // eslint-disable-next-line
afc163's avatar
afc163 committed
17
  console.log(data.toString());
偏右's avatar
偏右 committed
18 19 20 21 22 23 24
});

startServer.on('exit', () => {
  kill(process.env.PORT || 8000);
});

console.log('Starting development server for e2e tests...');
jim's avatar
jim committed
25
startServer.stdout.on('data', data => {
afc163's avatar
afc163 committed
26
  console.log(data.toString());
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
27
  if (!once && data.toString().indexOf('Compiled successfully') >= 0) {
偏右's avatar
偏右 committed
28
    // eslint-disable-next-line
29
    once = true;
偏右's avatar
偏右 committed
30
    console.log('Development server is started, ready to run tests.');
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
31 32
    const testCmd = spawn(
      /^win/.test(process.platform) ? 'npm.cmd' : 'npm',
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
33
      ['test', '--', '--maxWorkers=1', '--runInBand'],
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
34 35 36 37
      {
        stdio: 'inherit',
      }
    );
jim's avatar
jim committed
38
    testCmd.on('exit', code => {
偏右's avatar
偏右 committed
39
      startServer.kill();
jim's avatar
jim committed
40
      process.exit(code);
偏右's avatar
偏右 committed
41 42 43
    });
  }
});