Files
vercel/packages/node/test/unit/edge-handler/edge-wasm-plugin.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

47 lines
1.3 KiB
TypeScript

import { createEdgeWasmPlugin } from '../../../src/edge-functions/edge-wasm-plugin';
import { prepareFilesystem } from '../test-utils';
import { build } from 'esbuild';
import { join } from 'path';
test('fails to locate the file', async () => {
const { workPath: dir } = await prepareFilesystem({
'index.js': `
import wasm from './file.wasm?module';
console.log(wasm);
`,
});
await expect(buildWithPlugin(dir)).rejects.toThrowError(
`WebAssembly file could not be located: ./file.wasm`
);
});
test('locates the file', async () => {
const { workPath: dir } = await prepareFilesystem({
'index.js': `
import wasm from './file.wasm?module';
console.log(wasm);
`,
'file.wasm': Buffer.from('binary file'),
});
const { assets, code } = await buildWithPlugin(dir);
expect([...assets]).toHaveLength(1);
expect(code).toContain('globalThis["wasm_');
});
async function buildWithPlugin(
directory: string
): Promise<{ assets: Map<string, string>; code: string }> {
const { plugin, wasmAssets } = createEdgeWasmPlugin();
const {
outputFiles: [file],
} = await build({
bundle: true,
logLevel: 'silent',
format: 'cjs',
write: false,
plugins: [plugin],
entryPoints: [join(directory, 'index.js')],
});
return { assets: wasmAssets, code: file.text };
}