Skip to content

Commit 56ebac2

Browse files
committed
moving tests from config-generator to babel.js
1 parent a3ae19f commit 56ebac2

File tree

2 files changed

+68
-51
lines changed

2 files changed

+68
-51
lines changed

test/config-generator.js

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -375,57 +375,6 @@ describe('The config-generator function', () => {
375375
// check for the default env preset only
376376
expect(JSON.stringify(jsRule.use[0].options.presets)).contains('env');
377377
});
378-
379-
it('If .babelrc is present, we pass *no* config', () => {
380-
const runtimeConfig = new RuntimeConfig();
381-
runtimeConfig.babelRcFileExists = true;
382-
const config = createConfig(runtimeConfig);
383-
config.outputPath = '/tmp/output/public-path';
384-
config.publicPath = '/public-path';
385-
config.addEntry('main', './main');
386-
387-
const actualConfig = configGenerator(config);
388-
389-
const jsRule = findRule(/\.jsx?$/, actualConfig.module.rules);
390-
391-
// the options should only contain the cacheDirectory option
392-
expect(JSON.stringify(jsRule.use[0].options)).to.equal(JSON.stringify({ 'cacheDirectory': true }));
393-
});
394-
395-
it('configureBabel() passes babel options', () => {
396-
const config = createConfig();
397-
config.outputPath = '/tmp/output/public-path';
398-
config.publicPath = '/public-path';
399-
config.addEntry('main', './main');
400-
config.configureBabel(function(babelConfig) {
401-
babelConfig.presets.push('foo');
402-
});
403-
404-
const actualConfig = configGenerator(config);
405-
406-
const jsRule = findRule(/\.jsx?$/, actualConfig.module.rules);
407-
408-
expect(jsRule.use[0].options.presets).to.include('foo');
409-
});
410-
411-
it('enableReactPreset() passes react preset to babel', () => {
412-
const config = createConfig();
413-
config.outputPath = '/tmp/output/public-path';
414-
config.publicPath = '/public-path';
415-
config.addEntry('main', './main');
416-
config.enableReactPreset();
417-
config.configureBabel(function(babelConfig) {
418-
babelConfig.presets.push('foo');
419-
});
420-
421-
const actualConfig = configGenerator(config);
422-
423-
const jsRule = findRule(/\.jsx?$/, actualConfig.module.rules);
424-
425-
expect(jsRule.use[0].options.presets).to.include('react');
426-
// foo is also still there, not overridden
427-
expect(jsRule.use[0].options.presets).to.include('foo');
428-
});
429378
});
430379

431380
describe('cleanupOutputBeforeBuild() adds CleanWebpackPlugin', () => {

test/loaders/babel.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of the Symfony package.
3+
*
4+
* (c) Fabien Potencier <[email protected]>
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 babelLoader = require('../../lib/loaders/babel');
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/babel', () => {
26+
it('getLoaders() basic usage', () => {
27+
const config = createConfig();
28+
config.runtimeConfig.babelRcFileExists = false;
29+
config.configureBabel(function(config) {
30+
config.foo = 'bar';
31+
});
32+
33+
const actualLoaders = babelLoader.getLoaders(config);
34+
expect(actualLoaders).to.have.lengthOf(1);
35+
// the env preset is enabled by default
36+
expect(actualLoaders[0].options.presets).to.have.lengthOf(1);
37+
// callback is used
38+
expect(actualLoaders[0].options.foo).to.equal('bar');
39+
});
40+
41+
it('getLoaders() when .babelrc IS present', () => {
42+
const config = createConfig();
43+
config.runtimeConfig.babelRcFileExists = true;
44+
45+
const actualLoaders = babelLoader.getLoaders(config);
46+
// we only add cacheDirectory
47+
expect(actualLoaders[0].options).to.deep.equal({
48+
cacheDirectory: true
49+
});
50+
});
51+
52+
it('getLoaders() with react', () => {
53+
const config = createConfig();
54+
config.enableReactPreset();
55+
56+
config.configureBabel(function(babelConfig) {
57+
babelConfig.presets.push('foo');
58+
});
59+
60+
const actualLoaders = babelLoader.getLoaders(config);
61+
62+
// env, react & foo
63+
expect(actualLoaders[0].options.presets).to.have.lengthOf(3);
64+
expect(actualLoaders[0].options.presets).to.include('react');
65+
// foo is also still there, not overridden
66+
expect(actualLoaders[0].options.presets).to.include('foo');
67+
});
68+
});

0 commit comments

Comments
 (0)