Replies: 2 comments
-
On second (or third) examination, this can be done via bootstrap in the codecept.conf.js: const { container } = require("codeceptjs");
exports.config = {
...
bootstrap: async function () {
const mocha = container.mocha();
mocha.selective = function(selective) {
if (!selective) {
return false;
}
if (!Array.isArray(selective)) {
throw new Error("Must provide an array.");
}
const re = selective.join("|");
const regex = new RegExp(re);
mocha.grep(regex);
};
mocha.selective(["tag1", "tag2"]);
return null;
},
...
} Where the array in UPDATE |
Beta Was this translation helpful? Give feedback.
-
Looks like a good approach and nice example of using bootstrap! |
Beta Was this translation helpful? Give feedback.
-
What are you trying to achieve?
Selectively run a subset of tests without "skip"ing all the rest
What do you get instead?
At the moment, I have a mechanism in a hook to skip a test if it matches a set of criteria, one of which being a relevant tag being present in a list.
example: #661
But a basic example:
Details
Hack Implementation
I'm not really sure how to do all the things necessary to offer a PR on this project. I'm also not sure if this project is appropriate, or if it's more appropriate to offer a solution to the Allure project (https://github.com/allure-framework/allure-js) or the Mocha project (https://github.com/mochajs/mocha) given the motivation and maybe draft? solution(s) for mocha and/or CodeceptJS as referenced https://docs.qameta.io/allure-testops/integrations/test-frameworks/.
So, I've built what will roughly do what I need in my own codebase, though I'll need to patch it after every update.
A test scenario, (bdd or plain-code, doesn't matter)
In codecept.conf.js (where the property value is an array, but could also be a function result after importing and transforming an external file content).
In lib/container.js, add the if (config.selective) block
In lib/mochaFactory::create(), added a new prototype definition on the Mocha object and then call the function; on or about line 44/45 in CodeceptJS v3.3.6
Weakness/Uknowns
codeceptjs run
command and both BDD and plain-code tests.--selective
, maybe even with a file path, but I couldn't figure how to modify the command prompt for codecept and have it follow through into mocha..only()
methodology. However, I couldn't figure out how to call the .only() method or any related functionality via a programatic before.test or before.suite event; like I was able to programmatically skip() as described in issue 661.Summary
Hopefully someone with greater experience in CodeceptJS and/or Mocha can see this and maybe this will provide some inspiration for a quick(er) patch. If not, then anyone else coming along might be able to use this to patch their own installation.
Beta Was this translation helpful? Give feedback.
All reactions