How to close CodeceptJS Custom Runner Instance

What are you trying to achieve?

I have a Job queue and an API server setup. once a trigger received from the user, api server will insert a job in the queue.
Queue listener will pickup the job and for every job, I have to run few test cases using CodeceptJS custom runner. I will execute the next job’s testcases only after the current job’s codecept instance is completed.

Basically I would like to have something like “codecept.close()” this in CodeCeptJS.

const createTestCafe = require('testcafe');

const testCafe = await createTestCafe('localhost', 1337, 1338);

try {
    const runner = testCafe.createRunner();

    await runner
finally {
    await testCafe.close();

What do you get instead?

I could get the test completion status only using “event.all.after” event. I can’t close the instantiated codeceptjs instance by code.

Provide test source code if related

const {  container: Container,  codecept: Codecept,  event} = require ('codeceptjs');
const {dataStore} = require ('../helper');
const {app, runner, flags} = require ('../config').config;
const path = require ('path');

class CustomRunner {
  config = require (path.join (app.projectDirectory, '/config/codecept.conf')).config;
  opts = {steps: runner.steps, debug: runner.debug};
  testFiles = path.join (app.projectDirectory, runner.testFiles);

  run () {

    // create runner
    const codecept = new Codecept (this.config, this.opts);

    // initialize codeceptjs in current dir
    codecept.initGlobals (__dirname);

    // create helpers, support files, mocha
    Container.create (this.config, this.opts);

    // initialize listeners
    codecept.runHooks ();

    // run bootstrap function from config

    // load tests
    codecept.loadTests (this.testFiles);

    // run tests ();


if (!flags.isDebugMode) {
  new CustomRunner().run ();

module.exports = CustomRunner;


  • CodeceptJS version: 2.6.6
  • NodeJS Version: v12.14.1
  • Operating System: Windows 10
  • puppeteer
try  {
    if (someConditionHere) {
} catch (error) {

Maybe try something like this? I have a prompter that runs before the custom runner so I can use promises something like this:

        .then((answers) => {
        .catch((error) => {