@whatwg-node/fetch 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @whatwg-node/fetch
2
2
 
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`a8a7cfc`](https://github.com/ardatan/whatwg-node/commit/a8a7cfcbb98c5ca8fff3b4a6d8638e9208690b61) Thanks [@ardatan](https://github.com/ardatan)! - Fix for new undici
8
+
3
9
  ## 0.5.0
4
10
 
5
11
  ### Minor Changes
@@ -122,6 +122,9 @@ module.exports = function createNodePonyfill(opts = {}) {
122
122
  class Request extends OriginalRequest {
123
123
  constructor(requestOrUrl, options) {
124
124
  if (typeof requestOrUrl === "string" || requestOrUrl instanceof URL) {
125
+ if (options != null && typeof options === "object" && !options.duplex) {
126
+ options.duplex = 'half';
127
+ }
125
128
  super(requestOrUrl, options);
126
129
  const contentType = this.headers.get("content-type");
127
130
  if (contentType && contentType.startsWith("multipart/form-data")) {
@@ -140,6 +143,9 @@ module.exports = function createNodePonyfill(opts = {}) {
140
143
 
141
144
  const fetch = function (requestOrUrl, options) {
142
145
  if (typeof requestOrUrl === "string" || requestOrUrl instanceof URL) {
146
+ if (options != null && typeof options === "object" && !options.duplex) {
147
+ options.duplex = 'half';
148
+ }
143
149
  // We cannot use our ctor because it leaks on Node 18's global fetch
144
150
  return originalFetch(requestOrUrl, options);
145
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/fetch",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Cross Platform Smart Fetch Ponyfill",
5
5
  "author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
6
6
  "repository": {
@@ -24,7 +24,7 @@
24
24
  "form-data-encoder": "^1.7.1",
25
25
  "formdata-node": "^4.3.1",
26
26
  "node-fetch": "^2.6.7",
27
- "undici": "^5.10.0",
27
+ "undici": "^5.12.0",
28
28
  "web-streams-polyfill": "^3.2.0"
29
29
  },
30
30
  "publishConfig": {
@@ -1,38 +1,36 @@
1
1
  import { createTestContainer } from '../../server/test/create-test-container';
2
2
 
3
3
  describe('getFormDataMethod', () => {
4
- createTestContainer(
5
- fetchAPI => {
6
- it('should parse fields correctly', async () => {
7
- const formData = new fetchAPI.FormData();
8
- formData.append('greetings', 'Hello world!');
9
- formData.append('bye', 'Goodbye world!');
10
- const request = new fetchAPI.Request('http://localhost:8080', {
11
- method: 'POST',
12
- body: formData,
13
- });
14
- const formdata = await request.formData();
15
- expect(formdata.get('greetings')).toBe('Hello world!');
16
- expect(formdata.get('bye')).toBe('Goodbye world!');
4
+ createTestContainer(fetchAPI => {
5
+ it('should parse fields correctly', async () => {
6
+ const formData = new fetchAPI.FormData();
7
+ formData.append('greetings', 'Hello world!');
8
+ formData.append('bye', 'Goodbye world!');
9
+ const request = new fetchAPI.Request('http://localhost:8080', {
10
+ method: 'POST',
11
+ body: formData,
17
12
  });
18
- it('should parse and receive text files correctly', async () => {
19
- const formData = new fetchAPI.FormData();
20
- const greetingsFile = new fetchAPI.File(['Hello world!'], 'greetings.txt', { type: 'text/plain' });
21
- const byeFile = new fetchAPI.File(['Goodbye world!'], 'bye.txt', { type: 'text/plain' });
22
- formData.append('greetings', greetingsFile);
23
- formData.append('bye', byeFile);
24
- const request = new fetchAPI.Request('http://localhost:8080', {
25
- method: 'POST',
26
- body: formData,
27
- });
28
- const formdata = await request.formData();
29
- const receivedGreetingsFile = formdata.get('greetings') as File;
30
- const receivedGreetingsText = await receivedGreetingsFile.text();
31
- expect(receivedGreetingsText).toBe('Hello world!');
32
- const receivedByeFile = formdata.get('bye') as File;
33
- const receivedByeText = await receivedByeFile.text();
34
- expect(receivedByeText).toBe('Goodbye world!');
13
+ const formdata = await request.formData();
14
+ expect(formdata.get('greetings')).toBe('Hello world!');
15
+ expect(formdata.get('bye')).toBe('Goodbye world!');
16
+ });
17
+ it('should parse and receive text files correctly', async () => {
18
+ const formData = new fetchAPI.FormData();
19
+ const greetingsFile = new fetchAPI.File(['Hello world!'], 'greetings.txt', { type: 'text/plain' });
20
+ const byeFile = new fetchAPI.File(['Goodbye world!'], 'bye.txt', { type: 'text/plain' });
21
+ formData.append('greetings', greetingsFile);
22
+ formData.append('bye', byeFile);
23
+ const request = new fetchAPI.Request('http://localhost:8080', {
24
+ method: 'POST',
25
+ body: formData,
35
26
  });
36
- }
37
- );
27
+ const formdata = await request.formData();
28
+ const receivedGreetingsFile = formdata.get('greetings') as File;
29
+ const receivedGreetingsText = await receivedGreetingsFile.text();
30
+ expect(receivedGreetingsText).toBe('Hello world!');
31
+ const receivedByeFile = formdata.get('bye') as File;
32
+ const receivedByeText = await receivedByeFile.text();
33
+ expect(receivedByeText).toBe('Goodbye world!');
34
+ });
35
+ });
38
36
  });