Azure / Azure/azure-sdk-for-js
`dev-tool run test:vitest` ignores file path and `-t` filter arguments
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 1.4k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 144
Description
- **Package Name**: @azure/dev-tool
- **Package Version**: workspace:*
- **Operating system**: Windows 11
- [x] **nodejs**
- **version**: v22.x LTS
- [ ] **browser**
- **name/version**: N/A
- [x] **typescript**
- **version**: 5.x
- Is the bug related to **documentation** in
- [x] 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:
1. Navigate to any SDK package directory with vitest tests, e.g., [`sdk/planetarycomputer/planetarycomputer`](https://github.com/chahibi/azure-sdk-for-js/tree/mpcpro-sdk-gen-pup-js-mod/sdk/planetarycomputer)
2. Run the following command (as suggested by documentation and maintainer guidance):
```powershell
npx dev-tool run test:vitest -- test/public/07_collectionLifecycle.spec.ts -t "test_01"
```
3. Observe that **all 100 tests** across **all 8 test files** run, instead of just the single test matching `test_01` in the specified file.
**Expected behavior**
Only the test(s) matching the `-t` filter pattern in the specified test file should run. For example, running:
```powershell
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:
```powershell
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](https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/dev-tool/src/commands/run/testVitest.ts#L65-L77):
```typescript
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](https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/dev-tool/README.md) documents `test:vitest` as:
> `test:vitest` runs tests using vitest with the default and the provided options; starts the proxy-tool in record and playback modes
However, it does not:
1. Document how to pass additional vitest arguments using `--`
2. Warn about the filtering limitation
3. Provide examples of how to run a single test file or filter by test name
The [Quickstart-on-how-to-write-tests.md](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/Quickstart-on-how-to-write-tests.md) documentation only shows `pnpm test` without any guidance on running individual tests or filtering.
**Suggested Fix**
1. Fix the argument passing in `testVitest.ts` to properly handle vitest file path filtering
2. Update documentation to include examples like:
```powershell
# 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"
```
3. If the current implementation cannot be fixed easily, document the workaround of using `npx vitest run --config vitest.config.ts` directly
**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
Contributor guide
Assessment
This issue has not been assessed yet.