fix: fetch-dependent interfaces in Web Workers (#42579)

This commit is contained in:
Shelley Vohr 2024-06-20 17:01:50 +02:00 committed by GitHub
parent edb939ae80
commit 37608933ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 101 additions and 13 deletions

View file

@ -159,6 +159,38 @@ describe('node feature', () => {
});
});
describe('fetch', () => {
itremote('works correctly when nodeIntegration is enabled in the renderer', async (fixtures: string) => {
const file = require('node:path').join(fixtures, 'hello.txt');
expect(() => {
fetch('file://' + file);
}).to.not.throw();
expect(() => {
const formData = new FormData();
formData.append('username', 'Groucho');
}).not.to.throw();
expect(() => {
const request = new Request('https://example.com', {
method: 'POST',
body: JSON.stringify({ foo: 'bar' })
});
expect(request.method).to.equal('POST');
}).not.to.throw();
expect(() => {
const response = new Response('Hello, world!');
expect(response.status).to.equal(200);
}).not.to.throw();
expect(() => {
const headers = new Headers();
headers.append('Content-Type', 'text/xml');
}).not.to.throw();
}, [fixtures]);
});
it('does not hang when using the fs module in the renderer process', async () => {
const appPath = path.join(mainFixturesPath, 'apps', 'libuv-hang', 'main.js');
const appProcess = childProcess.spawn(process.execPath, [appPath], {