Skip to content

Commit

Permalink
test: rename && update HMR tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Jan 26, 2018
1 parent 23c3567 commit dda8b89
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
11 changes: 5 additions & 6 deletions test/basicTest.js → test/basic.test.js
Expand Up @@ -451,24 +451,23 @@ describe("basic tests", function() {
});
});

describe("hmr option", function() {

describe("HMR", function() {
it("should output HMR code block by default", function(done) {
runSourceTest(/Hot Module Replacement/g, null, done);
runSourceTest(/module\.hot/g, null, done);
});

it("should output HMR code block when options.hmr is true", function(done) {
styleLoaderOptions.hmr = true;
setupWebpackConfig();
runSourceTest(/Hot Module Replacement/g, null, done);
runSourceTest(/module\.hot/g, null, done);
});

it("should not output HMR code block when options.hmr is false", function(done) {
styleLoaderOptions.hmr = false;
setupWebpackConfig();
runSourceTest(null, /Hot Module Replacement/g, done);
runSourceTest(null, /module\.hot/g, done);
});

});

}); // describe
});
File renamed without changes.
6 changes: 3 additions & 3 deletions test/urlTest.js → test/url.test.js
Expand Up @@ -21,17 +21,17 @@ describe("url tests", function () {
});

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

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

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

});
6 changes: 3 additions & 3 deletions test/useableTest.js → test/useable.test.js
Expand Up @@ -21,17 +21,17 @@ describe("useable tests", function () {
});

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

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

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

});
24 changes: 13 additions & 11 deletions test/utils.js
Expand Up @@ -85,25 +85,27 @@ module.exports = {
});
},

/*
* Runs the test against Webpack compiled source code.
* @param {regex} regexToMatch - regex to match the source code
* @param {regex} regexToNotMatch - regex to NOT match the source code
* @param {function} done - Async callback from Mocha.
/**
* Runs the test against Webpack compiled source code
*
* @param {RegExp} match - regex to match the source code
* @param {RegExp} noMatch - regex to NOT match the source code
* @param {Function} done - Async callback (mocha)
*/
runSourceTest: function(regexToMatch, regexToNotMatch, done) {
runSourceTest: function(match, noMatch, done) {
compiler.run(function(err, stats) {
if (stats.compilation.errors.length) {
throw new Error(stats.compilation.errors);
}

const bundleJs = stats.compilation.assets["bundle.js"].source();
if (regexToMatch) {
assert.equal(regexToMatch.test(bundleJs), true);
const source = stats.compilation.assets["bundle.js"].source();

if (match) {
assert.equal(match.test(source), true);
}

if (regexToNotMatch) {
assert.equal(regexToNotMatch.test(bundleJs), false);
if (noMatch) {
assert.equal(noMatch.test(source), false);
}

done();
Expand Down

0 comments on commit dda8b89

Please sign in to comment.