Skip to content

[Question] Is there a way to programmattically handle codeceptjs instance? #2525

@svarunbe

Description

@svarunbe

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
        .src('./tests/my-fixture.js')
        .browsers('safari')
        .run();
}
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 console output if related. Use --verbose mode for more details.

# paste output here

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
    codecept.run ();
  }


}

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

module.exports = CustomRunner;

Details

  • CodeceptJS version: 2.6.6
  • NodeJS Version: v12.14.1
  • Operating System: Windows 10
  • puppeteer
  • Configuration file:
# paste config here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions