Skip to content

dev-tool run test:vitest ignores file path and -t filter arguments #36932

@chahibi

Description

@chahibi
  • 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

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
  2. 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"
  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:

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: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 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:
    # 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageWorkflow: This is a new issue that needs to be triaged to the appropriate team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions