-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
- Package Name: @azure/dev-tool
- Package Version: workspace:*
- Operating system: Windows 11
- nodejs
- version: v22.x LTS
- browser
- name/version: N/A
- typescript
- version: 5.x
- Is the bug related to documentation in
- README.md
- source code documentation
- SDK API docs on https://learn.microsoft.com
Describe the bug
When using dev-tool run test:vitest with the -- separator to pass additional vitest arguments (specifically test file paths and -t test name filters), the filtering does not work correctly. The command runs all tests across all test files instead of filtering to just the specified file and test name.
To Reproduce
Steps to reproduce the behavior:
- Navigate to any SDK package directory with vitest tests, e.g.,
sdk/planetarycomputer/planetarycomputer - Run the following command (as suggested by documentation and maintainer guidance):
npx dev-tool run test:vitest -- test/public/07_collectionLifecycle.spec.ts -t "test_01"
- Observe that all 100 tests across all 8 test files run, instead of just the single test matching
test_01in the specified file.
Expected behavior
Only the test(s) matching the -t filter pattern in the specified test file should run. For example, running:
npx dev-tool run test:vitest -- test/public/07_collectionLifecycle.spec.ts -t "test_01"Should run only tests matching test_01 in 07_collectionLifecycle.spec.ts (which would be 1 test with 5 skipped in that file).
Workaround
Running vitest directly works correctly:
npx vitest run --config vitest.config.ts test/public/07_collectionLifecycle.spec.ts -t "test_01"This correctly filters to only the specified file and test name pattern.
Root Cause Analysis
Looking at the source code in common/tools/dev-tool/src/commands/run/testVitest.ts:
const vitestArgs = updatedArgs?.length ? updatedArgs.join(" ") : "";
const command = {
command: `vitest ${args} ${vitestArgs}`,
name: "vitest",
};The arguments after -- are simply joined with spaces, but this doesn't properly handle how vitest expects positional arguments (test file paths) vs flag arguments (-t). When the command is constructed this way, vitest may not correctly interpret the file path as a filter.
Documentation Issue
The dev-tool README.md documents test:vitest as:
test:vitestruns tests using vitest with the default and the provided options; starts the proxy-tool in record and playback modes
However, it does not:
- Document how to pass additional vitest arguments using
-- - Warn about the filtering limitation
- Provide examples of how to run a single test file or filter by test name
The Quickstart-on-how-to-write-tests.md documentation only shows pnpm test without any guidance on running individual tests or filtering.
Suggested Fix
- Fix the argument passing in
testVitest.tsto properly handle vitest file path filtering - Update documentation to include examples like:
# Run a specific test file npx dev-tool run test:vitest -- test/public/myTest.spec.ts # Run tests matching a pattern npx dev-tool run test:vitest -- -t "my test pattern" # Run specific test in specific file npx dev-tool run test:vitest -- test/public/myTest.spec.ts -t "test_01"
- If the current implementation cannot be fixed easily, document the workaround of using
npx vitest run --config vitest.config.tsdirectly
Additional context
This issue affects developer productivity when working on specific tests during SDK development. Having to run the entire test suite instead of a single test adds significant time to the development cycle, especially for packages with large test suites or tests that require network calls.
A maintainer confirmed the expected syntax should work:
This worked for me:
npx dev-tool run test:vitest -- test/public/07_collectionLifecycle.spec.ts -t "test_03.*Delete a STAC collection"
However, this does not work consistently across different environments/packages.
Disclaimer: This bug report was generated through Copilot