mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 21:07:46 +00:00
[node] Fix ESM dependency support (#9692)
This commit is contained in:
@@ -2,7 +2,7 @@ import { forkDevServer, readMessage } from '../../src/fork-dev-server';
|
||||
import { resolve, extname } from 'path';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
jest.setTimeout(10 * 1000);
|
||||
jest.setTimeout(20 * 1000);
|
||||
|
||||
function testForkDevServer(entrypoint: string) {
|
||||
const ext = extname(entrypoint);
|
||||
@@ -10,7 +10,9 @@ function testForkDevServer(entrypoint: string) {
|
||||
const isEsm = ext === '.mjs';
|
||||
return forkDevServer({
|
||||
maybeTranspile: true,
|
||||
config: {},
|
||||
config: {
|
||||
debug: true,
|
||||
},
|
||||
isEsm,
|
||||
isTypeScript,
|
||||
meta: {},
|
||||
@@ -18,7 +20,7 @@ function testForkDevServer(entrypoint: string) {
|
||||
tsConfig: undefined,
|
||||
workPath: resolve(__dirname, '../dev-fixtures'),
|
||||
entrypoint,
|
||||
devServerPath: resolve(__dirname, '../../dist/dev-server.js'),
|
||||
devServerPath: resolve(__dirname, '../../dist/dev-server.mjs'),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
getUrl,
|
||||
respond,
|
||||
// @ts-ignore - this is a special patch file to allow importing from the template
|
||||
} from '../../../src/edge-functions/edge-handler-template.js';
|
||||
} from '../../../src/edge-functions/edge-handler-template.mjs';
|
||||
|
||||
describe('edge-handler-template', () => {
|
||||
describe('getUrl()', () => {
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createEdgeWasmPlugin } from '../../../src/edge-functions/edge-wasm-plugin';
|
||||
import { createEdgeWasmPlugin } from '../../../dist/edge-functions/edge-wasm-plugin.mjs';
|
||||
import { prepareFilesystem } from '../test-utils';
|
||||
import { build } from 'esbuild';
|
||||
import { join } from 'path';
|
||||
@@ -23,6 +23,7 @@ describe('prepareCache()', () => {
|
||||
entrypoint: '.',
|
||||
config: {},
|
||||
workPath: path.resolve(__dirname, '../cache-fixtures/foo/'),
|
||||
repoRootPath: path.resolve(__dirname, '../cache-fixtures/foo/'),
|
||||
});
|
||||
|
||||
const file = files['node_modules/file'];
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
// @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' });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user