Skip to content

Commit

Permalink
Add unit and functional test for TypeScript loader
Browse files Browse the repository at this point in the history
  • Loading branch information
David Paz authored and davidmpaz committed Jun 24, 2017
1 parent fc26e1b commit 58b7ef7
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
3 changes: 3 additions & 0 deletions fixtures/js/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import render = require('./render');

render();
5 changes: 5 additions & 0 deletions fixtures/js/render.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function render() {
document.getElementById('wrapper').innerHTML = "<h1> Hello World!</h1>";
}

export = render;
3 changes: 3 additions & 0 deletions fixtures/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
25 changes: 25 additions & 0 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 18 additions & 1 deletion test/functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 = "<h1> Hello World!</h1>";'
);

done();
});
});

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

0 comments on commit 58b7ef7

Please sign in to comment.