Skip to content

Error: test file "test2.spec.js" should not import test file "test1.spec.js" #23

@AndrewRedo

Description

@AndrewRedo

🐞 Issue: Playwright throws import error between test files in Bazel build

We’re using Playwright with rules_playwright, and have Bazel set up so that individual test files can be run by placing a playwright_test target in the nearest BUILD.bazel.

This works fine with a single test file — but as soon as we add a second .spec.ts file, we get this error:

Error: test file "test2.spec.js" should not import test file "test1.spec.js"

at test2.spec.js:1

1 | "use strict";
| ^
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | const test_1 = require("@playwright/test");
4 | (0, test_1.test)("Login with Authtoken", async () => {

🔍 Notes:

These test files do not import each other at the source level.

They only import from @playwright/test.

But after Bazel compilation, Playwright seems to detect an import between the resulting .js files.

❓ Question:

Has anyone encountered this issue when using rules_playwright with Bazel?

Is there a recommended way to structure the Bazel targets or ts_library definitions to avoid Playwright’s cross-import validation?

Is there a config option or Bazel macro pattern to compile .spec.ts files in isolation, or avoid them being included in each other’s output? (besides creating a new playwright section in the BUILD.bazel file for each test) 

Any insights or prior examples would be greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions