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

Error when running with jest #4

Open
AaronVasquez opened this issue May 10, 2018 · 5 comments
Open

Error when running with jest #4

AaronVasquez opened this issue May 10, 2018 · 5 comments
Labels
question Further information is requested

Comments

@AaronVasquez
Copy link

console.error node_modules/jsdom-worker/dist/jsdom-inline-worker.js:1
    Error: only absolute urls are supported
        at /Users/aaronvasquez/Oyster/webnode/directories/node_modules/node-fetch/index.js:54:10
        at new Promise (<anonymous>)
        at new Fetch (/Users/aaronvasquez/Oyster/webnode/directories/node_modules/node-fetch/index.js:49:9)
        at Fetch (/Users/aaronvasquez/Oyster/webnode/directories/node_modules/node-fetch/index.js:37:10)
        at Object.<anonymous>.global.fetch (/Users/aaronvasquez/Oyster/webnode/directories/node_modules/jsdom-worker/dist/jsdom-inline-worker.js:1:876)
        at new Worker (/Users/aaronvasquez/Oyster/webnode/directories/node_modules/jsdom-worker/dist/jsdom-inline-worker.js:1:1780)
        at /Users/aaronvasquez/Oyster/webnode/directories/src/utils/bg-worker/index.js:12:29
        at new Promise (<anonymous>)
        at performTask (/Users/aaronvasquez/Oyster/webnode/directories/src/utils/bg-worker/index.js:11:5)
        at Object.<anonymous> (/Users/aaronvasquez/Oyster/webnode/directories/src/utils/bg-worker/bg-worker.test.js:9:29)
        at resolve (/Users/aaronvasquez/Oyster/webnode/directories/node_modules/jest-jasmine2/build/queueRunner.js:38:12)
        at new Promise (<anonymous>)
        at mapper (/Users/aaronvasquez/Oyster/webnode/directories/node_modules/jest-jasmine2/build/queueRunner.js:31:21)
        at Promise.resolve.then.el (/Users/aaronvasquez/Oyster/webnode/directories/node_modules/p-map/index.js:46:16)
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:188:7)

This is what I have in my test file:

import "jsdom-worker";
@developit
Copy link
Owner

What are you passing to new Worker()?

@developit developit added the question Further information is requested label May 22, 2018
@ultr7A
Copy link

ultr7A commented Sep 8, 2018

I ran into the same issue.
Looking here, https://github.com/bitinn/node-fetch/blob/1d4ab5a0de0df991f92f1f30efd5f4815bbcdb71/src/request.js#L161 I see it needs to have a protocol specified. The problem is that file:// isn't supported

Error: only http(s) protocols are supported
          at ...node_modules\jsdom-worker\node_modules\node-fetch\index.js:58:10

@developit
Copy link
Owner

Ah - we'll need to have self.fetch in the worker context patch URLs it receives to rebase them.

@neptunian
Copy link

is there a workaround or this possible to fix?

@astagi
Copy link

astagi commented Sep 8, 2020

This is an old issue, but I have the same problem in my code (I opened a similar issue #14 ). In my tests tried to load a module where my Worker code lives but Node fetch seems to work only with absolute urls. I mocked fetch to load my module source and then I compiled it using babel/core. I also had to modify jsdom-worker source code to make it work. That wasn't a clean solution :( Since I started my project using Webpack worker-loader (https://webpack.js.org/loaders/worker-loader/) and using Jest as test framework, I created a little transformer to test workers inspired by jsdom-worker (https://github.com/astagi/workerloader-jest-transformer). I hope this may help someone! (note that workerloader-jest-transformer is highly experimental, any contribution and advice would be greatly appreciated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants