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

vitest runner defaultSuite always empty #5834

Closed
6 tasks done
DecathectZero opened this issue Jun 3, 2024 · 1 comment
Closed
6 tasks done

vitest runner defaultSuite always empty #5834

DecathectZero opened this issue Jun 3, 2024 · 1 comment

Comments

@DecathectZero
Copy link

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

@sheremet-va
Copy link
Member

It was removed in Vitest 2.0 - #5435. You can test the changes by installing the latest beta version of Vitest.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants