Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added thrown error for duplicate testcases in describe instance #4302

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/testsuite/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,20 @@ class Context extends EventEmitter {
throw new Error(`The "${testName}" test script must be a function. "${typeof testFn}" given.`);
}

// TODO: warn if test name already exists
if (this.allScreenedTests.includes(testName)) {
const {Logger} = Utils;

const err = new Error(
'An error occurred while loading the testsuite:\n' +
`A testcase with name "${testName}" already exists. Testcases must have unique names inside the test suite, ` +
'otherwise testcases with duplicate names might not run at all.\n\n' +
'This testsuite has been disabled, please fix the error to run it properly.'
);
Logger.error(err);

this.setAttribute('@disabled', true);
Comment on lines +320 to +330
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This acts more like a warning than throwing the error and exiting the process, while also making sure the faulty testsuite is disabled and the user sees it in the report.

image

}

if (!skipTest) {
this.tests.push(testName);
} else {
Expand Down
4 changes: 3 additions & 1 deletion lib/testsuite/interfaces/describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ class Describe extends Common {
context.xcontext =
context.describe.skip = (title, describeFn) => {
this.instance.once('module-loaded', () => {
// in case tests have been declared using other interfaces (e.g. exports)
// in case tests have been declared using other interfaces (e.g. exports),
// we do not want to disable the suite.
if (this.instance.tests.length === 0) {
// if no tests are added after all interfaces are loaded, disable the suite.
this.instance.setAttribute('@disabled', true);
}
});
Expand Down