Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
xia0hj committed Dec 28, 2023
1 parent 2fd1c42 commit 2bab62d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1715,3 +1715,36 @@ test('.d.ts files should be cleaned when --clean and --experimental-dts are prov
expect(result3.outFiles).not.toContain('bar.d.ts')
expect(result3.outFiles).not.toContain('bar.js')
})

test('generate sourcemap with --treeshake', async () => {
const { outFiles, getFileContent } = await run(
getTestName(),
{
'src/input.ts': 'export function getValue(val: any){ return val; }',
},
{
entry: ['src/input.ts'],
flags: ['--treeshake', '--sourcemap', '--format=cjs,esm,iife'],
}
)

expect(outFiles.length).toBe(6)

await Promise.all(
outFiles
.filter((fileName) => fileName.endsWith('.map'))
.map(async (sourceMapFile) => {
const sourceMap = await getFileContent(`dist/${sourceMapFile}`).then(
(rawContent) => JSON.parse(rawContent)
)

expect(sourceMap.sources[0]).toBe('../src/input.ts')
expect(sourceMap.sourcesContent[0]).toBe(
'export function getValue(val: any){ return val; }'
)

const outputFileName = sourceMapFile.replace('.map', '')
expect(sourceMap.file).toBe(outputFileName)
})
)
})

0 comments on commit 2bab62d

Please sign in to comment.