Skip to content

Commit 5c01c57

Browse files
committed
test: emit cjs
1 parent 1f58d39 commit 5c01c57

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`emit cjs 1`] = `
4+
"// index.d.cts
5+
6+
//#region tests/fixtures/emit-cjs/mod.d.ts
7+
declare const _default: number;
8+
9+
//#endregion
10+
export { _default as default };
11+
// index.d.ts
12+
13+
//#region tests/fixtures/emit-cjs/mod.d.ts
14+
declare const _default: number;
15+
16+
//#endregion
17+
export { _default as default };
18+
// index.js
19+
20+
//#region tests/fixtures/emit-cjs/mod.ts
21+
var emit_cjs_default$1 = 42;
22+
23+
//#endregion
24+
//#region tests/fixtures/emit-cjs/index.ts
25+
var emit_cjs_default = emit_cjs_default$1;
26+
27+
//#endregion
28+
export { emit_cjs_default as default };"
29+
`;

tests/cjs.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import path from 'node:path'
2+
import { fileURLToPath } from 'node:url'
3+
import { rolldownBuild } from '@sxzz/test-utils'
4+
import { expect, test } from 'vitest'
5+
import { dts } from '../src'
6+
7+
const dirname = path.dirname(fileURLToPath(import.meta.url))
8+
9+
test('emit cjs', async () => {
10+
const root = path.resolve(dirname, 'fixtures/emit-cjs')
11+
12+
const { snapshot } = await rolldownBuild(path.resolve(root, 'index.ts'), [
13+
dts({
14+
emitCJS: true,
15+
}),
16+
])
17+
expect(snapshot).toMatchSnapshot()
18+
})

tests/fixtures/emit-cjs/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import n from './mod'
2+
export default n

tests/fixtures/emit-cjs/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 42

0 commit comments

Comments
 (0)