microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.79k stars 3.58k forks source link

[Bug]: component tests fail with cryptic error when files are moved around #31015

Open Asvarox opened 3 months ago

Asvarox commented 3 months ago

Version

1.44.1

Steps to reproduce

  1. clone the repro repo https://github.com/Asvarox/playwright-ct-cache-repro
  2. npm install
  3. run the tests npm run test-ct
  4. move files from src/ (App.tsx and App.spec.tsx) to src/modules/
  5. run the tests again npm run test-ct

Expected behavior

The tests should pass

Actual behavior

Tests are not run due to following error

RollupError: Could not resolve "./App" from "playwright/index.tsx"
file: /Users/olek/playwright-ct-cache-repro/playwright/index.tsx

    at getRollupError (/Users/olek/playwright-ct-cache-repro/node_modules/rollup/dist/es/shared/parseAst.js:396:41)
    at error (/Users/olek/playwright-ct-cache-repro/node_modules/rollup/dist/es/shared/parseAst.js:392:42)
    at ModuleLoader.handleInvalidResolvedId (/Users/olek/playwright-ct-cache-repro/node_modules/rollup/dist/es/shared/node-entry.js:19102:24)
    at ModuleLoader.resolveDynamicImport (/Users/olek/playwright-ct-cache-repro/node_modules/rollup/dist/es/shared/node-entry.js:19162:58)
    at /Users/olek/playwright-ct-cache-repro/node_modules/rollup/dist/es/shared/node-entry.js:19049:32
  3 did not run

which doesn't really say much

Additional context

The file paths the the components are cached in playwright/.cache/metainfo.json file and in case any doesn't exist, the run fails without a proper explanation.

The best solution would probably be to verify the paths and invalidate the cache. Otherwise moving it to e.g. node_modules would likely slightly improve the DX, as usually with this kind of errors people remove the folder hoping it'd fix things.

Environment

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 304.95 MB / 32.00 GB
  Binaries:
    Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v20.9.0/bin/yarn
    npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
    pnpm: 9.0.6 - ~/Library/pnpm/pnpm
    bun: 1.0.2 - ~/.bun/bin/bun
  IDEs:
    VSCode: 1.89.1 - /usr/local/bin/code
  Languages:
    Bash: 3.2.57 - /bin/bash
  npmPackages:
    @playwright/experimental-ct-react: ^1.44.1 => 1.44.1
mxschmitt commented 3 months ago

Investigation notes

This regressed in https://github.com/microsoft/playwright/pull/20799 since we add old components to the componentRegistry