Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vercel E2E tests back #244

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sixty-rings-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@whatwg-node/server': patch
---

Fixes for Next.js
3 changes: 1 addition & 2 deletions .github/workflows/deployment-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
plan: ['aws-lambda', 'azure-function', 'cloudflare-workers', 'cloudflare-modules', 'deno']
# TODO: Add vercel
plan: ['aws-lambda', 'azure-function', 'cloudflare-workers', 'cloudflare-modules', 'deno', 'vercel']
name: e2e / ${{ matrix.plan }}

runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion e2e/vercel/scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { build } = require('esbuild');
async function main() {
await build({
entryPoints: ['./src/index.ts'],
outfile: 'pages/api/whatwgnode.js',
outfile: 'pages/api/[...slug].js',
format: 'cjs',
minify: false,
bundle: true,
Expand Down
13 changes: 5 additions & 8 deletions e2e/vercel/scripts/createVercelDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
execPromise,
fsPromises,
DeploymentConfiguration,
assertIndex,
waitForEndpoint,
assertDeployedEndpoint,
} from '@e2e/shared-scripts';
import { join } from 'path';

Expand Down Expand Up @@ -124,13 +123,13 @@ export function createVercelDeployment(): DeploymentConfiguration<{
const deployment = new VercelDeployment('vercel-function', {
files: [
{
file: '/api/whatwgnode.js',
data: await fsPromises.readFile(join(__dirname, '..', 'pages', 'api', 'whatwgnode.js'), 'utf-8'),
file: '/api/[...slug].js',
data: await fsPromises.readFile(join(__dirname, '..', 'pages', 'api', '[...slug].js'), 'utf-8'),
},
],
name: `whatwg-node-e2e-testing`,
functions: {
'api/whatwgnode.js': {
'api/[...slug].js': {
memory: 256,
maxDuration: 5,
},
Expand All @@ -146,9 +145,7 @@ export function createVercelDeployment(): DeploymentConfiguration<{
},
test: async ({ functionUrl }) => {
console.log(`ℹ️ Vercel Function deployed to URL: ${functionUrl.value}`);
// await assertDeployedEndpoint(functionUrl.value);
await waitForEndpoint(functionUrl.value, 5, 10000);
assertIndex(functionUrl.value);
await assertDeployedEndpoint(functionUrl.value);
},
};
}
6 changes: 3 additions & 3 deletions packages/server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ export async function sendNodeResponse({ headers, status, statusText, body }: Re
// eslint-disable-next-line no-async-promise-executor
return new Promise<void>(async resolve => {
if (body == null) {
serverResponse.end(resolve);
serverResponse.end('', resolve);
} else if (body[Symbol.toStringTag] === 'Uint8Array') {
serverResponse
// @ts-expect-error http and http2 writes are actually compatible
.write(body);
serverResponse.end(resolve);
serverResponse.end('', resolve);
} else if (isReadable(body)) {
serverResponse.once('close', () => {
body.destroy();
Expand All @@ -195,7 +195,7 @@ export async function sendNodeResponse({ headers, status, statusText, body }: Re
break;
}
}
serverResponse.end(resolve);
serverResponse.end('', resolve);
}
});
}
Expand Down