lucono/karma-test-explorer

Tests with same name but different classes should not be marked as "duplicates"

krilllind opened this issue · 5 comments

Describe the Bug

Jasmine "describe" with the same name as another test is marked with a triangle in testing UI (duplicates?). In Angular it's very common for large projects to have multiple services with the same name (for example StateService) but only provided within one specific component. Allowing for service to be disposed when component is destroyed.

I'm not sure if this issue is related to this extension, or if this belongs to vscode-test-explorer project.

Steps to Reproduce the Behavior
(see provided screenshots below for a visual representation)

  1. Create a new Angular project
  2. Create two components with with different names (like test-comp-one and test-comp-two)
  3. Create two services with the same name (for example StateService) and provide these in one component each.
  4. Open "testing" panel in VSC

Describe the Expected Behavior

Test UI should not report an error.

Provide Debug Logs

No issue with running so excluding logs

Screenshots

Result in testing UI
test explorer

Two different services, living in unique folders but share the same name
file explorer

Please Provide the Following Information

  • OS: Windows 10 build 19043.1348
  • Karma Test Explorer version: 0.3.0
  • Test Adapter Converter version: 0.1.4
  • Test Explorer UI version: 2.21.1

@krilllind I believe this is a limitation of Karma - those two tests will both run as StateService should be created and not have anything that explicitly associates them each to their individual test files or the components being tested.

I would recommend changing just the top-level describe of each in order to distinguish them from each other - perhaps by also including the different components they are each testing. So basically, ComponentOne StateService vs ComponentTwo StateService.

@lucono That is a good work around, but the fact that new scaffolded tests by Angular does not do this automatically makes it a bit harder to establish as a rule in enterprise development. Is there any way we can include the entire path from /src/ to detect if test name is already in use?

I guess that might defeat the purpose of this validation, so maybe have it as a setting?

Just throwing options out there. Let me know your thoughts

@krilllind The beta branch now has a new karmaTestExplorer.flagDuplicateTests boolean setting which can be used to disable test duplication flagging. Test that out to confirm if it addresses the issue. You can download the .vsix artifact from the CI build, or build it from the beta branch.

Works like a charm, tested out version 0.3.1 (preview) and I can confirm that I was able to locate this new setting and that it applies as intended 👍

@krilllind unfortunately, this change presents a potential for false positive test results and was therefore not released. For duplicate fully qualified test names, Karma Test Explorer does not have enough information to confidently assign each test to the exact test definition for which the test was originally discovered by the underlying test framework and so it must show a warning of potential misreporting of test results for those tests. This is because the test framework does not provide any file information for the discovered tests - Karma Test Explorer does an independent discovery of the test definitions in your test files.

Karma Test Explorer is just a very sophisticated reporter, and other reporters face similar or related issues (comment) when it comes to duplicate tests. Linter plugins also exist (such as this and this) to help identify test duplication.