Skip to content

vp test fails with @cloudflare/vitest-pool-workers while vitest run passes #1076

@toshiki-higa

Description

@toshiki-higa

Describe the bug

When using @cloudflare/vitest-pool-workers with vite-plus, running vp test fails, while plain vitest run passes in the same project.

vp test crashes during suite initialization with:

TypeError: Cannot read properties of undefined (reading 'config')
❯ initSuite .../@voidzero-dev/vite-plus-test/dist/@vitest/runner/index.js:1203:25
    1201|     const parentTask = currentSuite ?? collectorContext.currentSuite?.file;
    1202|     const suiteTags = toArray(suiteOptions?.tags);
    1203|     validateTags(runner.config, suiteTags);
       |                         ^
    1204|     suite = {
    1205|       id: "",

This appears specific to the vp test / @voidzero-dev/vite-plus-test runner path rather than the project test configuration itself.

Reproduction

N/A

Steps to reproduce

This requires a Cloudflare Workers test setup using @cloudflare/vitest-pool-workers, so I am not attaching a separate reproduction repo yet.

In a project configured like below, run:

vp test

Relevant test config:

import { cloudflareTest } from "@cloudflare/vitest-pool-workers"
import { defineConfig } from "vite-plus/test/config"

export default defineConfig({
  plugins: [
    cloudflareTest({
      wrangler: {
        configPath: "./wrangler.jsonc",
      },
    }),
  ],
  test: {
    include: ["test/**/*.spec.ts"],
  },
})

Example test:

import { exports } from "cloudflare:workers"
import { describe, expect, it } from "vitest"

describe("web worker", () => {
  it("responds to /ping", async () => {
    const response = await exports.default.fetch("https://example.com/ping")

    expect(response.status).toBe(200)
    await expect(response.json()).resolves.toEqual({ ok: true })
  })
})

For comparison, in the same workspace:

vitest run

passes successfully, but:

vp test

fails.

System Info

vp v0.1.13

Local vite-plus:
  vite-plus  v0.1.13

Tools:
  vite             v8.0.1
  rolldown         v1.0.0-rc.10
  vitest           v4.1.0
  oxfmt            v0.41.0
  oxlint           v1.56.0
  oxlint-tsgolint  v0.17.1
  tsdown           v0.21.4

Used Package Manager

pnpm

Logs

[vpw:warn] You're running `vitest@0.1.13`, but this version of `@cloudflare/vitest-pool-workers` only officially supports `vitest ^4.1.0`.
`@cloudflare/vitest-pool-workers` currently depends on internal Vitest APIs that are not protected by semantic-versioning guarantees.
Your tests may work without issue, but we can not guarantee compatibility outside of the above version range.
[vpw:debug] Adding `enable_nodejs_tty_module` compatibility flag during tests as this feature is needed to support the Vitest runner.
[vpw:debug] Adding `enable_nodejs_fs_module` compatibility flag during tests as this feature is needed to support the Vitest runner.
[vpw:debug] Adding `enable_nodejs_http_modules` compatibility flag during tests as this feature is needed to support the Vitest runner.
[vpw:debug] Adding `enable_nodejs_perf_hooks_module` compatibility flag during tests as this feature is needed to support the Vitest runner.
[vpw:debug] Adding `enable_nodejs_v8_module` compatibility flag during tests as this feature is needed to support the Vitest runner.
[vpw:debug] Adding `enable_nodejs_process_v2` compatibility flag during tests as this feature is needed to support the Vitest runner.
[vpw:info] Starting runtime for ...
 ❯ test/ping.spec.ts (0 test)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/ping.spec.ts [ test/ping.spec.ts ]
TypeError: Cannot read properties of undefined (reading 'config')
 ❯ initSuite ../../../../../../../.local/share/mise/installs/npm-vite-plus/0.1.13/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/runner/index.js:1203:25
    1201|     const parentTask = currentSuite ?? collectorContext…
    1202|     const suiteTags = toArray(suiteOptions?.tags);
    1203|     validateTags(runner.config, suiteTags);
       |                         ^
    1204|     suite = {
    1205|       id: "",

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions