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

Vitest is using Node.js native fetch() when environment is Happy DOM #6878

Closed
6 tasks done
capricorn86 opened this issue Nov 7, 2024 · 0 comments · Fixed by #6879
Closed
6 tasks done

Vitest is using Node.js native fetch() when environment is Happy DOM #6878

capricorn86 opened this issue Nov 7, 2024 · 0 comments · Fixed by #6879

Comments

@capricorn86
Copy link
Contributor

Describe the bug

It seems like Vitest doesn't populate globalThis with the fetch() implementation from Happy DOM. However, Request and Response are populated.

This causes issues when trying to use a Request or Response object together with fetch().

Additional context
Happy DOM plans to make it easier to mock requests and improve cache handling. This will prevent that from working.

Reproduction

describe('test fetch() with Request object', () => {
   it('can use a Request object with fetch()', () => {
        const request = new Request('https://localhost:8080/myFile.json');
        
        // This will crash with the error "TypeError: Failed to parse URL from [object Request]"
        const response = await fetch(request);
        
        const json = await response.json();
        
        expect(json).not.toBeNull();
   });
});

System Info

System:
    OS: Linux 6.11 Ubuntu 24.10 24.10 (Oracular Oriole)
    CPU: (4) x64 Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz
    Memory: 4.04 GB / 14.83 GB
    Container: Yes
    Shell: 5.2.32 - /bin/bash
  Binaries:
    Node: 22.6.0 - ~/.nvm/versions/node/v22.6.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v22.6.0/bin/npm
    bun: 1.1.34 - ~/.bun/bin/bun
  Browsers:
    Chrome: 130.0.6723.58
    Chromium: 130.0.6723.69

Used Package Manager

npm

Validations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant