Skip to content

Commit 65c2765

Browse files
committed
add test for minifying handler renaming
1 parent 47210c4 commit 65c2765

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/__snapshots__/plugin.test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,9 @@ var foo = (...rest) => {
154154
console.log(foo(\\"test\\"));
155155
"
156156
`;
157+
158+
exports[`minification does not rename handler function 1`] = `
159+
"
160+
function handler(event){console.log(\\"test\\")}
161+
"
162+
`;

src/plugin.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "fs/promises"
22
import { tmpdir } from "os"
33
import path from "path"
44

5-
import { build, BuildResult, OutputFile } from "esbuild"
5+
import { build, BuildOptions, BuildResult, OutputFile } from "esbuild"
66
import { nanoid } from "nanoid"
77
import dedent from "ts-dedent"
88
import { beforeEach, describe, expect, test, TestContext } from "vitest"
@@ -35,7 +35,11 @@ beforeEach(async (ctx) => {
3535
}
3636
})
3737

38-
const buildFile = async (ctx: TestContext, contents: string) => {
38+
const buildFile = async (
39+
ctx: TestContext,
40+
contents: string,
41+
extraOptions?: BuildOptions,
42+
) => {
3943
const inputFilePath = path.join(ctx.tempDirPath, "index.ts")
4044
await fs.writeFile(inputFilePath, dedent(contents))
4145

@@ -45,6 +49,8 @@ const buildFile = async (ctx: TestContext, contents: string) => {
4549

4650
target: "es5",
4751
format: "esm",
52+
53+
...extraOptions,
4854
write: false,
4955
})
5056
}
@@ -334,3 +340,19 @@ test("does not modify crypto imports", async (ctx) => {
334340
const output = getOutput(result)
335341
expect(output).toMatchSnapshot()
336342
})
343+
344+
test("minification does not rename handler function", async (ctx) => {
345+
const input = dedent`
346+
function handler(event: Record<string, unknkown>) {
347+
console.log("test")
348+
}
349+
`
350+
351+
const result = await buildFile(ctx, input, { minify: true })
352+
353+
expect(result.outputFiles).toBeDefined()
354+
355+
const output = getOutput(result)
356+
expect(output).toContain("handler(event)")
357+
expect(output).toMatchSnapshot()
358+
})

0 commit comments

Comments
 (0)