Skip to content

[Bug]: Playwright Test did not expect test.describe() to be called here in VS Code extension #38343

@yangnuowei88

Description

@yangnuowei88
## 🚀 Feature Request

The VS Code Playwright extension does not work when `test` and `expect` are imported from a custom package that wraps `@playwright/test` with extended fixtures.

## Current Behavior

When running tests via the VS Code extension that import from a custom fixtures package:

```typescript
// my-test.spec.ts
import { test, expect } from '@my-company/e2e-test' // custom package

test.describe('My tests', () => {
  test('example', async ({ page, customFixture }) => {
    // ...
  })
})

The extension throws:

Error: Playwright Test did not expect test.describe() to be called here.
Most common reasons include:
- You have two different versions of @playwright/test.

Expected Behavior

The VS Code extension should recognize and work with test objects that are extended via test.extend() and re-exported from third-party packages.

Root Cause Analysis

The issue occurs because:

  1. The VS Code extension loads its own instance of @playwright/test
  2. The test file imports test from a custom package (e.g., @my-company/e2e-test)
  3. The custom package internally imports from @playwright/test (potentially a different module instance due to Node.js module resolution)
  4. Playwright detects two different instances and throws an error

Reproduction Steps

  1. Create a custom fixtures package:
// packages/e2e-test/src/fixtures.ts
import { test as base } from '@playwright/test'

export const test = base.extend({
  customFixture: async ({ page }, use) => {
    // custom setup
    await use(new CustomHelper(page))
  },
})

export { expect } from '@playwright/test'
  1. Create a test file using the custom package:
// tests/example.spec.ts
import { test, expect } from '@my-company/e2e-test'

test.describe('Example', () => {
  test('works', async ({ page, customFixture }) => {
    await page.goto('/')
  })
})
  1. Run tests via CLI: ✅ Works perfectly
  2. Run tests via VS Code extension: ❌ Throws error

Workarounds

Currently, we have to:

  • Use CLI (npx playwright test) or F5 debugging instead of the extension
  • Or abandon custom fixtures entirely and import directly from @playwright/test

Environment

  • VS Code: 1.95.x
  • Playwright: 1.48.x
  • Playwright VS Code Extension: 1.1.x
  • OS: Windows 11
  • Package Manager: pnpm (monorepo)

Motivation

Many teams create shared test utilities with custom fixtures for:

  • Common page object models
  • Shared authentication flows
  • Domain-specific helpers
  • AI-powered testing tools (e.g., Midscene)

The current limitation forces teams to choose between:

  1. Using the excellent VS Code extension features (run/debug individual tests, pick locators, etc.)
  2. Using custom fixtures for better code reuse

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions