From 58b7ef7cafdba0a211820b80905d62a900bd94d9 Mon Sep 17 00:00:00 2001 From: David Paz Date: Wed, 21 Jun 2017 19:04:35 +0200 Subject: [PATCH] Add unit and functional test for TypeScript loader --- fixtures/js/index.ts | 3 +++ fixtures/js/render.ts | 5 +++++ fixtures/js/tsconfig.json | 3 +++ test/WebpackConfig.js | 25 +++++++++++++++++++++++++ test/functional.js | 19 ++++++++++++++++++- 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 fixtures/js/index.ts create mode 100644 fixtures/js/render.ts create mode 100644 fixtures/js/tsconfig.json diff --git a/fixtures/js/index.ts b/fixtures/js/index.ts new file mode 100644 index 00000000..7ff32dcf --- /dev/null +++ b/fixtures/js/index.ts @@ -0,0 +1,3 @@ +import render = require('./render'); + +render(); \ No newline at end of file diff --git a/fixtures/js/render.ts b/fixtures/js/render.ts new file mode 100644 index 00000000..47e4788a --- /dev/null +++ b/fixtures/js/render.ts @@ -0,0 +1,5 @@ +function render() { + document.getElementById('wrapper').innerHTML = "

Hello World!

"; +} + +export = render; \ No newline at end of file diff --git a/fixtures/js/tsconfig.json b/fixtures/js/tsconfig.json new file mode 100644 index 00000000..4ee3592b --- /dev/null +++ b/fixtures/js/tsconfig.json @@ -0,0 +1,3 @@ +{ + "compilerOptions": {} +} \ No newline at end of file diff --git a/test/WebpackConfig.js b/test/WebpackConfig.js index 642cbc1a..816707f4 100644 --- a/test/WebpackConfig.js +++ b/test/WebpackConfig.js @@ -278,6 +278,31 @@ describe('WebpackConfig object', () => { }); }); + describe('enableTypeScriptLoader', () => { + it('Call with no config', () => { + const config = createConfig(); + config.enableTypeScriptLoader(); + + expect(config.useTypeScriptLoader).to.be.true; + }); + + it('Pass valid config', () => { + const config = createConfig(); + config.enableTypeScriptLoader({ transpileOnly: true }); + + expect(config.useTypeScriptLoader).to.be.true; + expect(config.typeScriptOptions.transpileOnly).to.be.true; + }); + + it('Pass invalid config', () => { + const config = createConfig(); + + expect(() => { + config.enableTypeScriptLoader({ fake_option: false }); + }).to.throw('Invalid option "fake_option" passed to enableTypeScriptLoader()'); + }); + }); + describe('addPlugin', () => { it('extends the current registered plugins', () => { const config = createConfig(); diff --git a/test/functional.js b/test/functional.js index c3522f56..9e41f03b 100644 --- a/test/functional.js +++ b/test/functional.js @@ -45,7 +45,7 @@ describe('Functional tests using webpack', function() { testSetup.emptyTmpDir(); }); - describe('Basic scenarios', () => { + describe('Basic scenarios.', () => { it('Builds a few simple entries file + manifest.json', (done) => { const config = createWebpackConfig('web/build', 'dev'); @@ -583,6 +583,23 @@ module.exports = { }); }); + it('When enabled, TypeScript is compiled!', (done) => { + const config = createWebpackConfig('www/build', 'dev'); + config.setPublicPath('/build'); + config.addEntry('main', ['./js/render.ts', './js/index.ts']); + config.enableTypeScriptLoader(); + + testSetup.runWebpack(config, (webpackAssert) => { + // check that ts-loader transformed the ts file + webpackAssert.assertOutputFileContains( + 'main.js', + 'document.getElementById(\'wrapper\').innerHTML = "

Hello World!

";' + ); + + done(); + }); + }); + it('The output directory is cleaned between builds', (done) => { const config = createWebpackConfig('www/build', 'dev'); config.setPublicPath('/build');