Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
xia0hj authored and sxzz committed Jul 16, 2024
1 parent 0b55771 commit 15dfc0b
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 @@ -856,3 +856,36 @@ test('should load postcss esm config', async () => {
expect(outFiles).toEqual(['input.cjs', 'input.css'])
expect(await getFileContent('dist/input.css')).toContain('color: blue;')
})

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')

Check failure on line 882 in test/index.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18.x)

test/index.test.ts > generate sourcemap with --treeshake

AssertionError: expected 'input.global.js' to be '../src/input.ts' // Object.is equality - Expected + Received - ../src/input.ts + input.global.js ❯ test/index.test.ts:882:38 ❯ test/index.test.ts:874:3

Check failure on line 882 in test/index.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20.x)

test/index.test.ts > generate sourcemap with --treeshake

AssertionError: expected 'input.global.js' to be '../src/input.ts' // Object.is equality - Expected + Received - ../src/input.ts + input.global.js ❯ test/index.test.ts:882:38 ❯ test/index.test.ts:874:3
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 15dfc0b

Please sign in to comment.