vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
12.64k stars 1.13k forks source link

Extend existing `list` command to output only a list of file names #6374

Closed pleunv closed 2 weeks ago

pleunv commented 3 weeks ago

Clear and concise description of the problem

https://github.com/vitest-dev/vitest/issues/2901 lead to the introduction of the vitest list command, but unfortunately this is pretty slow and requires some processing if you're only interested in a list of files that will run with the given filters & flags (i.e. --changed), since it parses all test files and returns a list containing every individual test case. What I ideally would want is a command that returns which files are going to be executed given the provided filters & flags without drilling down to individual test cases, requiring only a lookup and eliminating the need for a parse, thus being a lot quicker.

My main use-case for this is dynamic sharding, where I dynamically determine the amount of shards and agents I want to spin up based on a predetermined number TESTS_PER_SHARD (i.e. 100), which serves to keep the test performance stable, irregardless of number of tests. Jest for example can achieve this with --listTests [--json], which runs in under a second for ~1k test files and leads to the following output:

jest --listTests

/path/to/testA.spec.tsx
/path/to/testB.spec.tsx

jest --listTests --json

["/path/to/testA.spec.tsx", "/path/to/testB.spec.tsx"]

For comparison, running vitest list --json on an M1 MBP for the same ~1k files takes 3.5 minutes.

Suggested solution

Since there is already a dedicated list command I suppose it would make sense to provide a new optional flag, i.e. --filesOnly.

Alternative

No response

Additional context

No response

Validations

sheremet-va commented 3 weeks ago

since it parses all test files and returns a list containing every individual test case

It doesn't parse it, it runs the code to collect tests. This is what mocha does for example.

Ma-hawaj commented 3 weeks ago

Can I try working on this ?

sheremet-va commented 3 weeks ago

Can I try working on this ?

Sure