Skip to content

Custom runner is ignored in browser mode #9546

@andyearnshaw

Description

@andyearnshaw

Describe the bug

I'm trying to write a custom runner for Svelte tests. However, I'm also running my tests in browser mode, and I noticed that my runner is not instantiated at all. If I comment out the browser configuration, my runner is instantiated correctly.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-kmmccmjy?file=vite.config.ts

Given a basic runner that throws on construction:

// customrunner.js
import { VitestTestRunner } from 'vitest/runners';

class CustomRunner extends VitestTestRunner {
  constructor(config) {
    throw new Error('Custom runner failed successfully!');
  }
}

export default CustomRunner;

And a basic config:

export default defineConfig({
  test: {
    runner: './customrunner.js',

    // Comment out here to see the custom runner failing tests
    browser: {
      enabled: true,
      provider: preview(), // issue is with other providers also
      instances: [{ browser: 'chromium' }],
    },
  },
});

You can see that the tests run even though the runner should be throwing. If you comment out the browser config and run again, the runner will throw and fail the tests as expected.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitest/browser-preview: latest => 4.0.18 
    @vitest/ui: latest => 4.0.18 
    vite: latest => 7.3.1 
    vitest: latest => 4.0.18

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions