-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
152 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@edge-runtime/primitives': patch | ||
--- | ||
|
||
Don't use require.resolve for the custom import resolution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@edge-runtime/vm': patch | ||
--- | ||
|
||
simplify primitives loading in VM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export { TextEncoder, TextDecoder } from 'text-encoding' | ||
export const atob = enc => Buffer.from(enc, 'base64').toString('binary') | ||
export const btoa = str => Buffer.from(str, 'binary').toString('base64') | ||
export const atob = (enc) => Buffer.from(enc, 'base64').toString('binary') | ||
export const btoa = (str) => Buffer.from(str, 'binary').toString('base64') | ||
|
||
const TE = TextEncoder | ||
const TD = TextDecoder | ||
|
||
export { TE as TextEncoder, TD as TextDecoder } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { createServer } from 'http' | ||
import listen from 'test-listen' | ||
import { EdgeVM } from '../src' | ||
|
||
test('fetch within vm', async () => { | ||
const server = createServer((req, res) => { | ||
res.write(`Hello from ${req.url}`) | ||
res.end() | ||
}) | ||
try { | ||
const url = await listen(server) | ||
const vm = new EdgeVM() | ||
|
||
const result = await vm.evaluate(`fetch("${url}/foo")`) | ||
expect(await result.text()).toBe(`Hello from /foo`) | ||
} finally { | ||
server.close() | ||
} | ||
}) | ||
|
||
test('sends a Uint8Array', async () => { | ||
const server = createServer(async (req, res) => { | ||
const chunks = [] as Buffer[] | ||
for await (const chunk of req) { | ||
chunks.push(chunk) | ||
} | ||
const body = Buffer.concat(chunks).toString() | ||
res.write(`Hello from ${req.url} with body ${body}`) | ||
res.end() | ||
}) | ||
try { | ||
const url = await listen(server) | ||
const vm = new EdgeVM() | ||
|
||
const result = await vm.evaluate( | ||
`fetch("${url}/foo", { method: "POST", body: new Uint8Array([104, 105, 33]) })` | ||
) | ||
expect(await result.text()).toBe(`Hello from /foo with body hi!`) | ||
} finally { | ||
server.close() | ||
} | ||
}) |
Oops, something went wrong.
a9054f7
There was a problem hiding this comment.
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