Skip to content

Commit

Permalink
Merge pull request #156 from vercel/dependabot/npm_and_yarn/undici-5.…
Browse files Browse the repository at this point in the history
…11.0

build(deps-dev): bump undici from 5.10.0 to 5.11.0
  • Loading branch information
Kikobeats authored Oct 4, 2022
2 parents b32d227 + 37e7901 commit c61ce8b
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 113 deletions.
6 changes: 6 additions & 0 deletions .changeset/tasty-paws-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@edge-runtime/primitives": patch
"@edge-runtime/vm": patch
---

build(deps-dev): bump undici from 5.10.0 to 5.11.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@changesets/cli": "latest",
"@jest/types": "28.1.3",
"@svitejs/changesets-changelog-github-compact": "latest",
"@types/jest": "latest",
"@types/jest": "28.1.3",
"@types/node": "12",
"c8": "latest",
"finepack": "latest",
Expand Down
2 changes: 1 addition & 1 deletion packages/primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"formdata-node": "4.4.1",
"text-encoding": "0.7.0",
"tsup": "6",
"undici": "5.10.0",
"undici": "5.11.0",
"urlpattern-polyfill": "6.0.1",
"uuid": "9.0.0",
"web-streams-polyfill": "4.0.0-beta.3",
Expand Down
4 changes: 1 addition & 3 deletions packages/primitives/src/primitives/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ export function createCaches() {
})
} catch (error) {
if (error.message === 'disturbed') {
throw new TypeError(
"Failed to execute 'put' on 'Cache': Response body is already used"
)
throw new TypeError('The body has already been consumed.')
}
throw error
}
Expand Down
2 changes: 1 addition & 1 deletion packages/primitives/src/primitives/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as ResponseModule from 'undici/lib/fetch/response'
import * as UtilModule from 'undici/lib/fetch/util'
import * as WebIDLModule from 'undici/lib/fetch/webidl'

import fetchImpl from 'undici/lib/fetch'
import { fetch as fetchImpl } from 'undici/lib/fetch'
import Agent from 'undici/lib/agent'

global.AbortController = AbortController
Expand Down
4 changes: 1 addition & 3 deletions packages/primitives/tests/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ test('cache.put throws an error if response body is used or locked', async () =>
await cache.put(request, response)
} catch (error: any) {
expect(error instanceof Error).toBe(true)
expect(error.message).toBe(
"Failed to execute 'put' on 'Cache': Response body is already used"
)
expect(error.message).toBe('The body has already been consumed.')
}
})

Expand Down
32 changes: 25 additions & 7 deletions packages/primitives/tests/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetch } from '../fetch'
import { FormData, fetch } from '../fetch'
import { URL } from '../url'

test('perform a POST as application/json', async () => {
Expand All @@ -10,9 +10,10 @@ test('perform a POST as application/json', async () => {
},
})

expect(response.status).toEqual(200)
expect(response.status).toBe(200)
const json = await response.json()
expect(JSON.parse(json.data).foo).toBe('bar')
expect(JSON.parse(json.data)).toEqual({ foo: 'bar' })
expect(json.headers['Content-Type']).toBe('application/json')
})

test('perform a POST as application/x-www-form-urlencoded', async () => {
Expand All @@ -24,15 +25,32 @@ test('perform a POST as application/x-www-form-urlencoded', async () => {
body: new URLSearchParams({ foo: 'bar' }),
})

expect(response.status).toEqual(200)
expect(response.status).toBe(200)
const json = await response.json()
expect(json.form.foo).toBe('bar')
expect(json.form).toEqual({ foo: 'bar' })
expect(json.headers['Content-Type']).toBe('application/x-www-form-urlencoded')
})

test('perform a POST as multipart/form-data', async () => {
const formData = new FormData()
formData.append('company', 'vercel')
formData.append('project', 'edge-runtime')

const response = await fetch('https://httpbin.org/post', {
method: 'POST',
body: formData,
})

expect(response.status).toBe(200)
const json = await response.json()
expect(json.form).toEqual({ company: 'vercel', project: 'edge-runtime' })
expect(json.headers['Content-Type']).toContain('multipart/form-data')
})

test('sets header calling Headers constructor', async () => {
const url = new URL('/about', 'https://vercel.com')
const response = await fetch(url)
expect(response.status).toEqual(200)
expect(response.status).toBe(200)
})

test('sets headers unsupported in undici', async () => {
Expand All @@ -44,5 +62,5 @@ test('sets headers unsupported in undici', async () => {
'Transfer-Encoding': 'gzip',
},
})
expect(response.status).toEqual(200)
expect(response.status).toBe(200)
})
1 change: 1 addition & 0 deletions packages/vm/src/edge-vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function addPrimitives(context: VMContext) {
['http', { exports: require('http') }],
['net', { exports: require('net') }],
['perf_hooks', { exports: require('perf_hooks') }],
['querystring', { exports: require('querystring') }],
['stream', { exports: require('stream') }],
['tls', { exports: require('tls') }],
['util', { exports: require('util') }],
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/tests/integration/body.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ it('throws when the body was directly consumed', async () => {
const error = await response.text().catch((err) => err)

expect(error).toBeInstanceOf(TypeError)
expect(error.message).toEqual('locked')
expect(error.message).toEqual('The stream is locked.')
})

test('throws when the body was indirectly consumed', async () => {
Expand All @@ -64,7 +64,7 @@ test('throws when the body was indirectly consumed', async () => {
const error = await response.text().catch((err) => err)

expect(error).toBeInstanceOf(TypeError)
expect(error.message).toEqual('disturbed')
expect(error.message).toEqual('The body has already been consumed.')
})

test('allows to read a FormData body as text', async () => {
Expand Down
Loading

1 comment on commit c61ce8b

@vercel
Copy link

@vercel vercel bot commented on c61ce8b Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

edge-runtime – ./

edge-runtime.vercel.app
edge-runtime.vercel.sh
edge-runtime-git-main.vercel.sh

Please sign in to comment.