@whatwg-node/fetch
Advanced tools
Comparing version 0.5.0 to 0.5.1-alpha-20221028013012-a9e07ae
# @whatwg-node/fetch | ||
## 0.5.1-alpha-20221028013012-a9e07ae | ||
### Patch Changes | ||
- [`a8a7cfc`](https://github.com/ardatan/whatwg-node/commit/a8a7cfcbb98c5ca8fff3b4a6d8638e9208690b61) Thanks [@ardatan](https://github.com/ardatan)! - Fix for new undici | ||
## 0.5.0 | ||
@@ -4,0 +10,0 @@ |
@@ -125,2 +125,5 @@ const handleFileRequest = require("./handle-file-request"); | ||
if (typeof requestOrUrl === "string" || requestOrUrl instanceof URL) { | ||
if (options != null && typeof options === "object" && !options.duplex) { | ||
options.duplex = 'half'; | ||
} | ||
super(requestOrUrl, options); | ||
@@ -144,2 +147,5 @@ const contentType = this.headers.get("content-type"); | ||
if (typeof requestOrUrl === "string" || requestOrUrl instanceof URL) { | ||
if (options != null && typeof options === "object" && !options.duplex) { | ||
options.duplex = 'half'; | ||
} | ||
// We cannot use our ctor because it leaks on Node 18's global fetch | ||
@@ -146,0 +152,0 @@ return originalFetch(requestOrUrl, options); |
{ | ||
"name": "@whatwg-node/fetch", | ||
"version": "0.5.0", | ||
"version": "0.5.1-alpha-20221028013012-a9e07ae", | ||
"description": "Cross Platform Smart Fetch Ponyfill", | ||
@@ -27,3 +27,3 @@ "author": "Arda TANRIKULU <ardatanrikulu@gmail.com>", | ||
"node-fetch": "^2.6.7", | ||
"undici": "^5.10.0", | ||
"undici": "^5.12.0", | ||
"web-streams-polyfill": "^3.2.0" | ||
@@ -30,0 +30,0 @@ }, |
import { createTestContainer } from '../../server/test/create-test-container'; | ||
describe('getFormDataMethod', () => { | ||
createTestContainer( | ||
fetchAPI => { | ||
it('should parse fields correctly', async () => { | ||
const formData = new fetchAPI.FormData(); | ||
formData.append('greetings', 'Hello world!'); | ||
formData.append('bye', 'Goodbye world!'); | ||
const request = new fetchAPI.Request('http://localhost:8080', { | ||
method: 'POST', | ||
body: formData, | ||
}); | ||
const formdata = await request.formData(); | ||
expect(formdata.get('greetings')).toBe('Hello world!'); | ||
expect(formdata.get('bye')).toBe('Goodbye world!'); | ||
createTestContainer(fetchAPI => { | ||
it('should parse fields correctly', async () => { | ||
const formData = new fetchAPI.FormData(); | ||
formData.append('greetings', 'Hello world!'); | ||
formData.append('bye', 'Goodbye world!'); | ||
const request = new fetchAPI.Request('http://localhost:8080', { | ||
method: 'POST', | ||
body: formData, | ||
}); | ||
it('should parse and receive text files correctly', async () => { | ||
const formData = new fetchAPI.FormData(); | ||
const greetingsFile = new fetchAPI.File(['Hello world!'], 'greetings.txt', { type: 'text/plain' }); | ||
const byeFile = new fetchAPI.File(['Goodbye world!'], 'bye.txt', { type: 'text/plain' }); | ||
formData.append('greetings', greetingsFile); | ||
formData.append('bye', byeFile); | ||
const request = new fetchAPI.Request('http://localhost:8080', { | ||
method: 'POST', | ||
body: formData, | ||
}); | ||
const formdata = await request.formData(); | ||
const receivedGreetingsFile = formdata.get('greetings') as File; | ||
const receivedGreetingsText = await receivedGreetingsFile.text(); | ||
expect(receivedGreetingsText).toBe('Hello world!'); | ||
const receivedByeFile = formdata.get('bye') as File; | ||
const receivedByeText = await receivedByeFile.text(); | ||
expect(receivedByeText).toBe('Goodbye world!'); | ||
const formdata = await request.formData(); | ||
expect(formdata.get('greetings')).toBe('Hello world!'); | ||
expect(formdata.get('bye')).toBe('Goodbye world!'); | ||
}); | ||
it('should parse and receive text files correctly', async () => { | ||
const formData = new fetchAPI.FormData(); | ||
const greetingsFile = new fetchAPI.File(['Hello world!'], 'greetings.txt', { type: 'text/plain' }); | ||
const byeFile = new fetchAPI.File(['Goodbye world!'], 'bye.txt', { type: 'text/plain' }); | ||
formData.append('greetings', greetingsFile); | ||
formData.append('bye', byeFile); | ||
const request = new fetchAPI.Request('http://localhost:8080', { | ||
method: 'POST', | ||
body: formData, | ||
}); | ||
} | ||
); | ||
const formdata = await request.formData(); | ||
const receivedGreetingsFile = formdata.get('greetings') as File; | ||
const receivedGreetingsText = await receivedGreetingsFile.text(); | ||
expect(receivedGreetingsText).toBe('Hello world!'); | ||
const receivedByeFile = formdata.get('bye') as File; | ||
const receivedByeText = await receivedByeFile.text(); | ||
expect(receivedByeText).toBe('Goodbye world!'); | ||
}); | ||
}); | ||
}); |
26276
543
Updatedundici@^5.12.0