run-tests.js 1.05 KB
Newer Older
偏右's avatar
偏右 committed
1 2 3 4 5
const { spawn } = require('child_process');
const { kill } = require('cross-port-killer');

const env = Object.create(process.env);
env.BROWSER = 'none';
偏右's avatar
偏右 committed
6
const startServer = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['start'], {
偏右's avatar
偏右 committed
7 8 9
  env,
});

jim's avatar
jim committed
10
startServer.stderr.on('data', data => {
偏右's avatar
偏右 committed
11 12 13 14 15 16 17 18 19 20
  // eslint-disable-next-line
  console.log(data);
});

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

// eslint-disable-next-line
console.log('Starting development server for e2e tests...');
jim's avatar
jim committed
21
startServer.stdout.on('data', data => {
afc163's avatar
afc163 committed
22 23
  // eslint-disable-next-line
  console.log(data.toString());
jim's avatar
jim committed
24 25 26 27
  if (
    data.toString().indexOf('Compiled successfully') >= 0 ||
    data.toString().indexOf('Compiled with warnings') >= 0
  ) {
偏右's avatar
偏右 committed
28 29
    // eslint-disable-next-line
    console.log('Development server is started, ready to run tests.');
偏右's avatar
偏右 committed
30
    const testCmd = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['test'], {
偏右's avatar
偏右 committed
31 32
      stdio: 'inherit',
    });
jim's avatar
jim committed
33
    testCmd.on('exit', code => {
偏右's avatar
偏右 committed
34
      startServer.kill();
jim's avatar
jim committed
35
      process.exit(code);
偏右's avatar
偏右 committed
36 37 38
    });
  }
});