From 98f238c008618d96d4390676e103b559bc6cda1e Mon Sep 17 00:00:00 2001 From: Samantha-uk Date: Tue, 15 Dec 2020 19:30:53 +0000 Subject: [PATCH 1/3] test(typescript) test added --- packages/typescript/test/test.js | 143 ++++++++++++++++++++----------- 1 file changed, 94 insertions(+), 49 deletions(-) diff --git a/packages/typescript/test/test.js b/packages/typescript/test/test.js index 736913ff3..79dba949a 100644 --- a/packages/typescript/test/test.js +++ b/packages/typescript/test/test.js @@ -249,19 +249,29 @@ test.serial('ensures multiple outputs can be built', async (t) => { plugins: [typescript({ tsconfig: 'fixtures/multiple-files/tsconfig.json' })] }); - const output1 = await getCode(bundle1, { file: 'fixtures/multiple-files/index.js', format: 'cjs' }, true); + const output1 = await getCode( + bundle1, + { file: 'fixtures/multiple-files/index.js', format: 'cjs' }, + true + ); const bundle2 = await rollup({ input: 'fixtures/multiple-files/src/server.ts', plugins: [typescript({ tsconfig: 'fixtures/multiple-files/tsconfig.json' })] }); - const output2 = await getCode(bundle2, { file: 'fixtures/multiple-files/server.js', format: 'cjs' }, true); - - t.deepEqual( - [...new Set(output1.concat(output2).map((out) => out.fileName))].sort(), - ['index.d.ts', 'index.js', 'server.d.ts', 'server.js'] + const output2 = await getCode( + bundle2, + { file: 'fixtures/multiple-files/server.js', format: 'cjs' }, + true ); + + t.deepEqual([...new Set(output1.concat(output2).map((out) => out.fileName))].sort(), [ + 'index.d.ts', + 'index.js', + 'server.d.ts', + 'server.js' + ]); }); test.serial('relative paths in tsconfig.json are resolved relative to the file', async (t) => { @@ -1088,50 +1098,48 @@ test('supports custom transformers', async (t) => { }); function fakeTypescript(custom) { - return Object.assign( - { - sys: ts.sys, - createModuleResolutionCache: ts.createModuleResolutionCache, - ModuleKind: ts.ModuleKind, - - transpileModule() { - return { - outputText: '', - diagnostics: [], - sourceMapText: JSON.stringify({ mappings: '' }) - }; - }, - - createWatchCompilerHost() { - return { - afterProgramCreate() {} - }; - }, - - createWatchProgram() { - return {}; - }, - - parseJsonConfigFileContent(json, host, basePath, existingOptions) { - return { - options: { - ...json.compilerOptions, - ...existingOptions - }, - fileNames: [], - errors: [] - }; - }, - - getOutputFileNames(_, id) { - return [id.replace(/\.tsx?/, '.js')]; - }, - - // eslint-disable-next-line no-undefined - getTsBuildInfoEmitOutputFilePath: () => undefined + return { + sys: ts.sys, + createModuleResolutionCache: ts.createModuleResolutionCache, + ModuleKind: ts.ModuleKind, + + transpileModule() { + return { + outputText: '', + diagnostics: [], + sourceMapText: JSON.stringify({ mappings: '' }) + }; }, - custom - ); + + createWatchCompilerHost() { + return { + afterProgramCreate() {} + }; + }, + + createWatchProgram() { + return {}; + }, + + parseJsonConfigFileContent(json, host, basePath, existingOptions) { + return { + options: { + ...json.compilerOptions, + ...existingOptions + }, + fileNames: [], + errors: [] + }; + }, + + getOutputFileNames(_, id) { + return [id.replace(/\.tsx?/, '.js')]; + }, + + // eslint-disable-next-line no-undefined + getTsBuildInfoEmitOutputFilePath: () => undefined, + ...custom + }; } test.serial('picks up on newly included typescript files in watch mode', async (t) => { @@ -1208,6 +1216,43 @@ test.serial.skip('works when code is in src directory', async (t) => { ['index.js', 'types/index.d.ts', 'types/index.d.ts.map'] ); }); +/* Illustrates issue +Produces Error { + code: 'PLUGIN_ERROR', + hook: 'load', + plugin: 'typescript', + watchFiles: [ + '/plugins/packages/typescript/test/fixtures/basic/main.ts',], + message: 'Could not load /plugins/packages/typescript/test/fixtures/basic/main.ts: Debug Failure.', +} +*/ + +test.serial.skip( + 'Should support creating declaration files when not using tsconfig.json', + async (t) => { + const bundle = await rollup({ + input: 'fixtures/basic/main.ts', + plugins: [ + typescript({ + include: 'fixtures/basic/*.ts', + exclude: 'fixtures/basic/dist/types', + tsconfig: false, + declaration: true, + declarationDir: 'fixtures/basic/dist/types' + }) + ], + onwarn + }); + const output = await getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true); + + t.deepEqual( + output.map((out) => out.fileName), + ['main.js', 'types/main.d.ts'] + ); + + t.true(output[1].source.includes('declare const answer = 42;'), output[1].source); + } +); function waitForWatcherEvent(watcher, eventCode) { return new Promise((resolve, reject) => { From c22cf153d84f8650f4dd5eead4a1a2514a518045 Mon Sep 17 00:00:00 2001 From: Samantha-uk Date: Tue, 15 Dec 2020 19:41:23 +0000 Subject: [PATCH 2/3] test(typescript) test for issue #735 --- packages/typescript/test/test.js | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/typescript/test/test.js b/packages/typescript/test/test.js index 79dba949a..85f9a79ed 100644 --- a/packages/typescript/test/test.js +++ b/packages/typescript/test/test.js @@ -1227,6 +1227,43 @@ Produces Error { } */ +test.serial.skip( + 'Should support creating declaration files when not using tsconfig.json', + async (t) => { + const bundle = await rollup({ + input: 'fixtures/basic/main.ts', + plugins: [ + typescript({ + include: 'fixtures/basic/*.ts', + exclude: 'fixtures/basic/dist/types', + tsconfig: false, + declaration: true, + declarationDir: 'fixtures/basic/dist/types' + }) + ], + onwarn + }); + const output = await getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true); + + t.deepEqual( + output.map((out) => out.fileName), + ['main.js', 'types/main.d.ts'] + ); + + t.true(output[1].source.includes('declare const answer = 42;'), output[1].source); + } +); +/* Illustrates issue #735 +Produces Error { + code: 'PLUGIN_ERROR', + hook: 'load', + plugin: 'typescript', + watchFiles: [ + '/plugins/packages/typescript/test/fixtures/basic/main.ts',], + message: 'Could not load /plugins/packages/typescript/test/fixtures/basic/main.ts: Debug Failure.', +} +*/ + test.serial.skip( 'Should support creating declaration files when not using tsconfig.json', async (t) => { From c76494088a81a0dab5fcffe8ec5534a5303a40a5 Mon Sep 17 00:00:00 2001 From: Samantha-uk Date: Tue, 15 Dec 2020 19:51:09 +0000 Subject: [PATCH 3/3] test(typescript) removed duplicate of test --- packages/typescript/test/test.js | 47 -------------------------------- 1 file changed, 47 deletions(-) diff --git a/packages/typescript/test/test.js b/packages/typescript/test/test.js index 85f9a79ed..9d293a3a5 100644 --- a/packages/typescript/test/test.js +++ b/packages/typescript/test/test.js @@ -1216,53 +1216,6 @@ test.serial.skip('works when code is in src directory', async (t) => { ['index.js', 'types/index.d.ts', 'types/index.d.ts.map'] ); }); -/* Illustrates issue -Produces Error { - code: 'PLUGIN_ERROR', - hook: 'load', - plugin: 'typescript', - watchFiles: [ - '/plugins/packages/typescript/test/fixtures/basic/main.ts',], - message: 'Could not load /plugins/packages/typescript/test/fixtures/basic/main.ts: Debug Failure.', -} -*/ - -test.serial.skip( - 'Should support creating declaration files when not using tsconfig.json', - async (t) => { - const bundle = await rollup({ - input: 'fixtures/basic/main.ts', - plugins: [ - typescript({ - include: 'fixtures/basic/*.ts', - exclude: 'fixtures/basic/dist/types', - tsconfig: false, - declaration: true, - declarationDir: 'fixtures/basic/dist/types' - }) - ], - onwarn - }); - const output = await getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true); - - t.deepEqual( - output.map((out) => out.fileName), - ['main.js', 'types/main.d.ts'] - ); - - t.true(output[1].source.includes('declare const answer = 42;'), output[1].source); - } -); -/* Illustrates issue #735 -Produces Error { - code: 'PLUGIN_ERROR', - hook: 'load', - plugin: 'typescript', - watchFiles: [ - '/plugins/packages/typescript/test/fixtures/basic/main.ts',], - message: 'Could not load /plugins/packages/typescript/test/fixtures/basic/main.ts: Debug Failure.', -} -*/ test.serial.skip( 'Should support creating declaration files when not using tsconfig.json',