Skip to content

vitest runner defaultSuite always empty #5834

@DecathectZero

Description

@DecathectZero

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:

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/A

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions