run-tests.js 953 Bytes
Newer Older
偏右's avatar
偏右 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
const { spawn } = require('child_process');
const { kill } = require('cross-port-killer');

const env = Object.create(process.env);
env.BROWSER = 'none';
const startServer = spawn('npm', ['start'], {
  env,
});

startServer.stderr.on('data', (data) => {
  // 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...');
startServer.stdout.on('data', (data) => {
afc163's avatar
afc163 committed
22 23 24 25
  // eslint-disable-next-line
  console.log(data.toString());
  if (data.toString().indexOf('The app is running at') >= 0 ||
      data.toString().indexOf('Compiled with warnings') >= 0) {
偏右's avatar
偏右 committed
26 27
    // eslint-disable-next-line
    console.log('Development server is started, ready to run tests.');
afc163's avatar
afc163 committed
28
    const testCmd = spawn('npm', ['test'], {
偏右's avatar
偏右 committed
29 30 31 32 33 34 35
      stdio: 'inherit',
    });
    testCmd.on('exit', () => {
      startServer.kill();
    });
  }
});