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

Incompatible with with Comlink Workers #5571

Closed
6 tasks done
charlieforward9 opened this issue Apr 19, 2024 · 5 comments
Closed
6 tasks done

Incompatible with with Comlink Workers #5571

charlieforward9 opened this issue Apr 19, 2024 · 5 comments

Comments

@charlieforward9
Copy link

charlieforward9 commented Apr 19, 2024

Describe the bug

I was testing my code that uses a Comlink web worker. I followed the Testing with Web Workers instructions.

Error prior to @vitest/web-workerconfig

ReferenceError: Worker is not defined

Error after putting @vitest/web-worker into setupFiles config

[vitest] `importScripts` is not supported in Vite workers. Please, consider using `import` instead

My service worker is used as such, this is the only please a worker is used across/referenced the entire application.

const instance = new ComlinkWorker<typeof import("../service")>(new URL("../service", import.meta.url));
instance.doWork()

My understanding of service workers is still quite limited.

Reproduction

TODO ( about to 💤 on it and get back to in the AM)

System Info

System:
    OS: macOS 14.3.1
    CPU: (8) arm64 Apple M2
    Memory: 77.75 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 20.9.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.5.0 - /usr/local/bin/npm
    pnpm: 8.14.0 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 123.0.6312.124
    Safari: 17.3.1
  npmPackages:
    @vitejs/plugin-react: ^4.0.4 => 4.2.1 
    @vitest/coverage-v8: ^1.4.0 => 1.4.0 
    @vitest/web-worker: ^1.5.0 => 1.5.0 
    vite: ^5.1.3 => 5.1.3 
    vitest: ^1.4.0 => 1.4.0

Used Package Manager

npm

Validations

Tasks

No tasks being tracked yet.
Copy link

Hello @charlieforward9. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@sheremet-va
Copy link
Member

We cannot support importScripts because importing is asynchronous, but this API is synchronous. I would recommend using the browser mode instead.

@charlieforward9
Copy link
Author

charlieforward9 commented Apr 24, 2024

@sheremet-va Thank you. Is this something I should mention in the Comlink library? Or is browser mode a plenty workaround to avoid this additional work?

@charlieforward9
Copy link
Author

I am still curious about this issue. As my last comment is coming up on the 3 day mark, I am adding an additional one to prevent any automatic action from taking place, and also to add that I will be writing the tests for this module at the beginning of next week, so I hope to be adding a reproducible sample here within the next 3 days.

@sheremet-va
Copy link
Member

I don't think the comlink library can do anything to support @vitest/web-worker - it is meant to be used with the default Vite's worker handling.

Supporting importScripts is out of scope for Vitest, I would recommend testing your code in a real browser.

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants