Giter VIP home page Giter VIP logo

Comments (11)

hi-ogawa avatar hi-ogawa commented on August 16, 2024 1

@vitest/web-worker is only a web worker emulation on node runtime, so it doesn't deal with Vite client ?url convention.

You might have a better chance running that with Vitest browser mode instead https://vitest.dev/guide/browser/

If you really need to test wasm binding on non browser mode Vitest, then it might require some restructuring like I suggested previously in a different issue #5704 (comment)

from vitest.

sheremet-va avatar sheremet-va commented on August 16, 2024 1

Vite and Vitest resolve the same value of import, but as I said in the previous comment, the environment where it runs is different, so how you use the value depends on your use case.

In your code you pass the value to fetch - in the browser, it resolves the URL relative to the server origin (http://localhost + /gsa.wasm), but on the server fetch doesn't have this information and it requires a full URL :) (just /gsa.wasm is not a valid URL)

from vitest.

Zxilly avatar Zxilly commented on August 16, 2024

I search the issue previously, seems the browser mode won't collect the coverage for the worker?

from vitest.

hi-ogawa avatar hi-ogawa commented on August 16, 2024

Right, I think you're referring this issue and coverage is not supported #4899 (comment)

from vitest.

Zxilly avatar Zxilly commented on August 16, 2024

I created a hack to import the wasm in the normal test file and mock it to the worker, please see Zxilly/go-size-analyzer@45149d9

from vitest.

Zxilly avatar Zxilly commented on August 16, 2024

But I don't understand why in this case worker.ts is still not covered by coverage.

image

from vitest.

Zxilly avatar Zxilly commented on August 16, 2024

After switch to v8 coverage provider things got resolved.

from vitest.

sheremet-va avatar sheremet-va commented on August 16, 2024

?url actually resolves the file as an absolute pathname (this is Vite feature, not Vitest). To make it a valid file you still need an origin like http://localhost - but since in Node.js there is no origin, you should probably resolve it to a file:// yourself somehow.

Closing this as it's working as expected.

from vitest.

Zxilly avatar Zxilly commented on August 16, 2024

As https://vitest.dev/guide/why.html suggested

A test runner that uses the same configuration of your App (through ), sharing a common transformation pipeline during dev, build, and test time.

I think keep this behavior same between the vite and vitest is meaningful.

from vitest.

sheremet-va avatar sheremet-va commented on August 16, 2024

This is why we keep the behaviour :)

Vite and Vitest resolve the same value of import, but as I said in the previous comment, the environment where it runs is different, so how you use the value depends on your use case.

from vitest.

Zxilly avatar Zxilly commented on August 16, 2024

I understand that, maybe need to setup a transformer for node environment. Thanks.

from vitest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.