run-tests.js 1022 Bytes
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';
sorrycc's avatar
sorrycc committed
6
env.TEST = true;
偏右's avatar
偏右 committed
7
const startServer = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['start'], {
偏右's avatar
偏右 committed
8 9 10
  env,
});

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

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
22
startServer.stdout.on('data', data => {
afc163's avatar
afc163 committed
23 24
  // eslint-disable-next-line
  console.log(data.toString());
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
25
  if (data.toString().indexOf('App running at') >= 0) {
偏右's avatar
偏右 committed
26 27
    // eslint-disable-next-line
    console.log('Development server is started, ready to run tests.');
偏右's avatar
偏右 committed
28
    const testCmd = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['test'], {
偏右's avatar
偏右 committed
29 30
      stdio: 'inherit',
    });
jim's avatar
jim committed
31
    testCmd.on('exit', code => {
偏右's avatar
偏右 committed
32
      startServer.kill();
jim's avatar
jim committed
33
      process.exit(code);
偏右's avatar
偏右 committed
34 35 36
    });
  }
});