Skip to content

Commit 45c5f3a

Browse files
authored
test(typescript): Add preserveModules test (#234)
1 parent a66c8c7 commit 45c5f3a

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-disable */
2+
const b = () => {
3+
const a = { a: 1, b: 2 };
4+
console.log({ ...a });
5+
};
6+
7+
export { b };
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"downlevelIteration": true,
5+
"esModuleInterop": true,
6+
"forceConsistentCasingInFileNames": true,
7+
"module": "esnext",
8+
"strict": true,
9+
"target": "es5"
10+
}
11+
}

packages/typescript/test/test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,19 @@ test('should throw on bad options', async (t) => {
589589
]);
590590
});
591591

592+
test('creates _tslib.js file when preserveModules is used', async (t) => {
593+
const bundle = await rollup({
594+
input: 'fixtures/preserve-modules/main.ts',
595+
plugins: [typescript({ tsconfig: 'fixtures/preserve-modules/tsconfig.json' })],
596+
preserveModules: true,
597+
onwarn
598+
});
599+
600+
const files = await getCode(bundle, { format: 'es' }, true);
601+
t.true(files[0].fileName.includes('main.js'), files[0].fileName);
602+
t.true(files[1].fileName.includes('tslib.es6.js'), files[1].fileName);
603+
});
604+
592605
test('should handle re-exporting types', async (t) => {
593606
const bundle = await rollup({
594607
input: 'fixtures/reexport-type/main.ts',

0 commit comments

Comments
 (0)