Files
vercel/packages/node/test/unit/serverless-handler/dynamic-import.test.ts
Kiko Beats 6dded87426 [node] Add streaming support for vc dev (#9745)
Until now, the user code response it's buffered and serialized. This is
mismatching how Vercel works these days.

This PR enables streaming response in `vc dev` for Edge/Serverless.

As part of the implementation, the `node-bridge` which spawns a process
to consume the user code is not necessary anymore.

Some necessary files (like HTTP server helpers) have been moved to live
in node builder package instead.

---------

Co-authored-by: Ethan Arrowood <ethan.arrowood@vercel.com>
Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2023-04-19 23:56:41 +02:00

34 lines
800 B
TypeScript

// @ts-expect-error
import { dynamicImport } from '../../../src/serverless-functions/dynamic-import.js';
import { resolve } from 'path';
describe('dynamic-import', () => {
test('load esm code', async () => {
const entrypointPath = resolve(
__dirname,
'../../dev-fixtures/esm-module.mjs'
);
const fn = await dynamicImport(entrypointPath);
let buffer = '';
const headers: Record<string, string> = {};
const res = {
send: (data: string) => {
buffer = data;
return res;
},
setHeader: (key: string, value: string) => (headers[key] = value),
end: () => {},
};
const req = {};
fn.default(req, res);
expect(buffer).toBe('Hello, world!');
expect(headers).toStrictEqual({ 'x-hello': 'world' });
});
});