-
Notifications
You must be signed in to change notification settings - Fork 14
TE-6261 - Add a vitest runner #580
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
Open
mcncl
wants to merge
14
commits into
main
Choose a base branch
from
feat/vitest_runner
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c18f8d8
refactor(jest): vitest support in parser
mcncl cd5ef52
doc(vitest): note vitest support added
mcncl a4cf9f9
feat(vitest): add a vitest runner
mcncl 105f08e
chore(npm): add vitest to package.json
mcncl 3a483cb
chore(specs): add some vitest specs
mcncl 0f92bb6
chore(yarn): add yarn files and locks
mcncl 8fea0db
tests(vitest): add unit and integration tests
mcncl ef9afb4
docs: update changelog and add vitest docs
mcncl b1d80bc
Update internal/runner/vitest.go
buildkite-systems cdd54df
Merge branch 'main' into feat/vitest_runner
buildkite-systems 7e2d758
Update internal/runner/supported_features_test.go
buildkite-systems c192590
Update internal/runner/supported_features_test.go
buildkite-systems 308cb64
Update internal/runner/vitest.go
buildkite-systems 619e84f
Update internal/runner/vitest.go
buildkite-systems File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Using bktec with Vitest | ||
| To integrate bktec with Vitest, set the `BUILDKITE_TEST_ENGINE_TEST_RUNNER` environment variable to `vitest`. Then, specify the `BUILDKITE_TEST_ENGINE_RESULT_PATH` to define where the JSON result should be stored. bktec will instruct Vitest to output the JSON result to this path, which is necessary for bktec to read the test results for retries and verification purposes. | ||
|
|
||
| ```sh | ||
| export BUILDKITE_TEST_ENGINE_TEST_RUNNER=vitest | ||
| export BUILDKITE_TEST_ENGINE_RESULT_PATH=tmp/vitest-result.json | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > Vitest's JSON reporter is Jest-compatible, so bktec reuses the same result parsing as the Jest runner. | ||
|
|
||
| ## Configure test command | ||
| By default, bktec runs Vitest with the following command: | ||
|
|
||
| ```sh | ||
| npx vitest run {{testExamples}} --reporter=json --outputFile {{resultPath}} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: The code default now includes |
||
| ``` | ||
|
|
||
| In this command, `{{testExamples}}` is replaced by bktec with the list of test files to run, and `{{resultPath}}` is replaced with the value set in `BUILDKITE_TEST_ENGINE_RESULT_PATH`. You can customize this command using the `BUILDKITE_TEST_ENGINE_TEST_CMD` environment variable. | ||
|
|
||
| To customize the test command, set the following environment variable: | ||
| ```sh | ||
| export BUILDKITE_TEST_ENGINE_TEST_CMD="yarn vitest run {{testExamples}} --reporter=json --outputFile {{resultPath}}" | ||
| ``` | ||
|
|
||
| > [!IMPORTANT] | ||
| > Make sure to append `--reporter=json --outputFile {{resultPath}}` in your custom test command, as bktec requires this to read the test results for retries and verification purposes. Also ensure you use `vitest run` (not watch mode) so the process exits after the run completes. | ||
|
|
||
| ## Filter test files | ||
| By default, bktec runs test files that match the `**/{__tests__/**/*,*.spec,*.test}.{ts,js,tsx,jsx}` pattern. You can customize this pattern using the `BUILDKITE_TEST_ENGINE_TEST_FILE_PATTERN` environment variable. For instance, to configure bktec to only run Vitest test files inside the `src/components` directory, use: | ||
|
|
||
| ```sh | ||
| export BUILDKITE_TEST_ENGINE_TEST_FILE_PATTERN=src/components/**/*.test.{ts,tsx} | ||
| ``` | ||
|
|
||
| Additionally, you can exclude specific files or directories that match a certain pattern using the `BUILDKITE_TEST_ENGINE_TEST_FILE_EXCLUDE_PATTERN` environment variable. For example, to exclude test files inside the `src/utilities` directory, use: | ||
|
|
||
| ```sh | ||
| export BUILDKITE_TEST_ENGINE_TEST_FILE_EXCLUDE_PATTERN=src/utilities | ||
| ``` | ||
|
|
||
| > [!TIP] | ||
| > This option accepts the pattern syntax supported by the [zzglob](https://github.com/DrJosh9000/zzglob?tab=readme-ov-file#pattern-syntax) library. | ||
|
|
||
| ## Location prefix | ||
| If you have configured the [Buildkite test collector](https://buildkite.com/docs/test-engine/test-collection) with a location prefix, you should set the same prefix for bktec so that test file paths match those reported by the collector. You can set this using the `--location-prefix` flag or the `BUILDKITE_TEST_ENGINE_LOCATION_PREFIX` environment variable. | ||
|
|
||
| ```sh | ||
| export BUILDKITE_TEST_ENGINE_LOCATION_PREFIX=my/prefix/ | ||
| ``` | ||
|
|
||
| ## Automatically retry failed tests | ||
| You can configure bktec to automatically retry failed tests using the `BUILDKITE_TEST_ENGINE_RETRY_COUNT` environment variable. When this variable is set to a number greater than `0`, bktec will retry each failed test up to the specified number of times, using the following command: | ||
|
|
||
| ```sh | ||
| npx vitest run --testNamePattern '{{testNamePattern}}' --reporter=json --outputFile {{resultPath}} | ||
| ``` | ||
|
|
||
| In this command: | ||
| - `{{testNamePattern}}` is replaced by bktec with the pattern matching the failed test names | ||
| - `{{resultPath}}` is replaced with the value set in `BUILDKITE_TEST_ENGINE_RESULT_PATH` | ||
|
|
||
| You can customize this command using the `BUILDKITE_TEST_ENGINE_RETRY_CMD` environment variable. | ||
|
|
||
| ```sh | ||
| export BUILDKITE_TEST_ENGINE_RETRY_CMD="yarn vitest run --testNamePattern '{{testNamePattern}}' --reporter=json --outputFile {{resultPath}}" | ||
| export BUILDKITE_TEST_ENGINE_RETRY_COUNT=2 | ||
| ``` | ||
|
|
||
| > [!IMPORTANT] | ||
| > Make sure to append `--testNamePattern '{{testNamePattern}}' --reporter=json --outputFile {{resultPath}}` in your custom retry command. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| // Package runner provides the test runners that run sets of test cases. | ||
| // Supported runners: rspec, jest, cypress, playwright, pytest, gotest, cucumber, nunit. | ||
| // Supported runners: rspec, jest, vitest, cypress, playwright, pytest, gotest, cucumber, nunit. | ||
| package runner |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| approvedGitRepositories: | ||
| - "**" | ||
|
|
||
| enableScripts: true | ||
|
|
||
| nodeLinker: node-modules | ||
|
|
||
| npmMinimalAgeGate: 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: The implementation's default command now includes
--reporter=defaultas well as--reporter=json, so this default-command snippet is out of sync. Users copying the current docs would get JSON-only output and lose the normal Vitest console reporter; could we update the default/retry snippets and custom-command guidance to include both reporters?