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 5 commits into
base: main
Choose a base branch
from

Conversation

badra022
Copy link

Description

duplicate testcases inside describe instance that have same testName runs only the second test function for each time, this behavior should not be allowed so the user should have a thrown error explaining this to make test names inside the describe suite unique

Proof of work

here it shows the error when you write two tests with the same name inside the describe test suite
Screenshot 2024-11-16 140401

Thanks in advance for your contribution. Please follow the below steps in submitting a pull request, as it will help us with reviewing it quicker.

  • Before marking your PR for review, please test and verify your changes by making appropriate modifications to any of the Nightwatch example tests (present in examples/tests directory of the project) and running them. ecosia.js and duckDuckGo.js are good examples to work with.
  • Create a new branch from master (e.g. features/my-new-feature or issue/123-my-bugfix);
  • If you're fixing a bug also create an issue if one doesn't exist yet;
  • If it's a new feature explain why do you think it's necessary. Please check with the maintainers beforehand to make sure it is something that we will accept. Usually we only accept new features if we feel that they will benefit the entire community;
  • Please avoid sending PRs which contain drastic or low level changes. If you are certain that the changes are needed, please discuss them beforehand and indicate what the impact will be;
  • If your change is based on existing functionality please consider refactoring first. Pull requests that duplicate code will most likely be ignored;
  • Do not include changes that are not related to the issue at hand;
  • Follow the same coding style with regards to spaces, semicolons, variable naming etc.;
  • Always add unit tests - PRs without tests are most of the times ignored.

testcases have a 1 to 1 relation with functions so each test name should map to one function only, can't map to multiple functions in the same describeInstance
@CLAassistant
Copy link

CLAassistant commented Nov 17, 2024

CLA assistant check
All committers have signed the CLA.

@garg3133
Copy link
Member

@badra022 Thanks for this PR. Could you please sign the CLA as well?

@badra022
Copy link
Author

just signed it, thanks @garg3133

lib/testsuite/context.js Outdated Show resolved Hide resolved
Copy link

Status

  • ❌ No modified files found in the types directory.
    Please make sure to include types for any changes you have made. Thank you!.

@garg3133
Copy link
Member

This is potentially a breaking change because while it does run fine in the serial mode -- stops the test run with an error that is easily actionable, it just altogether skips the test suite during a parallel run without reporting any error in the HTML report. This is not ideal (and breaking) because the tests which were running earlier no longer run and it's not very straightforward for the user to know that a few tests stopped running.

Would need to spend some more time on this to figure out how the error can be better reported during a parallel run.

Comment on lines 320 to 330
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);
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

@garg3133
Copy link
Member

@badra022 Does this look like an acceptable solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants