Search code examples
protractorcodeceptjs

codeceptjs running with protractor does not exit


When running my tests with CodeceptJS using the Protractor driver, the tests run successfully but the process does not exit, so I have to force-stop it everytime, and I also cannot run them on my CI server or it will always timeout. My codecept.conf.js:

const conf = require('../config/config');

exports.config = {
  tests: './e2e/**/*.spec.js',
  output: './e2e/reports',
  helpers: {
    Protractor: protractor.config,
    ProtractorHelper: {
      require: './e2e/protractor.helper.js'
    }
  },
  name: 'test',
  timeout: 10000,
  bootstrap: './e2e/before-launch.js',
  mocha: {
    reporterOptions: {
      reportDir: './reports'
    }
  }
};

My protractor.conf.js:

const conf = require('../config/config');

exports.config = {
  scriptsTimeout: 11000,
  browser: 'chrome',
  capabilities: {
    chromeOptions: {
      args: process.env.CI ? [
        '--no-sandbox',
        // See https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
        '--headless',
        '--disable-gpu',
        // Without a remote debugging port, Google Chrome exits immediately.
        '--remote-debugging-port=9222',
        '--disable-web-security'
      ] : []
    }
  },
  directConnect: true,
  url: conf.e2e.baseUrl,
  noGlobals: true,
  rootElement: 'body'
};

And the before-launch.js which basically just serves up the website:

const conf = require('../config/config');

require('connect')().use(require('serve-static')(conf.e2e.paths.build)).listen(conf.e2e.servePort);

I am using:

  • CodeceptJS version: 1.4.1
  • NodeJS version: 10.1.0
  • Protractor version: 5.4.0

Solution

  • Turns out it was not exiting because of the connect which served up the website and kept listening at the end, so I changed the codecept config to:

    bootstrap: 'run-server.js',
    teardown: 'run-server.js',
    

    and in run-server.js:

    const http = require('http');
    const connect = require('connect');
    
    let app = connect();
    app.use(require('serve-static')('public'));
    let server = null;
    
    module.exports = {
      bootstrap: function(done) {
        server = http.createServer(app);
        server.listen(3001);
        done();
      },
      teardown: function(done) {
        server.close();
        done();
      }
    }
    

    And now it exits just fine