Skip to content

Commit 6220d39

Browse files
author
Marc Neuhaus
committed
add more tests
1 parent 456f060 commit 6220d39

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

fixtures/css/h2_styles.styl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
base = #f938ab
2+
h2
3+
color: saturation(base, 5%);

test/WebpackConfig.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,31 @@ describe('WebpackConfig object', () => {
519519
});
520520
});
521521

522+
describe('enableStylusLoader', () => {
523+
it('Calling method sets it', () => {
524+
const config = createConfig();
525+
config.enableStylusLoader();
526+
527+
expect(config.useStylusLoader).to.be.true;
528+
});
529+
530+
it('Calling with callback', () => {
531+
const config = createConfig();
532+
const callback = (stylusOptions) => {};
533+
config.enableStylusLoader(callback);
534+
535+
expect(config.stylusLoaderOptionsCallback).to.equal(callback);
536+
});
537+
538+
it('Calling with non-callback throws an error', () => {
539+
const config = createConfig();
540+
541+
expect(() => {
542+
config.enableStylusLoader('FOO');
543+
}).to.throw('must be a callback function');
544+
});
545+
});
546+
522547
describe('enablePreactPreset', () => {
523548
it('Without preact-compat', () => {
524549
const config = createConfig();

test/config-generator.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,32 @@ describe('The config-generator function', () => {
307307
});
308308
});
309309

310+
describe('enableStylusLoader() adds the stylus-loader', () => {
311+
it('without enableStylusLoader()', () => {
312+
const config = createConfig();
313+
config.outputPath = '/tmp/output/public-path';
314+
config.publicPath = '/public-path';
315+
config.addEntry('main', './main');
316+
// do not enable the stylus loader
317+
318+
const actualConfig = configGenerator(config);
319+
320+
expect(JSON.stringify(actualConfig.module.rules)).to.not.contain('stylus-loader');
321+
});
322+
323+
it('enableStylusLoader()', () => {
324+
const config = createConfig();
325+
config.outputPath = '/tmp/output/public-path';
326+
config.publicPath = '/public-path';
327+
config.addEntry('main', './main');
328+
config.enableStylusLoader();
329+
330+
const actualConfig = configGenerator(config);
331+
332+
expect(JSON.stringify(actualConfig.module.rules)).to.contain('stylus-loader');
333+
});
334+
});
335+
310336
describe('addLoader() adds a custom loader', () => {
311337
it('addLoader()', () => {
312338
const config = createConfig();

test/functional.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,24 @@ module.exports = {
657657
});
658658
});
659659

660+
it('stylus processes when enabled', (done) => {
661+
const config = createWebpackConfig('www/build', 'dev');
662+
config.setPublicPath('/build');
663+
config.addStyleEntry('styles', ['./css/h2_styles.styl']);
664+
config.enableStylusLoader();
665+
666+
testSetup.runWebpack(config, (webpackAssert) => {
667+
// check that stylus did its work!
668+
webpackAssert.assertOutputFileContains(
669+
'styles.css',
670+
// stylus logic inside will resolve to tis
671+
'color: #9e9399;'
672+
);
673+
674+
done();
675+
});
676+
});
677+
660678
it('Babel is executed on .js files', (done) => {
661679
const config = createWebpackConfig('www/build', 'dev');
662680
config.setPublicPath('/build');

0 commit comments

Comments
 (0)