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 not working with assets #7587

Open
dstr89 opened this issue Dec 18, 2024 · 4 comments
Open

🐛 BUG: vitest integration not working with assets #7587

dstr89 opened this issue Dec 18, 2024 · 4 comments
Labels
awaiting reporter response Needs clarification or followup from OP bug Something that isn't working

Comments

@dstr89
Copy link

dstr89 commented Dec 18, 2024

Which Cloudflare product(s) does this pertain to?

Miniflare

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

3.60.3 [wrangler], 4.20241216.0 [worker-types], 0.5.2 [vitest-pool-workers]]

What version of Node are you using?

16.20.2

What operating system and version are you using?

Mac Sonoma 14.16.1

Describe the Bug

Observed behavior

After adding the following configuration to expose public assets in my wrangler.toml

[assets]
directory = "./dist"
binding = "ASSETS"

I am getting the following error while running npm run test:

TypeError: Cannot read properties of undefined (reading 'digest')
 ❯ hashPath node_modules/miniflare/dist/src/index.js:7772:62
 ❯ node_modules/miniflare/dist/src/index.js:7707:11
 ❯ walk node_modules/miniflare/dist/src/index.js:7681:3
 ❯ buildAssetManifest node_modules/miniflare/dist/src/index.js:7671:42
 ❯ Object.getServices node_modules/miniflare/dist/src/index.js:7589:56
 ❯ Miniflare2.#assembleConfig node_modules/miniflare/dist/src/index.js:9840:42
 ❯ Miniflare2.#assembleAndUpdateConfig node_modules/miniflare/dist/src/index.js:9940:20
 ❯ Mutex.runWith node_modules/miniflare/dist/src/index.js:3632:16
 ❯ Miniflare2.#waitForReady node_modules/miniflare/dist/src/index.js:10042:5

Expected behavior

I noticed that the error goes away if I empty my ASSETS folder. However, then I cannot write an appropriate test. Expected behavior would be for ASSETS to work and not getting a Miniflare error.

Steps to reproduce

Here is my package JSON:

{
  "name": "my-on-page-app-worker",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build": "vite build",
    "deploy": "wrangler deploy",
    "dev": "wrangler dev",
    "start": "wrangler dev",
    "test": "vitest",
    "cf-typegen": "wrangler types"
  },
  "dependencies": {
    "preact": "^10.22.1"
  },
  "devDependencies": {
    "@cloudflare/vitest-pool-workers": "^0.5.2",
    "@cloudflare/workers-types": "^4.20241216.0",
    "@preact/preset-vite": "^2.9.0",
    "@types/node": "^22.8.1",
    "eslint": "^8.57.1",
    "eslint-config-preact": "^1.5.0",
    "typescript": "^5.5.2",
    "vite": "^5.3.3",
    "vite-plugin-css-injected-by-js": "^3.5.2",
    "vitest": "2.1.8",
    "wrangler": "^3.60.3"
  }
}

Here. is my wrangler.toml:

#:schema node_modules/wrangler/config-schema.json
name = "my-on-page-app-worker"
main = "src/index.ts"
compatibility_date = "2024-10-22"
compatibility_flags = ["nodejs_compat"]

# Expose the On Page App JS file in /dist as asset
[assets]
directory = "./dist"
binding = "ASSETS"

# Add a build step to run Vite build and generate the On Page App JS file in /dist
[build]
command = "npm run build"

The error happens only when running tests, the Worker is working fine on Cloudflare.

Please advise,
Daniel

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

@dstr89 dstr89 added the bug Something that isn't working label Dec 18, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Dec 18, 2024
@emily-shen
Copy link
Contributor

Hiya, if you're intending to use these assets with the vitest integration, you need wrangler 3.80.1 or later - let me know if you still have issues though!

@emily-shen emily-shen added the awaiting reporter response Needs clarification or followup from OP label Dec 18, 2024
@emily-shen emily-shen changed the title 🐛 BUG: 🐛 BUG: vitest integration not working with assets Dec 18, 2024
@dstr89
Copy link
Author

dstr89 commented Dec 19, 2024

Hi @emily-shen,
thanks for the hint. I updated "wrangler" to "^3.96.0", but still getting the same error:

TypeError: Cannot read properties of undefined (reading 'digest')
 ❯ hashPath node_modules/miniflare/dist/src/index.js:7772:62
 ❯ node_modules/miniflare/dist/src/index.js:7707:11
 ❯ walk node_modules/miniflare/dist/src/index.js:7681:3
 ❯ buildAssetManifest node_modules/miniflare/dist/src/index.js:7671:42
 ❯ Object.getServices node_modules/miniflare/dist/src/index.js:7589:56
 ❯ Miniflare2.#assembleConfig node_modules/miniflare/dist/src/index.js:9840:42
 ❯ Miniflare2.#assembleAndUpdateConfig node_modules/miniflare/dist/src/index.js:9940:20
 ❯ Mutex.runWith node_modules/miniflare/dist/src/index.js:3632:16
 ❯ Miniflare2.#waitForReady node_modules/miniflare/dist/src/index.js:10042:5

I found this example: https://github.com/cloudflare/workers-sdk/blob/main/fixtures/vitest-pool-workers-examples/workers-assets/test/assets.test.ts but I cannot figure out why it's not working.

BR,
Daniel

@dstr89
Copy link
Author

dstr89 commented Dec 19, 2024

The issue is easily reproducible on a newly generated worker project. Here is an example: https://github.com/dstr89/cloudflare-vitest-assets-issue/. Steps to reproduce the issue are described in the README.

@Achatzibaum281
Copy link

.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reporter response Needs clarification or followup from OP bug Something that isn't working
Projects
Status: Untriaged
Development

No branches or pull requests

3 participants