Sonar Not Detecting Sequential Tests in Vitest

Sonar Not Detecting Sequential Tests in Vitest

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • Languages of the repository: TypeScript
  • Tools used: Vitest
  • Errors:
    • "Add some tests to this file or delete it" in ‘New Issues’ section in SonarCloud Summary

Description

When I set up my tests to be sequential in Vitest and nested in ‘describe’ methods, Sonar does not register it to be a valid test.

Sonar does not register tests: Sequential Tests

describe('Here are my tests', () => { 
    describe('myFunc', () => {
        test.sequential('I am testing for a success response', async () => {
            // test body
     })
  })
})

However, if I remove the ‘sequential’ property and therefore make my tests run in parallel, Sonar will register the tests as valid.

Sonar registers tests: Parallel Tests

describe('Here are my tests', () => { 
    describe('myFunc', () => {
        test('I am testing for a success response', async () => {
            // test body
     })
  })
})

Is this a bug in Sonar? Both scenarios run successfully on my end, but when Sonar analyzes these different test set ups, it does not register the first scenario with sequential tests as a valid test.

Thank you,
Kenney

Hi @kenneyp1234 ,

When you run sequential is the name of the test report file the same as when you run parallel?

Regards,
Charlie Teague

Hi Charlie,

Yes, the name of the test file is the same (ex: my-test.test.ts). I would just be changing the different test scenarios in this same file, but receive the issue as posted above.

Thanks,
Kenney

Hey @kenneyp1234!

Thanks for the report. I’m pretty sure this is a known false-positive: Fix FP S2699 (`assertions-in-tests`): Detect `expect` provided by the test callback on concurrent tests · Issue #4507 · SonarSource/SonarJS · GitHub

Hi Colin,

Thank you. It seems like you guys are already on this. I’ll be looking forward to the push for this bug.

Best,
Kenney

1 Like