-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better tests for CF Workers, Bun and Azure Functions & Update Azure e…
…xample & Fix `event.request` ref issue in CFW (#1101)
- Loading branch information
Showing
19 changed files
with
132 additions
and
120 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 @@ | ||
--- | ||
"@whatwg-node/server": patch | ||
--- | ||
|
||
Access the property in the given server context object correctly |
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
*.js.map | ||
*.ts | ||
.git* | ||
.vscode | ||
local.settings.json | ||
test | ||
getting_started.md | ||
node_modules/@types/ | ||
node_modules/azure-functions-core-tools/ | ||
node_modules/typescript/ |
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,3 @@ | ||
{ | ||
"recommendations": ["ms-azuretools.vscode-azurefunctions"] | ||
} |
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,15 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingSettings": { | ||
"isEnabled": true, | ||
"excludedTypes": "Request" | ||
} | ||
} | ||
}, | ||
"extensionBundle": { | ||
"id": "Microsoft.Azure.Functions.ExtensionBundle", | ||
"version": "[4.*, 5.0.0)" | ||
} | ||
} |
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,16 @@ | ||
import { app, InvocationContext } from '@azure/functions'; | ||
import { createTestServerAdapter } from '@e2e/shared-server'; | ||
|
||
const handler = createTestServerAdapter<InvocationContext>(); | ||
|
||
declare global { | ||
interface ReadableStream { | ||
[Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array>; | ||
} | ||
} | ||
|
||
app.http('whatwgnode', { | ||
methods: ['GET', 'POST'], | ||
authLevel: 'anonymous', | ||
handler, | ||
}); |
This file was deleted.
Oops, something went wrong.
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,29 +1,50 @@ | ||
import { createServer } from 'node:http'; | ||
import { describe, expect, it } from 'bun:test'; | ||
import { afterEach, describe, expect, it } from 'bun:test'; | ||
import { createServerAdapter } from '@whatwg-node/server'; | ||
import { assertDeployedEndpoint } from '../../shared-scripts/src/index'; | ||
import { createTestServerAdapter } from '../../shared-server/src/index'; | ||
|
||
describe('Bun', () => { | ||
let stopServer: () => void; | ||
afterEach(() => stopServer?.()); | ||
it('works', async () => { | ||
const server = Bun.serve({ | ||
fetch: createTestServerAdapter(), | ||
port: 3000, | ||
}); | ||
stopServer = () => server.stop(true); | ||
try { | ||
await assertDeployedEndpoint(`http://localhost:3000/graphql`); | ||
} catch (e) { | ||
expect(e).toBeUndefined(); | ||
} | ||
server.stop(true); | ||
}); | ||
it('should have unique contexts for each request', async () => { | ||
const contexts = new Set(); | ||
const adapter = createServerAdapter((_, ctx) => { | ||
contexts.add(ctx); | ||
return new Response(null, { | ||
status: 204, | ||
}); | ||
}); | ||
const server = Bun.serve({ | ||
fetch: adapter, | ||
port: 3000, | ||
}); | ||
stopServer = () => server.stop(true); | ||
for (let i = 0; i < 10; i++) { | ||
await fetch(`http://localhost:3000/graphql`); | ||
} | ||
expect(contexts.size).toBe(10); | ||
}); | ||
it('works with Node compat mode', async () => { | ||
const server = createServer(createTestServerAdapter()); | ||
stopServer = () => server.close(); | ||
await new Promise<void>(resolve => server.listen(3000, resolve)); | ||
try { | ||
await assertDeployedEndpoint(`http://localhost:3000/graphql`); | ||
} catch (e) { | ||
expect(e).toBeUndefined(); | ||
} | ||
return new Promise(resolve => server.close(resolve)); | ||
}); | ||
}); |
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,8 +1,7 @@ | ||
import { createTestServerAdapter } from '@e2e/shared-server'; | ||
|
||
const app = createTestServerAdapter(); | ||
|
||
export default { | ||
async fetch(request: Request, env: Record<string, string>, ctx: any): Promise<Response> { | ||
const app = createTestServerAdapter(); | ||
return app.handle(request, env, ctx); | ||
}, | ||
fetch: app, | ||
}; |
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,5 +1,13 @@ | ||
import { createTestServerAdapter } from '@e2e/shared-server'; | ||
import { createServerAdapter, type FetchEvent } from '@whatwg-node/server'; | ||
|
||
const app = createTestServerAdapter(); | ||
const app = createServerAdapter<FetchEvent>(async (request, ctx) => | ||
Response.json({ | ||
url: request.url, | ||
method: request.method, | ||
headers: Object.fromEntries(request.headers.entries()), | ||
reqText: request.method === 'POST' ? await request.text() : '', | ||
reqExistsInCtx: ctx.request === request, | ||
}), | ||
); | ||
|
||
self.addEventListener('fetch', app); |
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
Oops, something went wrong.