Skip to content

Commit 1e27556

Browse files
committed
test: add test case that import module that does not exist
1 parent 66cba91 commit 1e27556

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

  • packages/edge-bundler

packages/edge-bundler/node/bundler.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,65 @@ describe.skipIf(lt(denoVersion, '2.4.2'))(
12521252

12531253
await cleanup()
12541254
})
1255+
1256+
test('Importing not existing module when caught is handled', async () => {
1257+
const systemLogger = vi.fn()
1258+
const { basePath, cleanup, distPath } = await useFixture('caught-module-not-found-import', {
1259+
copyDirectory: true,
1260+
})
1261+
const declarations: Declaration[] = [
1262+
{
1263+
function: 'func1',
1264+
path: '/func1',
1265+
},
1266+
]
1267+
1268+
await bundle([join(basePath, 'netlify/edge-functions')], distPath, declarations, {
1269+
basePath,
1270+
configPath: join(basePath, '.netlify/edge-functions/config.json'),
1271+
importMapPaths: [resolve(basePath, 'import_map.json')],
1272+
featureFlags: {
1273+
edge_bundler_generate_tarball: true,
1274+
},
1275+
systemLogger,
1276+
})
1277+
1278+
expect(
1279+
systemLogger.mock.calls.find((call) => call[0] === 'Could not track dependencies in edge function:'),
1280+
).toBeUndefined()
1281+
1282+
const expectedOutput = {
1283+
func1: 'ok',
1284+
}
1285+
1286+
const manifestFile = await readFile(resolve(distPath, 'manifest.json'), 'utf8')
1287+
const manifest = JSON.parse(manifestFile)
1288+
1289+
expect(manifest.bundling_timing).toEqual({ tarball_ms: expect.any(Number) })
1290+
1291+
const tarballPath = join(distPath, manifest.bundles[0].asset)
1292+
const tarballResult = await runTarball(tarballPath)
1293+
expect(tarballResult).toStrictEqual(expectedOutput)
1294+
1295+
const entries: string[] = []
1296+
1297+
await tar.list({
1298+
file: tarballPath,
1299+
onReadEntry: (entry) => {
1300+
entries.push(entry.path)
1301+
},
1302+
})
1303+
1304+
expect(entries).toContain('./___netlify-edge-functions.json')
1305+
expect(entries).toContain('./deno.json')
1306+
expect(entries).toContain('./func1.ts')
1307+
1308+
const eszipPath = join(distPath, manifest.bundles[1].asset)
1309+
const eszipResult = await runESZIP(eszipPath)
1310+
expect(eszipResult).toStrictEqual(expectedOutput)
1311+
1312+
await cleanup()
1313+
})
12551314
},
12561315
10_000,
12571316
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
try {
2+
await import("./some-module-that-does-not-exist.js");
3+
} catch (error) {
4+
console.error("Error importing module but we continue anyway:", error);
5+
}
6+
7+
export default function Handler() {
8+
return new Response("ok");
9+
}
10+
11+
export const config = {
12+
path: "/*",
13+
};

0 commit comments

Comments
 (0)