Skip to content

Commit 846d142

Browse files
David Pazdavidmpaz
David Paz
authored andcommitted
Update tests to take into account refactoring
1 parent b43f5c9 commit 846d142

File tree

3 files changed

+64
-18
lines changed

3 files changed

+64
-18
lines changed

test/WebpackConfig.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -278,28 +278,20 @@ describe('WebpackConfig object', () => {
278278
});
279279
});
280280

281-
describe('enableTypeScriptLoader', () => {
282-
it('Call with no config', () => {
283-
const config = createConfig();
284-
config.enableTypeScriptLoader();
285-
286-
expect(config.useTypeScriptLoader).to.be.true;
287-
});
288-
289-
it('Pass valid config', () => {
281+
describe('configureTypeScript', () => {
282+
it('Calling method sets it', () => {
290283
const config = createConfig();
291-
config.enableTypeScriptLoader({ transpileOnly: true });
292-
293-
expect(config.useTypeScriptLoader).to.be.true;
294-
expect(config.typeScriptOptions.transpileOnly).to.be.true;
284+
const testCallback = () => {};
285+
config.configureTypeScript(testCallback);
286+
expect(config.tsConfigurationCallback).to.equal(testCallback);
295287
});
296288

297-
it('Pass invalid config', () => {
289+
it('Calling with non-callback throws an error', () => {
298290
const config = createConfig();
299291

300292
expect(() => {
301-
config.enableTypeScriptLoader({ fake_option: false });
302-
}).to.throw('Invalid option "fake_option" passed to enableTypeScriptLoader()');
293+
config.configureTypeScript('FOO');
294+
}).to.throw('must be a callback function');
303295
});
304296
});
305297

test/functional.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,11 +583,12 @@ module.exports = {
583583
});
584584
});
585585

586-
it('When enabled, TypeScript is compiled!', (done) => {
586+
it('When configured, TypeScript is compiled!', (done) => {
587587
const config = createWebpackConfig('www/build', 'dev');
588588
config.setPublicPath('/build');
589589
config.addEntry('main', ['./js/render.ts', './js/index.ts']);
590-
config.enableTypeScriptLoader();
590+
const testCallback = () => {};
591+
config.configureTypeScript(testCallback);
591592

592593
testSetup.runWebpack(config, (webpackAssert) => {
593594
// check that ts-loader transformed the ts file

test/loaders/typescript.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* This file is part of the Symfony package.
3+
*
4+
* (c) Fabien Potencier <fabien@symfony.com>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
'use strict';
11+
12+
const expect = require('chai').expect;
13+
const WebpackConfig = require('../../lib/WebpackConfig');
14+
const RuntimeConfig = require('../../lib/config/RuntimeConfig');
15+
const tsLoader = require('../../lib/loaders/typescript');
16+
17+
function createConfig() {
18+
const runtimeConfig = new RuntimeConfig();
19+
runtimeConfig.context = __dirname;
20+
runtimeConfig.babelRcFileExists = false;
21+
22+
return new WebpackConfig(runtimeConfig);
23+
}
24+
25+
describe('loaders/typescript', () => {
26+
it('getLoaders() basic usage', () => {
27+
const config = createConfig();
28+
config.configureTypeScript(function(config) {
29+
config.foo = 'bar';
30+
});
31+
32+
const actualLoaders = tsLoader.getLoaders(config);
33+
expect(actualLoaders).to.have.lengthOf(2);
34+
// callback is used
35+
expect(actualLoaders[1].options.foo).to.equal('bar');
36+
});
37+
38+
it('getLoaders() check defaults configuration values', () => {
39+
const config = createConfig();
40+
config.configureTypeScript(function(config) {
41+
config.foo = 'bar';
42+
});
43+
44+
const actualLoaders = tsLoader.getLoaders(config);
45+
// callback is used
46+
expect(actualLoaders[1].options.foo).to.equal('bar');
47+
// defaults
48+
expect(actualLoaders[1].options.silent).to.be.true;
49+
expect(actualLoaders[1].options.transpileOnly).to.be.false;
50+
expect(actualLoaders[1].options.logLevel).to.equal('info');
51+
});
52+
53+
});

0 commit comments

Comments
 (0)