Skip to content

Commit dda8b89

Browse files
committedJan 26, 2018
test: rename && update HMR tests
1 parent 23c3567 commit dda8b89

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed
 

‎test/basicTest.js ‎test/basic.test.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -451,24 +451,23 @@ describe("basic tests", function() {
451451
});
452452
});
453453

454-
describe("hmr option", function() {
455-
454+
describe("HMR", function() {
456455
it("should output HMR code block by default", function(done) {
457-
runSourceTest(/Hot Module Replacement/g, null, done);
456+
runSourceTest(/module\.hot/g, null, done);
458457
});
459458

460459
it("should output HMR code block when options.hmr is true", function(done) {
461460
styleLoaderOptions.hmr = true;
462461
setupWebpackConfig();
463-
runSourceTest(/Hot Module Replacement/g, null, done);
462+
runSourceTest(/module\.hot/g, null, done);
464463
});
465464

466465
it("should not output HMR code block when options.hmr is false", function(done) {
467466
styleLoaderOptions.hmr = false;
468467
setupWebpackConfig();
469-
runSourceTest(null, /Hot Module Replacement/g, done);
468+
runSourceTest(null, /module\.hot/g, done);
470469
});
471470

472471
});
473472

474-
}); // describe
473+
});
File renamed without changes.

‎test/urlTest.js ‎test/url.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ describe("url tests", function () {
2121
});
2222

2323
it("should output HMR code by default", function () {
24-
assert.equal(/Hot Module Replacement/g.test(url.pitch()), true);
24+
assert.equal(/(module\.hot)/g.test(url.pitch()), true);
2525
});
2626

2727
it("should NOT output HMR code when options.hmr is false", function () {
2828
getOptions.returns({hmr: false});
29-
assert.equal(/Hot Module Replacement/g.test(url.pitch()), false);
29+
assert.equal(/(module\.hot)/g.test(url.pitch()), false);
3030
});
3131

3232
it("should output HMR code when options.hmr is true", function () {
3333
getOptions.returns({hmr: true});
34-
assert.equal(/Hot Module Replacement/g.test(url.pitch()), true);
34+
assert.equal(/(module\.hot)/g.test(url.pitch()), true);
3535
});
3636

3737
});

‎test/useableTest.js ‎test/useable.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ describe("useable tests", function () {
2121
});
2222

2323
it("should output HMR code by default", function () {
24-
assert.equal(/Hot Module Replacement/g.test(useable.pitch()), true);
24+
assert.equal(/(module\.hot)/g.test(useable.pitch()), true);
2525
});
2626

2727
it("should NOT output HMR code when options.hmr is false", function () {
2828
getOptions.returns({hmr: false});
29-
assert.equal(/Hot Module Replacement/g.test(useable.pitch()), false);
29+
assert.equal(/(module\.hot)/g.test(useable.pitch()), false);
3030
});
3131

3232
it("should output HMR code when options.hmr is true", function () {
3333
getOptions.returns({hmr: true});
34-
assert.equal(/Hot Module Replacement/g.test(useable.pitch()), true);
34+
assert.equal(/(module\.hot)/g.test(useable.pitch()), true);
3535
});
3636

3737
});

‎test/utils.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,27 @@ module.exports = {
8585
});
8686
},
8787

88-
/*
89-
* Runs the test against Webpack compiled source code.
90-
* @param {regex} regexToMatch - regex to match the source code
91-
* @param {regex} regexToNotMatch - regex to NOT match the source code
92-
* @param {function} done - Async callback from Mocha.
88+
/**
89+
* Runs the test against Webpack compiled source code
90+
*
91+
* @param {RegExp} match - regex to match the source code
92+
* @param {RegExp} noMatch - regex to NOT match the source code
93+
* @param {Function} done - Async callback (mocha)
9394
*/
94-
runSourceTest: function(regexToMatch, regexToNotMatch, done) {
95+
runSourceTest: function(match, noMatch, done) {
9596
compiler.run(function(err, stats) {
9697
if (stats.compilation.errors.length) {
9798
throw new Error(stats.compilation.errors);
9899
}
99100

100-
const bundleJs = stats.compilation.assets["bundle.js"].source();
101-
if (regexToMatch) {
102-
assert.equal(regexToMatch.test(bundleJs), true);
101+
const source = stats.compilation.assets["bundle.js"].source();
102+
103+
if (match) {
104+
assert.equal(match.test(source), true);
103105
}
104106

105-
if (regexToNotMatch) {
106-
assert.equal(regexToNotMatch.test(bundleJs), false);
107+
if (noMatch) {
108+
assert.equal(noMatch.test(source), false);
107109
}
108110

109111
done();

0 commit comments

Comments
 (0)
Please sign in to comment.