Skip to content

Commit

Permalink
test(typescript): Add preserveModules test (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods committed Mar 2, 2020
1 parent a66c8c7 commit 45c5f3a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/typescript/test/fixtures/preserve-modules/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable */
const b = () => {
const a = { a: 1, b: 2 };
console.log({ ...a });
};

export { b };
11 changes: 11 additions & 0 deletions packages/typescript/test/fixtures/preserve-modules/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"strict": true,
"target": "es5"
}
}
13 changes: 13 additions & 0 deletions packages/typescript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,19 @@ test('should throw on bad options', async (t) => {
]);
});

test('creates _tslib.js file when preserveModules is used', async (t) => {
const bundle = await rollup({
input: 'fixtures/preserve-modules/main.ts',
plugins: [typescript({ tsconfig: 'fixtures/preserve-modules/tsconfig.json' })],
preserveModules: true,
onwarn
});

const files = await getCode(bundle, { format: 'es' }, true);
t.true(files[0].fileName.includes('main.js'), files[0].fileName);
t.true(files[1].fileName.includes('tslib.es6.js'), files[1].fileName);
});

test('should handle re-exporting types', async (t) => {
const bundle = await rollup({
input: 'fixtures/reexport-type/main.ts',
Expand Down

0 comments on commit 45c5f3a

Please sign in to comment.