Skip to content

Commit 6447dca

Browse files
committed
moving the last of the tests
1 parent 3f6b34f commit 6447dca

File tree

3 files changed

+142
-42
lines changed

3 files changed

+142
-42
lines changed

test/config-generator.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -254,32 +254,6 @@ describe('The config-generator function', () => {
254254
});
255255
});
256256

257-
describe('enablePostCssLoader() adds the postcss-loader', () => {
258-
it('without enablePostCssLoader()', () => {
259-
const config = createConfig();
260-
config.outputPath = '/tmp/output/public-path';
261-
config.publicPath = '/public-path';
262-
config.addEntry('main', './main');
263-
//config.enablePostCssLoader();
264-
265-
const actualConfig = configGenerator(config);
266-
267-
expect(JSON.stringify(actualConfig.module.rules)).to.not.contain('postcss-loader');
268-
});
269-
270-
it('enablePostCssLoader()', () => {
271-
const config = createConfig();
272-
config.outputPath = '/tmp/output/public-path';
273-
config.publicPath = '/public-path';
274-
config.addEntry('main', './main');
275-
config.enablePostCssLoader();
276-
277-
const actualConfig = configGenerator(config);
278-
279-
expect(JSON.stringify(actualConfig.module.rules)).to.contain('postcss-loader');
280-
});
281-
});
282-
283257
describe('enableSassLoader() adds the sass-loader', () => {
284258
it('without enableSassLoader()', () => {
285259
const config = createConfig();
@@ -303,22 +277,6 @@ describe('The config-generator function', () => {
303277
const actualConfig = configGenerator(config);
304278

305279
expect(JSON.stringify(actualConfig.module.rules)).to.contain('sass-loader');
306-
expect(JSON.stringify(actualConfig.module.rules)).to.contain('resolve-url-loader');
307-
// sourceMap option is needed for resolve-url-loader
308-
expect(JSON.stringify(actualConfig.module.rules)).to.contain('"sourceMap":true');
309-
});
310-
311-
it('enableSassLoader() without resolve_url_loader', () => {
312-
const config = createConfig();
313-
config.outputPath = '/tmp/output/public-path';
314-
config.publicPath = '/public-path';
315-
config.addEntry('main', './main');
316-
config.enableSassLoader({ resolve_url_loader: false });
317-
318-
const actualConfig = configGenerator(config);
319-
320-
expect(JSON.stringify(actualConfig.module.rules)).to.not.contain('resolve-url-loader');
321-
expect(JSON.stringify(actualConfig.module.rules)).to.contain('"sourceMap":false');
322280
});
323281
});
324282

test/loaders/css.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 cssLoader = require('../../lib/loaders/css');
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/css', () => {
26+
it('getLoaders() basic usage', () => {
27+
const config = createConfig();
28+
config.enableSourceMaps(true);
29+
30+
const actualLoaders = cssLoader.getLoaders(config);
31+
expect(actualLoaders).to.have.lengthOf(1);
32+
expect(actualLoaders[0].options.sourceMap).to.be.true;
33+
expect(actualLoaders[0].options.minimize).to.be.false;
34+
});
35+
36+
it('getLoaders() for production', () => {
37+
const config = createConfig();
38+
config.enableSourceMaps(false);
39+
config.runtimeConfig.environment = 'production';
40+
41+
const actualLoaders = cssLoader.getLoaders(config);
42+
expect(actualLoaders).to.have.lengthOf(1);
43+
expect(actualLoaders[0].options.sourceMap).to.be.false;
44+
expect(actualLoaders[0].options.minimize).to.be.true;
45+
});
46+
47+
it('getLoaders() with PostCSS', () => {
48+
const config = createConfig();
49+
config.enableSourceMaps();
50+
config.enablePostCssLoader();
51+
52+
const actualLoaders = cssLoader.getLoaders(config);
53+
// css-loader & postcss-loader
54+
expect(actualLoaders).to.have.lengthOf(2);
55+
expect(actualLoaders[1].options.sourceMap).to.be.true;
56+
});
57+
});

test/loaders/sass.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 sassLoader = require('../../lib/loaders/sass');
16+
const cssLoader = require('../../lib/loaders/css');
17+
const sinon = require('sinon');
18+
19+
function createConfig() {
20+
const runtimeConfig = new RuntimeConfig();
21+
runtimeConfig.context = __dirname;
22+
runtimeConfig.babelRcFileExists = false;
23+
24+
return new WebpackConfig(runtimeConfig);
25+
}
26+
27+
describe('loaders/sass', () => {
28+
it('getLoaders() basic usage', () => {
29+
const config = createConfig();
30+
config.enableSourceMaps(true);
31+
32+
// make the cssLoader return nothing
33+
sinon.stub(cssLoader, 'getLoaders')
34+
.callsFake(() => []);
35+
36+
const actualLoaders = sassLoader.getLoaders(config);
37+
expect(actualLoaders).to.have.lengthOf(2);
38+
expect(actualLoaders[0].loader).to.equal('resolve-url-loader');
39+
expect(actualLoaders[0].options.sourceMap).to.be.true;
40+
41+
expect(actualLoaders[1].loader).to.equal('sass-loader');
42+
expect(actualLoaders[1].options.sourceMap).to.be.true;
43+
44+
cssLoader.getLoaders.restore();
45+
});
46+
47+
it('getLoaders() with resolve-url-loader but not sourcemaps', () => {
48+
const config = createConfig();
49+
config.enableSourceMaps(false);
50+
51+
// make the cssLoader return nothing
52+
sinon.stub(cssLoader, 'getLoaders')
53+
.callsFake(() => []);
54+
55+
const actualLoaders = sassLoader.getLoaders(config);
56+
expect(actualLoaders).to.have.lengthOf(2);
57+
expect(actualLoaders[0].loader).to.equal('resolve-url-loader');
58+
expect(actualLoaders[0].options.sourceMap).to.be.false;
59+
60+
expect(actualLoaders[1].loader).to.equal('sass-loader');
61+
// sourcemaps always enabled when resolve-url-loader is enabled
62+
expect(actualLoaders[1].options.sourceMap).to.be.true;
63+
64+
cssLoader.getLoaders.restore();
65+
});
66+
67+
it('getLoaders() without resolve-url-loader', () => {
68+
const config = createConfig();
69+
config.enableSassLoader({
70+
resolve_url_loader: false,
71+
});
72+
config.enableSourceMaps(false);
73+
74+
// make the cssLoader return nothing
75+
sinon.stub(cssLoader, 'getLoaders')
76+
.callsFake(() => []);
77+
78+
const actualLoaders = sassLoader.getLoaders(config);
79+
expect(actualLoaders).to.have.lengthOf(1);
80+
expect(actualLoaders[0].loader).to.equal('sass-loader');
81+
expect(actualLoaders[0].options.sourceMap).to.be.false;
82+
83+
cssLoader.getLoaders.restore();
84+
});
85+
});

0 commit comments

Comments
 (0)