chromaui / chromatic-e2e

Archive end-to-end tests to be replayed in Storybook and Chromatic
MIT License
13 stars 3 forks source link

Dynamic require issue in an ES module #88

Closed Murreey closed 3 months ago

Murreey commented 5 months ago

Describe the bug When running playwright with chromatic-playwright installed in a ES module project, I'm seeing a dynamic require error:

> chromatic-test@0.0.0 test
> playwright test

Error: Dynamic require of "fs" is not supported

    at rrweb (~/chromatic-test/node_modules/chromatic-playwright/src/takeSnapshot.ts:38:7)
    at rrweb (~/chromatic-test/node_modules/chromatic-playwright/src/takeSnapshot.ts:38:7)
    at ~/chromatic-test/node_modules/chromatic-playwright/src/takeSnapshot.ts:38:7
    at rrweb (~/chromatic-test/node_modules/chromatic-playwright/dist/index.mjs:11:5098)
    at ~/chromatic-test/node_modules/chromatic-playwright/src/takeSnapshot.ts:38:7
    at rrweb (~/chromatic-test/node_modules/chromatic-playwright/dist/index.mjs:16:4390)
    at ~/chromatic-test/node_modules/chromatic-playwright/src/takeSnapshot.ts:38:7
    at ~/chromatic-test/node_modules/chromatic-playwright/dist/index.mjs:16:44868
Error: No tests found

That's running in a relatively small reproduction repo with just one test in it, and with "type": "module" in the package.json. If I take that type out, it works great and runs the test and creates the archive.

This is with the latest version of chromatic-playwright (0.4.0), have tried in a couple different Node/npm versions too just in case (16, 18 & 20) and get the same result.

To Reproduce Install chromatic-playwright in a project with "type": "module" in the package.json, set it up with Playwright as usual, and try to run playwright test. I think that's all it takes, I'm seeing it happen in a minimal repo with no code and no other dependencies than chromatic and storybook etc from the install guide.

Expected behavior The test runs and the snapshots are taken, same as without "type": "module".

Thanks in advance!

hustlelikeaboss commented 4 months ago

i ran into the same issue with @chromatic-com/cypress while following the instructions here: https://www.chromatic.com/docs/cypress/. had to convert cypress.config.cjs to cmj module

sourcec0de commented 3 months ago

Playwright doesn't seem to work the same way as @hustlelikeaboss suggested cypress does. I ended up moving all my e2e tests into a separate pnpm workspace, and removed type: module from my package.json.

tevanoff commented 3 months ago

Hey everybody, this should be fixed in version 0.6.4. Please give it another try and let us know if you continue to have problems.