@@ -2,7 +2,7 @@ import fs from "fs/promises"
22import { tmpdir } from "os"
33import path from "path"
44
5- import { build , BuildResult , OutputFile } from "esbuild"
5+ import { build , BuildOptions , BuildResult , OutputFile } from "esbuild"
66import { nanoid } from "nanoid"
77import dedent from "ts-dedent"
88import { 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