Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: Vitest integration does not work with discord-api-types #7323

Closed
davidhouweling opened this issue Nov 21, 2024 · 1 comment
Closed
Labels
bug Something that isn't working

Comments

@davidhouweling
Copy link

davidhouweling commented Nov 21, 2024

Which Cloudflare product(s) does this pertain to?

Workers Vitest Integration

What version(s) of the tool(s) are you using?

0.5.28 [@cloudflare/vitest-pool-workers]

What version of Node are you using?

22.11.0

What operating system and version are you using?

Windows 11

Describe the Bug

Observed behavior

Following the steps in https://developers.cloudflare.com/workers/testing/vitest-integration/, testing a discord bot but having problems when it tries to import discord-api-types with the following error when trying to run vitest. Of note, when using the same test without the cloudflare vitest integration, the test passes, meaning that the issue really is more to do with the vitest integration module rather than with discord-api-types.

 FAIL  src/impl.test.mts [ src/impl.test.mts ]
Error: No such module "C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.js".
  imported from "C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs"

Dug into discord and found guidance on turning on debug details NODE_DEBUG=vitest-pool-workers:module-fallback which I've added into the log section.

Expected behavior

Unit tests should be able to run successfully.

Steps to reproduce

  1. Clone https://github.com/davidhouweling/vitest-wrangler-discord-api-types
  2. npm install
  3. npm test

Please provide a link to a minimal reproduction

https://github.com/davidhouweling/vitest-wrangler-discord-api-types

Please provide any relevant error logs

VITEST-POOL-WORKERS:MODULE-FALLBACK 58168: import("C:/git/vitest-wrangler-discord-api-types/node_modules/vite-node/dist/file:/C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs") relative to C:/git/vitest-wrangler-discord-api-types/node_modules/vite-node/dist/client.mjs: redirect: C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs
VITEST-POOL-WORKERS:MODULE-FALLBACK 58168: import("C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs") relative to C:/git/vitest-wrangler-discord-api-types/node_modules/vite-node/dist/client.mjs: esm: C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs
VITEST-POOL-WORKERS:MODULE-FALLBACK 58168: import("C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.js") relative to C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs: error: Error: Parse error @7:1:8
    at Module.parse (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/cjs-module-lexer/dist/lexer.mjs:2:381)
    at getCjsNamedExports (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:703:49)
    at getCjsNamedExports (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:719:35)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async load (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:940:24)
    at async handleModuleFallbackRequest (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:977:12)
    at async #handleLoopback (C:\git\vitest-wrangler-discord-api-types\node_modules\miniflare\dist\src\index.js:9619:20) {
  idx: 7,
  code: 'ERR_LEXER_ESM_SYNTAX'
}
workerd/server/server.c++:3059: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=%2FC%3A%2Fgit%2Fvitest-wrangler-discord-api-types%2Fnode_modules%2Fdiscord-api-types%2Fv10.js&referrer=%2FC%3A%2Fgit%2Fvitest-wrangler-discord-api-types%2Fnode_modules%2Fdiscord-api-types%2Fv10.mjs&rawSpecifier=.%2Fv10.js
@davidhouweling davidhouweling added the bug Something that isn't working label Nov 21, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Nov 21, 2024
@emily-shen
Copy link
Contributor

Thanks for reporting this issue 🧡

closing this as a duplicate of #6591, although if you go to the reproduction linked in that issue (https://github.com/dario-piotrowicz/vitest-pool-workers-ext-repro) see how to sort of get around this by patching the imports in the discord-api package. this is obviously not an ideal solution. we're going to be doing some work around the vitest integration in the new year, so hopefully a proper fix should be incoming.

@github-project-automation github-project-automation bot moved this from Untriaged to Done in workers-sdk Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
None yet
Development

No branches or pull requests

2 participants