-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
vitest runner defaultSuite always empty #5834
Copy link
Copy link
Closed
Labels
Description
Describe the bug
This is monitor pet-peeve that's been really bothering me.
When I run the tests I notice there's always this "ghost" suite at the top of the ancestorTitles stack that leads to the test name having a space in front of it, and the ancestor with an empty array item:
[
{
ancestorTitles: [ '' ],
fullName: ' test',
status: 'passed',
title: 'test',
duration: 0,
failureMessages: []
}
]
You can see it here with testResults.assertionResults.ancestorTitles:
https://vitest.dev/guide/reporters#json-reporter
The reason behind this is in this code:
vitest/packages/runner/src/suite.ts
Lines 43 to 47 in e99451c
| function createDefaultSuite(runner: VitestRunner) { | |
| const config = runner.config.sequence | |
| const api = config.shuffle ? suite.shuffle : suite | |
| return api('', { concurrent: config.concurrent }, () => {}) | |
| } |
It just generates an empty suite. If there was some way to pass a prop to it for it to take the name of the currently running file, it would be much more clear.
Reproduction
vitest version: 1.6.0
test.test.ts:
import { it, expect } from 'vitest';
it('test', async () => {
expect(true).toBe(true);
});
run.js:
import { startVitest } from 'vitest/node';
import { JsonReporter } from 'vitest/reporters';
class RunReporter extends JsonReporter {
async writeReport(report) {
this.report = JSON.parse(report);
}
}
const reporter = new RunReporter({});
(async () => {
await startVitest('test', undefined, undefined, {
test: {
reporters: [reporter],
include: ['**/test.test.ts'], // use any test here
testTimeout: 1000,
},
});
reporter.report?.testResults.forEach((result) => {
console.log(result.assertionResults);
});
})();
node run.js
System Info
N/AUsed Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable