workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🚀 Feature Request: Supporting Node.js `readFileSync`[vitest-pool-workers]

Open m-shaka opened this issue 1 year ago • 3 comments

Describe the solution

Node.js polyfill of readFileSync is not yet implemented, but [email protected] uses readFileSync. https://github.com/vitest-dev/vitest/blob/6b29f3ddc86060cf3265959d4ae32e90b186cb92/packages/vitest/src/runtime/execute.ts#L110

It's a barrier to supporting [email protected].

Is there any problem with implementing it? Can I help you?

m-shaka avatar Jun 17 '24 11:06 m-shaka

@m-shaka - is this in terms of writing tests using the @cloudflare/vitest-pool-workers to write Workers tests or some other use of Vitest?

What would the behaviour be for loading files in a Worker?

petebacondarwin avatar Jun 17 '24 13:06 petebacondarwin

Thank you for your quick response. seems like it's required just to run Vitest with @cloudflare/vitest-pool-workers.

Here is a minimum repro. vitest run fails since readFileSync is not yet implemented. https://codesandbox.io/p/devbox/misty-butterfly-lnhhns

I'm not sure what Vitest is doing there, probably it's about executing test files

m-shaka avatar Jun 18 '24 01:06 m-shaka

I found https://github.com/cloudflare/workerd/pull/2147

~From my understanding, @cloudflare/vitest-pool-workers will work with Vitest >= 1.6 if miniflare supports experimental:nodejs_compat_v2 compatibility flag. Is that true?~ (It was a misunderstanding. v2 doesn't seem to support fs yet)

After I added experimental:nodejs_compat_v2 to compatibility_flags, I got this error. https://codesandbox.io/p/devbox/misty-butterfly-forked-mmn6v3?file=%2Fwrangler.toml

service core:user:vitest-pool-workers-runner-: No such compatibility flag: experimental:nodejs_compat_v2

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.
 ❯ #assembleAndUpdateConfig node_modules/miniflare/dist/src/index.js:9161:13
 ❯ process.processTicksAndRejections node:internal/process/task_queues:95:5
 ❯ Mutex.runWith node_modules/miniflare/dist/src/index.js:3521:16
 ❯ #waitForReady node_modules/miniflare/dist/src/index.js:9218:5
 ❯ getProjectMiniflare node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:1306:5
 ❯ Object.runTests node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:1556:20
 ❯ Object.runTests node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:8862:5
 ❯ async file:/project/workspace/node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:11207:9

m-shaka avatar Jun 18 '24 04:06 m-shaka

Thanks for reporting this! We'll follow up with the Vitest team to find a path forward here

penalosa avatar Jul 08 '24 10:07 penalosa

Closing in favour of https://github.com/cloudflare/workers-sdk/issues/6215

penalosa avatar Aug 21 '24 12:08 penalosa