mirror of https://github.com/webpack/webpack.git
Migrate unit tests to Jest
This commit is contained in:
parent
02f8c96925
commit
2f4910b4c3
10
package.json
10
package.json
|
@ -43,6 +43,7 @@
|
||||||
"istanbul": "^0.4.5",
|
"istanbul": "^0.4.5",
|
||||||
"jade": "^1.11.0",
|
"jade": "^1.11.0",
|
||||||
"jade-loader": "~0.8.0",
|
"jade-loader": "~0.8.0",
|
||||||
|
"jest": "^22.1.4",
|
||||||
"js-beautify": "^1.5.10",
|
"js-beautify": "^1.5.10",
|
||||||
"json-loader": "^0.5.7",
|
"json-loader": "^0.5.7",
|
||||||
"less": "^2.5.1",
|
"less": "^2.5.1",
|
||||||
|
@ -86,9 +87,9 @@
|
||||||
"schemas/"
|
"schemas/"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha test/*.test.js test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation",
|
"test": "jest",
|
||||||
"test:integration": "mocha test/*.test.js --max-old-space-size=4096 --harmony --trace-deprecation",
|
"test:integration": "jest --testMatch '<rootDir>/test/*.test.js'",
|
||||||
"test:unit": "mocha test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation",
|
"test:unit": "jest --testMatch '<rootDir>/test/*.unittest.js'",
|
||||||
"travis:integration": "npm run cover:init && npm run cover:integration && npm run cover:report-min",
|
"travis:integration": "npm run cover:init && npm run cover:integration && npm run cover:report-min",
|
||||||
"travis:unit": "npm run cover:init && npm run cover:unit && npm run cover:report-min",
|
"travis:unit": "npm run cover:init && npm run cover:unit && npm run cover:report-min",
|
||||||
"travis:lint": "npm run lint-files",
|
"travis:lint": "npm run lint-files",
|
||||||
|
@ -114,5 +115,8 @@
|
||||||
"cover:report": "istanbul report",
|
"cover:report": "istanbul report",
|
||||||
"cover:report-min": "istanbul report --report lcovonly",
|
"cover:report-min": "istanbul report --report lcovonly",
|
||||||
"publish-patch": "npm run lint && npm run beautify-lint && mocha && npm version patch && git push && git push --tags && npm publish"
|
"publish-patch": "npm run lint && npm run beautify-lint && mocha && npm version patch && git push && git push --tags && npm publish"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"testEnvironment": "node"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("should");
|
|
||||||
const CachePlugin = require("../lib/CachePlugin");
|
const CachePlugin = require("../lib/CachePlugin");
|
||||||
|
|
||||||
describe("CachePlugin", () => {
|
describe("CachePlugin", () => {
|
||||||
|
@ -16,26 +15,28 @@ describe("CachePlugin", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("applyMtime", () => {
|
describe("applyMtime", () => {
|
||||||
beforeEach(() => env.plugin = new CachePlugin());
|
beforeEach(() => {
|
||||||
|
env.plugin = new CachePlugin();
|
||||||
|
});
|
||||||
|
|
||||||
it("sets file system accuracy to 1 for granular modification timestamp", () => {
|
it("sets file system accuracy to 1 for granular modification timestamp", () => {
|
||||||
env.plugin.applyMtime(1483819067001);
|
env.plugin.applyMtime(1483819067001);
|
||||||
env.plugin.FS_ACCURENCY.should.be.exactly(1);
|
expect(env.plugin.FS_ACCURENCY).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets file system accuracy to 10 for moderately granular modification timestamp", () => {
|
it("sets file system accuracy to 10 for moderately granular modification timestamp", () => {
|
||||||
env.plugin.applyMtime(1483819067004);
|
env.plugin.applyMtime(1483819067004);
|
||||||
env.plugin.FS_ACCURENCY.should.be.exactly(10);
|
expect(env.plugin.FS_ACCURENCY).toBe(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets file system accuracy to 100 for moderately coarse modification timestamp", () => {
|
it("sets file system accuracy to 100 for moderately coarse modification timestamp", () => {
|
||||||
env.plugin.applyMtime(1483819067040);
|
env.plugin.applyMtime(1483819067040);
|
||||||
env.plugin.FS_ACCURENCY.should.be.exactly(100);
|
expect(env.plugin.FS_ACCURENCY).toBe(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets file system accuracy to 1000 for coarse modification timestamp", () => {
|
it("sets file system accuracy to 1000 for coarse modification timestamp", () => {
|
||||||
env.plugin.applyMtime(1483819067400);
|
env.plugin.applyMtime(1483819067400);
|
||||||
env.plugin.FS_ACCURENCY.should.be.exactly(1000);
|
expect(env.plugin.FS_ACCURENCY).toBe(1000);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("should");
|
|
||||||
const CaseSensitiveModulesWarning = require("../lib/CaseSensitiveModulesWarning");
|
const CaseSensitiveModulesWarning = require("../lib/CaseSensitiveModulesWarning");
|
||||||
|
|
||||||
const createModule = function(identifier, numberOfReasons) {
|
const createModule = (identifier, numberOfReasons) => {
|
||||||
const reasons = new Array(numberOfReasons || 0).fill(null).map((value, index) => {
|
const reasons = new Array(numberOfReasons || 0).fill(null).map((value, index) => {
|
||||||
return {
|
return {
|
||||||
module: createModule(`${identifier}-reason-${index}`)
|
module: createModule(`${identifier}-reason-${index}`)
|
||||||
|
@ -29,10 +28,12 @@ describe("CaseSensitiveModulesWarning", () => {
|
||||||
myCaseSensitiveModulesWarning = new CaseSensitiveModulesWarning(modules);
|
myCaseSensitiveModulesWarning = new CaseSensitiveModulesWarning(modules);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has the a name", () => myCaseSensitiveModulesWarning.name.should.be.exactly("CaseSensitiveModulesWarning"));
|
it("has the a name", () => {
|
||||||
|
expect(myCaseSensitiveModulesWarning.name).toBe("CaseSensitiveModulesWarning");
|
||||||
|
});
|
||||||
|
|
||||||
it("has the a message", () => {
|
it("has the a message", () => {
|
||||||
myCaseSensitiveModulesWarning.message.should.be.exactly(`
|
expect(myCaseSensitiveModulesWarning.message).toBe(`
|
||||||
There are multiple modules with names that only differ in casing.
|
There are multiple modules with names that only differ in casing.
|
||||||
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
|
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
|
||||||
Use equal casing. Compare these module identifiers:
|
Use equal casing. Compare these module identifiers:
|
||||||
|
@ -46,9 +47,11 @@ Use equal casing. Compare these module identifiers:
|
||||||
`.trim());
|
`.trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has the an origin", () =>
|
it("has the an origin", () => {
|
||||||
myCaseSensitiveModulesWarning.origin.should.be.exactly(modules[0]));
|
expect(myCaseSensitiveModulesWarning.origin).toBe(modules[0]);
|
||||||
|
});
|
||||||
it("has the a module", () =>
|
|
||||||
myCaseSensitiveModulesWarning.module.should.be.exactly(modules[0]));
|
it("has the a module", () => {
|
||||||
|
expect(myCaseSensitiveModulesWarning.module).toBe(modules[0]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,99 +1,114 @@
|
||||||
/* globals describe, it, beforeEach */
|
/* globals describe, it, beforeEach */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const should = require("should");
|
|
||||||
const sinon = require("sinon");
|
const sinon = require("sinon");
|
||||||
const Chunk = require("../lib/Chunk");
|
const Chunk = require("../lib/Chunk");
|
||||||
|
|
||||||
describe("Chunk", () => {
|
describe("Chunk", () => {
|
||||||
let ChunkInstance;
|
let ChunkInstance;
|
||||||
|
|
||||||
beforeEach(() => ChunkInstance = new Chunk("chunk-test", "module-test", "loc-test"));
|
beforeEach(() => {
|
||||||
|
ChunkInstance = new Chunk("chunk-test", "module-test", "loc-test");
|
||||||
|
});
|
||||||
|
|
||||||
it("should have debugId more than 999", () => should(ChunkInstance.debugId).be.above(999));
|
it("should have debugId more than 999", () => {
|
||||||
|
expect(ChunkInstance.debugId).toBeGreaterThan(999);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns a string with modules information", () => should(ChunkInstance.toString()).be.exactly("Chunk[]"));
|
it("returns a string with modules information", () => {
|
||||||
|
expect(ChunkInstance.toString()).toBe("Chunk[]");
|
||||||
|
});
|
||||||
|
|
||||||
it("should not be the initial instance", () => should(ChunkInstance.canBeInitial()).be.false());
|
it("should not be the initial instance", () => {
|
||||||
|
expect(ChunkInstance.canBeInitial()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
describe("entry", () => {
|
describe("entry", () => {
|
||||||
it("returns an error if get entry", () =>
|
it("returns an error if get entry", () => {
|
||||||
should(() => {
|
expect(() => {
|
||||||
ChunkInstance.entry;
|
ChunkInstance.entry;
|
||||||
}).throw("Chunk.entry was removed. Use hasRuntime()"));
|
}).toThrow("Chunk.entry was removed. Use hasRuntime()");
|
||||||
|
});
|
||||||
|
|
||||||
it("returns an error if set an entry", () =>
|
it("returns an error if set an entry", () => {
|
||||||
should(() => {
|
expect(() => {
|
||||||
ChunkInstance.entry = 10;
|
ChunkInstance.entry = 10;
|
||||||
}).throw("Chunk.entry was removed. Use hasRuntime()"));
|
}).toThrow("Chunk.entry was removed. Use hasRuntime()");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("initial", () => {
|
describe("initial", () => {
|
||||||
it("returns an error if get initial", () =>
|
it("returns an error if get initial", () => {
|
||||||
should(() => {
|
expect(() => {
|
||||||
ChunkInstance.initial;
|
ChunkInstance.initial;
|
||||||
}).throw("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()"));
|
}).toThrow("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()");
|
||||||
|
});
|
||||||
|
|
||||||
it("returns an error if set an initial", () =>
|
it("returns an error if set an initial", () => {
|
||||||
should(() => {
|
expect(() => {
|
||||||
ChunkInstance.initial = 10;
|
ChunkInstance.initial = 10;
|
||||||
}).throw("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()"));
|
}).toThrow("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("hasRuntime", () => {
|
describe("hasRuntime", () => {
|
||||||
it("returns false", () => should(ChunkInstance.hasRuntime()).be.false());
|
it("returns false", () => {
|
||||||
|
expect(ChunkInstance.hasRuntime()).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("isEmpty", () => {
|
describe("isEmpty", () => {
|
||||||
it("should NOT have any module by default", () => should(ChunkInstance.isEmpty()).be.true());
|
it("should NOT have any module by default", () => {
|
||||||
|
expect(ChunkInstance.isEmpty()).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("size", () => {
|
describe("size", () => {
|
||||||
it("should NOT have any module by default", () =>
|
it("should NOT have any module by default", () => {
|
||||||
should(ChunkInstance.size({
|
expect(ChunkInstance.size({
|
||||||
chunkOverhead: 10,
|
chunkOverhead: 10,
|
||||||
entryChunkMultiplicator: 2
|
entryChunkMultiplicator: 2
|
||||||
})).be.exactly(10));
|
})).toBe(10);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("removeModule", function() {
|
describe("removeModule", () => {
|
||||||
let module;
|
let module;
|
||||||
let removeChunkSpy;
|
let removeChunkSpy;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
removeChunkSpy = sinon.spy();
|
removeChunkSpy = sinon.spy();
|
||||||
|
|
||||||
module = {
|
module = {
|
||||||
removeChunk: removeChunkSpy
|
removeChunk: removeChunkSpy
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and the chunk does not contain this module", function() {
|
describe("and the chunk does not contain this module", () => {
|
||||||
it("returns false", function() {
|
it("returns false", () => {
|
||||||
ChunkInstance.removeModule(module).should.eql(false);
|
expect(ChunkInstance.removeModule(module)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and the chunk does contain this module", function() {
|
describe("and the chunk does contain this module", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
ChunkInstance._modules = new Set([module]);
|
ChunkInstance._modules = new Set([module]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls module.removeChunk with itself and returns true", function() {
|
it("calls module.removeChunk with itself and returns true", () => {
|
||||||
ChunkInstance.removeModule(module).should.eql(true);
|
expect(ChunkInstance.removeModule(module)).toBe(true);
|
||||||
|
|
||||||
removeChunkSpy.callCount.should.eql(1);
|
expect(removeChunkSpy.callCount).toBe(1);
|
||||||
removeChunkSpy.args[0][0].should.eql(ChunkInstance);
|
expect(removeChunkSpy.args[0][0]).toBe(ChunkInstance);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getNumberOfGroups", function() {
|
describe("getNumberOfGroups", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
ChunkInstance._groups = new Set();
|
ChunkInstance._groups = new Set();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return the number of chunk groups contained by the chunk", function() {
|
it("should return the number of chunk groups contained by the chunk", () => {
|
||||||
ChunkInstance.getNumberOfGroups().should.eql(0);
|
expect(ChunkInstance.getNumberOfGroups()).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
/* globals describe, it, beforeEach */
|
/* globals describe, it, beforeEach */
|
||||||
"use strict";
|
"use strict";
|
||||||
require("should");
|
|
||||||
const MemoryFs = require("memory-fs");
|
const MemoryFs = require("memory-fs");
|
||||||
const ContextModuleFactory = require("../lib/ContextModuleFactory");
|
const ContextModuleFactory = require("../lib/ContextModuleFactory");
|
||||||
|
|
||||||
describe("ContextModuleFactory", function() {
|
describe("ContextModuleFactory", () => {
|
||||||
describe("resolveDependencies", function() {
|
describe("resolveDependencies", () => {
|
||||||
let factory, memfs;
|
let factory, memfs;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
factory = new ContextModuleFactory([]);
|
factory = new ContextModuleFactory([]);
|
||||||
memfs = new MemoryFs();
|
memfs = new MemoryFs();
|
||||||
});
|
});
|
||||||
it("should not report an error when ENOENT errors happen", function(done) {
|
it("should not report an error when ENOENT errors happen", (done) => {
|
||||||
memfs.readdir = (dir, callback) => {
|
memfs.readdir = (dir, callback) => {
|
||||||
setTimeout(() => callback(null, ["/file"]));
|
setTimeout(() => callback(null, ["/file"]));
|
||||||
};
|
};
|
||||||
|
@ -25,13 +25,13 @@ describe("ContextModuleFactory", function() {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
regExp: /.*/
|
regExp: /.*/
|
||||||
}, (err, res) => {
|
}, (err, res) => {
|
||||||
(!!err).should.be.false();
|
expect(err).toBeFalsy();
|
||||||
res.should.be.an.Array();
|
expect(Array.isArray(res)).toBe(true);
|
||||||
res.length.should.be.exactly(0);
|
expect(res.length).toBe(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should report an error when non-ENOENT errors happen", function(done) {
|
it("should report an error when non-ENOENT errors happen", (done) => {
|
||||||
memfs.readdir = (dir, callback) => {
|
memfs.readdir = (dir, callback) => {
|
||||||
setTimeout(() => callback(null, ["/file"]));
|
setTimeout(() => callback(null, ["/file"]));
|
||||||
};
|
};
|
||||||
|
@ -45,8 +45,8 @@ describe("ContextModuleFactory", function() {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
regExp: /.*/
|
regExp: /.*/
|
||||||
}, (err, res) => {
|
}, (err, res) => {
|
||||||
err.should.be.an.Error();
|
expect(err).toBeInstanceOf(Error);
|
||||||
(!!res).should.be.false();
|
expect(res).toBeFalsy();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/* globals describe, it, beforeEach */
|
/* globals describe, it, beforeEach */
|
||||||
"use strict";
|
"use strict";
|
||||||
require("should");
|
|
||||||
const DelegatedModule = require("../lib/DelegatedModule");
|
const DelegatedModule = require("../lib/DelegatedModule");
|
||||||
|
|
||||||
describe("DelegatedModule", function() {
|
describe("DelegatedModule", () => {
|
||||||
describe("#updateHash", function() {
|
describe("#updateHash", () => {
|
||||||
const sourceRequest = "dll-reference dll_e54c0fb67f8152792ad2";
|
const sourceRequest = "dll-reference dll_e54c0fb67f8152792ad2";
|
||||||
const data = {
|
const data = {
|
||||||
id: "/xg9"
|
id: "/xg9"
|
||||||
|
@ -13,7 +13,7 @@ describe("DelegatedModule", function() {
|
||||||
const userRequest = "./library.js";
|
const userRequest = "./library.js";
|
||||||
let hashedText;
|
let hashedText;
|
||||||
let hash;
|
let hash;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
hashedText = "";
|
hashedText = "";
|
||||||
hash = {
|
hash = {
|
||||||
update: (text) => {
|
update: (text) => {
|
||||||
|
@ -23,11 +23,11 @@ describe("DelegatedModule", function() {
|
||||||
const delegatedModule = new DelegatedModule(sourceRequest, data, type, userRequest);
|
const delegatedModule = new DelegatedModule(sourceRequest, data, type, userRequest);
|
||||||
delegatedModule.updateHash(hash);
|
delegatedModule.updateHash(hash);
|
||||||
});
|
});
|
||||||
it("updates hash with delegated module ID", function() {
|
it("updates hash with delegated module ID", () => {
|
||||||
hashedText.should.containEql("/xg9");
|
expect(hashedText).toMatch("/xg9");
|
||||||
});
|
});
|
||||||
it("updates hash with delegation type", function() {
|
it("updates hash with delegation type", () => {
|
||||||
hashedText.should.containEql("require");
|
expect(hashedText).toMatch("require");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,68 +1,62 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const should = require("should");
|
|
||||||
const sinon = require("sinon");
|
const sinon = require("sinon");
|
||||||
const DependenciesBlockVariable = require("../lib/DependenciesBlockVariable");
|
const DependenciesBlockVariable = require("../lib/DependenciesBlockVariable");
|
||||||
|
|
||||||
describe("DependenciesBlockVariable", () => {
|
describe("DependenciesBlockVariable", () => {
|
||||||
let DependenciesBlockVariableInstance,
|
const sandbox = sinon.sandbox.create();
|
||||||
dependencyMock,
|
const dependencyMock = {
|
||||||
sandbox;
|
|
||||||
|
|
||||||
before(() => {
|
|
||||||
sandbox = sinon.sandbox.create();
|
|
||||||
dependencyMock = {
|
|
||||||
constructor: {
|
constructor: {
|
||||||
name: "DependencyMock"
|
name: "DependencyMock"
|
||||||
},
|
},
|
||||||
disconnect: sandbox.spy(),
|
disconnect: sandbox.spy(),
|
||||||
updateHash: sandbox.spy()
|
updateHash: sandbox.spy()
|
||||||
};
|
};
|
||||||
DependenciesBlockVariableInstance = new DependenciesBlockVariable(
|
const DependenciesBlockVariableInstance = new DependenciesBlockVariable("dependencies-name", "expression", [dependencyMock]);
|
||||||
"dependencies-name",
|
|
||||||
"expression", [dependencyMock]);
|
afterEach(() => {
|
||||||
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => sandbox.restore());
|
describe("hasDependencies", () => {
|
||||||
|
it("returns `true` if has dependencies", () => {
|
||||||
|
expect(DependenciesBlockVariableInstance.hasDependencies()).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("hasDependencies", () =>
|
describe("disconnect", () => {
|
||||||
it("returns `true` if has dependencies", () =>
|
|
||||||
should(DependenciesBlockVariableInstance.hasDependencies()).be.true()));
|
|
||||||
|
|
||||||
describe("disconnect", () =>
|
|
||||||
it("trigger dependencies disconnection", () => {
|
it("trigger dependencies disconnection", () => {
|
||||||
DependenciesBlockVariableInstance.disconnect();
|
DependenciesBlockVariableInstance.disconnect();
|
||||||
should(dependencyMock.disconnect.calledOnce).be.true();
|
expect(dependencyMock.disconnect.calledOnce).toBe(true);
|
||||||
}));
|
});
|
||||||
|
|
||||||
describe("updateHash", () => {
|
|
||||||
let hash;
|
|
||||||
before(() => {
|
|
||||||
hash = {
|
|
||||||
update: sandbox.spy()
|
|
||||||
};
|
|
||||||
DependenciesBlockVariableInstance.updateHash(hash);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should update hash dependencies with name", () =>
|
describe("updateHash", () => {
|
||||||
should(hash.update.calledWith("dependencies-name")).be.true());
|
const hash = {
|
||||||
|
update: sandbox.spy()
|
||||||
|
};
|
||||||
|
|
||||||
it("should update hash dependencies with expression", () =>
|
DependenciesBlockVariableInstance.updateHash(hash);
|
||||||
should(hash.update.calledWith("expression")).be.true());
|
|
||||||
|
|
||||||
it("should update hash inside dependencies", () =>
|
it("should update hash dependencies with name", () => {
|
||||||
should(dependencyMock.updateHash.calledOnce).be.true());
|
expect(hash.update.calledWith("dependencies-name")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update hash dependencies with expression", () => {
|
||||||
|
expect(hash.update.calledWith("expression")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update hash inside dependencies", () => {
|
||||||
|
expect(dependencyMock.updateHash.calledOnce).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("expressionSource", () => {
|
describe("expressionSource", () => {
|
||||||
let dependencyTemplates,
|
const applyMock = sandbox.spy();
|
||||||
applyMock;
|
|
||||||
|
|
||||||
before(() => applyMock = sandbox.spy());
|
|
||||||
|
|
||||||
it("aplies information inside dependency templates", () => {
|
it("aplies information inside dependency templates", () => {
|
||||||
dependencyTemplates = {
|
const dependencyTemplates = {
|
||||||
get: function() {
|
get() {
|
||||||
return {
|
return {
|
||||||
apply: applyMock
|
apply: applyMock
|
||||||
};
|
};
|
||||||
|
@ -71,20 +65,20 @@ describe("DependenciesBlockVariable", () => {
|
||||||
DependenciesBlockVariableInstance.expressionSource(
|
DependenciesBlockVariableInstance.expressionSource(
|
||||||
dependencyTemplates, {}, {}
|
dependencyTemplates, {}, {}
|
||||||
);
|
);
|
||||||
should(applyMock.calledOnce).be.true();
|
expect(applyMock.calledOnce).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("aplies information inside dependency templates", () => {
|
it("aplies information inside dependency templates", () => {
|
||||||
dependencyTemplates = {
|
const dependencyTemplates = {
|
||||||
get: function() {
|
get() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
should(() => {
|
expect(() => {
|
||||||
DependenciesBlockVariableInstance.expressionSource(
|
DependenciesBlockVariableInstance.expressionSource(
|
||||||
dependencyTemplates, {}, {}
|
dependencyTemplates, {}, {}
|
||||||
);
|
);
|
||||||
}).throw("No template for dependency: DependencyMock");
|
}).toThrow("No template for dependency: DependencyMock");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
/* globals describe, it, beforeEach */
|
/* globals describe, it, beforeEach */
|
||||||
"use strict";
|
"use strict";
|
||||||
require("should");
|
|
||||||
const sinon = require("sinon");
|
const sinon = require("sinon");
|
||||||
const ExternalModule = require("../lib/ExternalModule");
|
const ExternalModule = require("../lib/ExternalModule");
|
||||||
const OriginalSource = require("webpack-sources").OriginalSource;
|
const OriginalSource = require("webpack-sources").OriginalSource;
|
||||||
const RawSource = require("webpack-sources").RawSource;
|
const RawSource = require("webpack-sources").RawSource;
|
||||||
|
|
||||||
describe("ExternalModule", function() {
|
describe("ExternalModule", () => {
|
||||||
let externalModule;
|
let externalModule;
|
||||||
let request;
|
let request;
|
||||||
let type;
|
let type;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
request = "some/request";
|
request = "some/request";
|
||||||
type = "some-type";
|
type = "some-type";
|
||||||
externalModule = new ExternalModule(
|
externalModule = new ExternalModule(
|
||||||
|
@ -19,34 +19,34 @@ describe("ExternalModule", function() {
|
||||||
`${type} ${request}`
|
`${type} ${request}`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
describe("#identifier", function() {
|
describe("#identifier", () => {
|
||||||
it("returns an identifier for this module", function() {
|
it("returns an identifier for this module", () => {
|
||||||
const expected = `external "${request}"`;
|
const expected = `external "${request}"`;
|
||||||
externalModule.identifier().should.eql(expected);
|
expect(externalModule.identifier()).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#readableIdentifier", function() {
|
describe("#readableIdentifier", () => {
|
||||||
it("returns an identifier for this module", function() {
|
it("returns an identifier for this module", () => {
|
||||||
const expected = `external "${request}"`;
|
const expected = `external "${request}"`;
|
||||||
externalModule.identifier().should.eql(expected);
|
expect(externalModule.identifier()).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#needRebuild", function() {
|
describe("#needRebuild", () => {
|
||||||
it("always returns false", function() {
|
it("always returns false", () => {
|
||||||
externalModule.needRebuild().should.eql(false);
|
expect(externalModule.needRebuild()).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#size", function() {
|
describe("#size", () => {
|
||||||
it("always returns 42", function() {
|
it("always returns 42", () => {
|
||||||
externalModule.size().should.eql(42);
|
expect(externalModule.size()).toBe(42);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#source", function() {
|
describe("#source", () => {
|
||||||
it("calls getSource with the result of getSourceString", function() {
|
it("calls getSource with the result of getSourceString", () => {
|
||||||
// set up
|
// set up
|
||||||
const expectedString = "something expected stringy";
|
const expectedString = "something expected stringy";
|
||||||
const expectedSource = "something expected sourcy";
|
const expectedSource = "something expected sourcy";
|
||||||
|
@ -57,19 +57,19 @@ describe("ExternalModule", function() {
|
||||||
const result = externalModule.source();
|
const result = externalModule.source();
|
||||||
|
|
||||||
// check
|
// check
|
||||||
externalModule.getSource.callCount.should.eql(1);
|
expect(externalModule.getSource.callCount).toBe(1);
|
||||||
externalModule.getSourceString.callCount.should.eql(1);
|
expect(externalModule.getSourceString.callCount).toBe(1);
|
||||||
externalModule.getSource.args[0][0].should.eql(expectedString);
|
expect(externalModule.getSource.args[0][0]).toBe(expectedString);
|
||||||
result.should.eql(expectedSource);
|
expect(result).toBe(expectedSource);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#getSource", function() {
|
describe("#getSource", () => {
|
||||||
describe("given it should use source maps", function() {
|
describe("given it should use source maps", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
externalModule.useSourceMap = true;
|
externalModule.useSourceMap = true;
|
||||||
});
|
});
|
||||||
it("returns an instance of OriginalSource", function() {
|
it("returns an instance of OriginalSource", () => {
|
||||||
// set up
|
// set up
|
||||||
const someSourceString = "some source string";
|
const someSourceString = "some source string";
|
||||||
|
|
||||||
|
@ -77,14 +77,14 @@ describe("ExternalModule", function() {
|
||||||
const result = externalModule.getSource(someSourceString);
|
const result = externalModule.getSource(someSourceString);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.be.instanceOf(OriginalSource);
|
expect(result).toBeInstanceOf(OriginalSource);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given it does not use source maps", function() {
|
describe("given it does not use source maps", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
externalModule.useSourceMap = false;
|
externalModule.useSourceMap = false;
|
||||||
});
|
});
|
||||||
it("returns an instance of RawSource", function() {
|
it("returns an instance of RawSource", () => {
|
||||||
// set up
|
// set up
|
||||||
const someSourceString = "some source string";
|
const someSourceString = "some source string";
|
||||||
|
|
||||||
|
@ -92,14 +92,14 @@ describe("ExternalModule", function() {
|
||||||
const result = externalModule.getSource(someSourceString);
|
const result = externalModule.getSource(someSourceString);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.be.instanceOf(RawSource);
|
expect(result).toBeInstanceOf(RawSource);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#getSourceForGlobalVariableExternal", function() {
|
describe("#getSourceForGlobalVariableExternal", () => {
|
||||||
describe("given an array as variable name in the global namespace", function() {
|
describe("given an array as variable name in the global namespace", () => {
|
||||||
it("use the array as lookup in the global object", function() {
|
it("use the array as lookup in the global object", () => {
|
||||||
// set up
|
// set up
|
||||||
const type = "window";
|
const type = "window";
|
||||||
const varName = ["foo", "bar"];
|
const varName = ["foo", "bar"];
|
||||||
|
@ -109,11 +109,11 @@ describe("ExternalModule", function() {
|
||||||
const result = externalModule.getSourceForGlobalVariableExternal(varName, type);
|
const result = externalModule.getSourceForGlobalVariableExternal(varName, type);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.eql(expected);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given an single variable name", function() {
|
describe("given an single variable name", () => {
|
||||||
it("look it up in the global namespace", function() {
|
it("look it up in the global namespace", () => {
|
||||||
// set up
|
// set up
|
||||||
const type = "window";
|
const type = "window";
|
||||||
const varName = "foo";
|
const varName = "foo";
|
||||||
|
@ -123,14 +123,14 @@ describe("ExternalModule", function() {
|
||||||
const result = externalModule.getSourceForGlobalVariableExternal(varName, type);
|
const result = externalModule.getSourceForGlobalVariableExternal(varName, type);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.eql(expected);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#getSourceForCommonJsExternal", function() {
|
describe("#getSourceForCommonJsExternal", () => {
|
||||||
describe("given an array as names in the global namespace", function() {
|
describe("given an array as names in the global namespace", () => {
|
||||||
it("use the first to require a module and the rest as lookup on the required module", function() {
|
it("use the first to require a module and the rest as lookup on the required module", () => {
|
||||||
// set up
|
// set up
|
||||||
const varName = ["module", "look", "up"];
|
const varName = ["module", "look", "up"];
|
||||||
const expected = "module.exports = require(module)[\"look\"][\"up\"];";
|
const expected = "module.exports = require(module)[\"look\"][\"up\"];";
|
||||||
|
@ -139,11 +139,11 @@ describe("ExternalModule", function() {
|
||||||
const result = externalModule.getSourceForCommonJsExternal(varName, type);
|
const result = externalModule.getSourceForCommonJsExternal(varName, type);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.eql(expected);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given an single variable name", function() {
|
describe("given an single variable name", () => {
|
||||||
it("require a module with that name", function() {
|
it("require a module with that name", () => {
|
||||||
// set up
|
// set up
|
||||||
const type = "window";
|
const type = "window";
|
||||||
const varName = "foo";
|
const varName = "foo";
|
||||||
|
@ -153,13 +153,13 @@ describe("ExternalModule", function() {
|
||||||
const result = externalModule.getSourceForCommonJsExternal(varName, type);
|
const result = externalModule.getSourceForCommonJsExternal(varName, type);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.eql(expected);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#checkExternalVariable", function() {
|
describe("#checkExternalVariable", () => {
|
||||||
it("creates a check that fails if a variable does not exist", function() {
|
it("creates a check that fails if a variable does not exist", () => {
|
||||||
// set up
|
// set up
|
||||||
const variableToCheck = "foo";
|
const variableToCheck = "foo";
|
||||||
const request = "bar";
|
const request = "bar";
|
||||||
|
@ -170,12 +170,12 @@ describe("ExternalModule", function() {
|
||||||
const result = externalModule.checkExternalVariable(variableToCheck, request);
|
const result = externalModule.checkExternalVariable(variableToCheck, request);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.eql(expected);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#getSourceForAmdOrUmdExternal", function() {
|
describe("#getSourceForAmdOrUmdExternal", () => {
|
||||||
it("looks up a global variable as specified by the id", function() {
|
it("looks up a global variable as specified by the id", () => {
|
||||||
// set up
|
// set up
|
||||||
const id = "someId";
|
const id = "someId";
|
||||||
const optional = false;
|
const optional = false;
|
||||||
|
@ -185,10 +185,10 @@ describe("ExternalModule", function() {
|
||||||
const result = externalModule.getSourceForAmdOrUmdExternal(id, optional, request);
|
const result = externalModule.getSourceForAmdOrUmdExternal(id, optional, request);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.eql(expected);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
describe("given an optinal check is set", function() {
|
describe("given an optinal check is set", () => {
|
||||||
it("ads a check for the existance of the variable before looking it up", function() {
|
it("ads a check for the existance of the variable before looking it up", () => {
|
||||||
// set up
|
// set up
|
||||||
const id = "someId";
|
const id = "someId";
|
||||||
const optional = true;
|
const optional = true;
|
||||||
|
@ -199,13 +199,13 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_someId__;`;
|
||||||
const result = externalModule.getSourceForAmdOrUmdExternal(id, optional, request);
|
const result = externalModule.getSourceForAmdOrUmdExternal(id, optional, request);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.eql(expected);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#getSourceForDefaultCase", function() {
|
describe("#getSourceForDefaultCase", () => {
|
||||||
it("returns the given request as lookup", function() {
|
it("returns the given request as lookup", () => {
|
||||||
// set up
|
// set up
|
||||||
const optional = false;
|
const optional = false;
|
||||||
const expected = "module.exports = some/request;";
|
const expected = "module.exports = some/request;";
|
||||||
|
@ -214,10 +214,10 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_someId__;`;
|
||||||
const result = externalModule.getSourceForDefaultCase(optional, request);
|
const result = externalModule.getSourceForDefaultCase(optional, request);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.eql(expected);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
describe("given an optinal check is requested", function() {
|
describe("given an optinal check is requested", () => {
|
||||||
it("checks for the existance of the request setting it", function() {
|
it("checks for the existance of the request setting it", () => {
|
||||||
// set up
|
// set up
|
||||||
const optional = true;
|
const optional = true;
|
||||||
const expected = `if(typeof some/request === 'undefined') {var e = new Error("Cannot find module \\"some/request\\""); e.code = 'MODULE_NOT_FOUND'; throw e;}
|
const expected = `if(typeof some/request === 'undefined') {var e = new Error("Cannot find module \\"some/request\\""); e.code = 'MODULE_NOT_FOUND'; throw e;}
|
||||||
|
@ -227,15 +227,15 @@ module.exports = some/request;`;
|
||||||
const result = externalModule.getSourceForDefaultCase(optional, request);
|
const result = externalModule.getSourceForDefaultCase(optional, request);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
result.should.eql(expected);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#updateHash", function() {
|
describe("#updateHash", () => {
|
||||||
let hashedText;
|
let hashedText;
|
||||||
let hash;
|
let hash;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
hashedText = "";
|
hashedText = "";
|
||||||
hash = {
|
hash = {
|
||||||
update: (text) => {
|
update: (text) => {
|
||||||
|
@ -245,21 +245,21 @@ module.exports = some/request;`;
|
||||||
externalModule.id = 12345678;
|
externalModule.id = 12345678;
|
||||||
externalModule.updateHash(hash);
|
externalModule.updateHash(hash);
|
||||||
});
|
});
|
||||||
it("updates hash with request", function() {
|
it("updates hash with request", () => {
|
||||||
hashedText.should.containEql("some/request");
|
expect(hashedText).toMatch("some/request");
|
||||||
});
|
});
|
||||||
it("updates hash with type", function() {
|
it("updates hash with type", () => {
|
||||||
hashedText.should.containEql("some-type");
|
expect(hashedText).toMatch("some-type");
|
||||||
});
|
});
|
||||||
it("updates hash with module id", function() {
|
it("updates hash with module id", () => {
|
||||||
hashedText.should.containEql("12345678");
|
expect(hashedText).toMatch("12345678");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#updateHash without optional", function() {
|
describe("#updateHash without optional", () => {
|
||||||
let hashedText;
|
let hashedText;
|
||||||
let hash;
|
let hash;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
hashedText = "";
|
hashedText = "";
|
||||||
hash = {
|
hash = {
|
||||||
update: (text) => {
|
update: (text) => {
|
||||||
|
@ -270,17 +270,17 @@ module.exports = some/request;`;
|
||||||
externalModule.id = 12345678;
|
externalModule.id = 12345678;
|
||||||
externalModule.updateHash(hash);
|
externalModule.updateHash(hash);
|
||||||
});
|
});
|
||||||
it("updates hash with request", function() {
|
it("updates hash with request", () => {
|
||||||
hashedText.should.containEql("some/request");
|
expect(hashedText).toMatch("some/request");
|
||||||
});
|
});
|
||||||
it("updates hash with type", function() {
|
it("updates hash with type", () => {
|
||||||
hashedText.should.containEql("some-type");
|
expect(hashedText).toMatch("some-type");
|
||||||
});
|
});
|
||||||
it("updates hash with optional flag", function() {
|
it("updates hash with optional flag", () => {
|
||||||
hashedText.should.containEql("false");
|
expect(hashedText).toMatch("false");
|
||||||
});
|
});
|
||||||
it("updates hash with module id", function() {
|
it("updates hash with module id", () => {
|
||||||
hashedText.should.containEql("12345678");
|
expect(hashedText).toMatch("12345678");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
/* globals describe, it, beforeEach */
|
/* globals describe, it, beforeEach */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const should = require("should");
|
|
||||||
const HarmonyExportImportedSpecifierDependency = require("../lib/dependencies/HarmonyExportImportedSpecifierDependency");
|
const HarmonyExportImportedSpecifierDependency = require("../lib/dependencies/HarmonyExportImportedSpecifierDependency");
|
||||||
|
|
||||||
describe("HarmonyExportImportedSpecifierDependency", () => {
|
describe("HarmonyExportImportedSpecifierDependency", () => {
|
||||||
describe("getHashValue", () => {
|
describe("getHashValue", () => {
|
||||||
it("should return empty string on missing module", () => { // see e.g. PR #4368
|
it("should return empty string on missing module", () => { // see e.g. PR #4368
|
||||||
var instance = new HarmonyExportImportedSpecifierDependency();
|
var instance = new HarmonyExportImportedSpecifierDependency();
|
||||||
should(instance.getHashValue(undefined)).be.eql("");
|
expect(instance.getHashValue(undefined)).toBe("");
|
||||||
should(instance.getHashValue(null)).be.eql("");
|
expect(instance.getHashValue(null)).toBe("");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
/* globals describe, it */
|
/* globals describe, it */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const should = require("should");
|
|
||||||
const LocalModulesHelpers = require("../lib/dependencies/LocalModulesHelpers");
|
const LocalModulesHelpers = require("../lib/dependencies/LocalModulesHelpers");
|
||||||
|
|
||||||
describe("LocalModulesHelpers", () => {
|
describe("LocalModulesHelpers", () => {
|
||||||
|
|
||||||
describe("addLocalModule", () => {
|
describe("addLocalModule", () => {
|
||||||
it("returns a module var without special characters", () => {
|
it("returns a module var without special characters", () => {
|
||||||
const state = {
|
const state = {
|
||||||
module: "module_sample",
|
module: "module_sample",
|
||||||
localModules: ["first", "second"]
|
localModules: ["first", "second"]
|
||||||
};
|
};
|
||||||
should(LocalModulesHelpers.addLocalModule(state, "local_module_sample")).be.an.instanceOf(Object).and.have.properties({
|
const localModule = LocalModulesHelpers.addLocalModule(state, "local_module_sample");
|
||||||
|
expect(localModule).toBeInstanceOf(Object);
|
||||||
|
expect(localModule).toMatchObject({
|
||||||
module: "module_sample",
|
module: "module_sample",
|
||||||
name: "local_module_sample",
|
name: "local_module_sample",
|
||||||
idx: 2,
|
idx: 2,
|
||||||
used: false
|
used: false
|
||||||
});
|
});
|
||||||
should(state.localModules.length).be.eql(3);
|
expect(state.localModules.length).toBe(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ describe("LocalModulesHelpers", () => {
|
||||||
name: "second"
|
name: "second"
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
should(LocalModulesHelpers.getLocalModule(state, "local_module_sample")).be.eql(null);
|
expect(LocalModulesHelpers.getLocalModule(state, "local_module_sample")).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns local module informtion", () => {
|
it("returns local module informtion", () => {
|
||||||
|
@ -44,7 +44,7 @@ describe("LocalModulesHelpers", () => {
|
||||||
name: "second"
|
name: "second"
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
should(LocalModulesHelpers.getLocalModule(state, "first")).be.eql({
|
expect(LocalModulesHelpers.getLocalModule(state, "first")).toEqual({
|
||||||
name: "first"
|
name: "first"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
require("should");
|
|
||||||
const ModuleDependencyError = require("../lib/ModuleDependencyError");
|
const ModuleDependencyError = require("../lib/ModuleDependencyError");
|
||||||
|
|
||||||
describe("ModuleDependencyError", () => {
|
describe("ModuleDependencyError", () => {
|
||||||
let env;
|
let env;
|
||||||
|
|
||||||
beforeEach(() => env = {});
|
beforeEach(() => {
|
||||||
|
env = {};
|
||||||
it("is a function", () => ModuleDependencyError.should.be.a.Function());
|
});
|
||||||
|
|
||||||
describe("when new error created", () => {
|
describe("when new error created", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -17,17 +16,28 @@ describe("ModuleDependencyError", () => {
|
||||||
env.moduleDependencyError = new ModuleDependencyError("myModule", env.error, "Location");
|
env.moduleDependencyError = new ModuleDependencyError("myModule", env.error, "Location");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is an error", () => env.moduleDependencyError.should.be.an.Error());
|
it("is an error", () => {
|
||||||
|
expect(env.moduleDependencyError).toBeInstanceOf(Error);
|
||||||
|
});
|
||||||
|
|
||||||
it("has a name property", () => env.moduleDependencyError.name.should.be.exactly("ModuleDependencyError"));
|
it("has a name property", () => {
|
||||||
|
expect(env.moduleDependencyError.name).toBe("ModuleDependencyError");
|
||||||
|
});
|
||||||
|
|
||||||
it("has a message property", () => env.moduleDependencyError.message.should.be.exactly("Location Error Message"));
|
it("has a message property", () => {
|
||||||
|
expect(env.moduleDependencyError.message).toBe("Location Error Message");
|
||||||
|
});
|
||||||
|
|
||||||
it("has a details property", () => env.moduleDependencyError.details.should.containEql(path.join("test", "ModuleDependencyError.unittest.js:")));
|
it("has a details property", () => {
|
||||||
|
expect(env.moduleDependencyError.details).toMatch(path.join("test", "ModuleDependencyError.unittest.js:"));
|
||||||
|
});
|
||||||
|
|
||||||
it("has an origin property", () => env.moduleDependencyError.origin.should.be.exactly("myModule"));
|
it("has an origin property", () => {
|
||||||
|
expect(env.moduleDependencyError.origin).toBe("myModule");
|
||||||
it("has an error property", () => env.moduleDependencyError.error.should.be.exactly(env.error));
|
});
|
||||||
|
|
||||||
|
it("has an error property", () => {
|
||||||
|
expect(env.moduleDependencyError.error).toBe(env.error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,6 @@ const Module = require("../lib/Module");
|
||||||
const Chunk = require("../lib/Chunk");
|
const Chunk = require("../lib/Chunk");
|
||||||
const Dependency = require("../lib/Dependency");
|
const Dependency = require("../lib/Dependency");
|
||||||
const ModuleReason = require("../lib/ModuleReason");
|
const ModuleReason = require("../lib/ModuleReason");
|
||||||
const should = require("should");
|
|
||||||
|
|
||||||
describe("ModuleReason", () => {
|
describe("ModuleReason", () => {
|
||||||
let myModule;
|
let myModule;
|
||||||
|
@ -23,11 +22,13 @@ describe("ModuleReason", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("hasChunk", () => {
|
describe("hasChunk", () => {
|
||||||
it("returns false when chunk is not present", () => should(myModuleReason.hasChunk(myChunk)).be.false());
|
it("returns false when chunk is not present", () => {
|
||||||
|
expect(myModuleReason.hasChunk(myChunk)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns true when chunk is present", () => {
|
it("returns true when chunk is present", () => {
|
||||||
myModuleReason.module.addChunk(myChunk);
|
myModuleReason.module.addChunk(myChunk);
|
||||||
should(myModuleReason.hasChunk(myChunk)).be.true();
|
expect(myModuleReason.hasChunk(myChunk)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -36,15 +37,15 @@ describe("ModuleReason", () => {
|
||||||
myModuleReason.module.addChunk(myChunk);
|
myModuleReason.module.addChunk(myChunk);
|
||||||
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
|
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
|
||||||
|
|
||||||
should(myModuleReason.hasChunk(myChunk)).be.false();
|
expect(myModuleReason.hasChunk(myChunk)).toBe(false);
|
||||||
should(myModuleReason.hasChunk(myChunk2)).be.true();
|
expect(myModuleReason.hasChunk(myChunk2)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("if old chunk is not present, new chunks are not added", () => {
|
it("if old chunk is not present, new chunks are not added", () => {
|
||||||
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
|
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
|
||||||
|
|
||||||
should(myModuleReason.hasChunk(myChunk)).be.false();
|
expect(myModuleReason.hasChunk(myChunk)).toBe(false);
|
||||||
should(myModuleReason.hasChunk(myChunk2)).be.false();
|
expect(myModuleReason.hasChunk(myChunk2)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("if already rewritten chunk is present, it is replaced with new chunks", () => {
|
it("if already rewritten chunk is present, it is replaced with new chunks", () => {
|
||||||
|
@ -52,8 +53,8 @@ describe("ModuleReason", () => {
|
||||||
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
|
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
|
||||||
myModuleReason.rewriteChunks(myChunk2, [myChunk]);
|
myModuleReason.rewriteChunks(myChunk2, [myChunk]);
|
||||||
|
|
||||||
should(myModuleReason.hasChunk(myChunk)).be.true();
|
expect(myModuleReason.hasChunk(myChunk)).toBe(true);
|
||||||
should(myModuleReason.hasChunk(myChunk2)).be.false();
|
expect(myModuleReason.hasChunk(myChunk2)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("should");
|
|
||||||
const packageJSON = require("../package.json");
|
const packageJSON = require("../package.json");
|
||||||
const MultiStats = require("../lib/MultiStats");
|
const MultiStats = require("../lib/MultiStats");
|
||||||
|
|
||||||
|
@ -29,7 +28,9 @@ describe("MultiStats", () => {
|
||||||
packageJSON.version = "1.2.3";
|
packageJSON.version = "1.2.3";
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => packageJSON.version = packageVersion);
|
afterEach(() => {
|
||||||
|
packageJSON.version = packageVersion;
|
||||||
|
});
|
||||||
|
|
||||||
describe("created", () => {
|
describe("created", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -44,7 +45,9 @@ describe("MultiStats", () => {
|
||||||
myMultiStats = new MultiStats(stats);
|
myMultiStats = new MultiStats(stats);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("creates a hash string", () => myMultiStats.hash.should.be.exactly("abc123xyz890"));
|
it("creates a hash string", () => {
|
||||||
|
expect(myMultiStats.hash).toBe("abc123xyz890");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("hasErrors", () => {
|
describe("hasErrors", () => {
|
||||||
|
@ -61,7 +64,9 @@ describe("MultiStats", () => {
|
||||||
myMultiStats = new MultiStats(stats);
|
myMultiStats = new MultiStats(stats);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns true", () => myMultiStats.hasErrors().should.be.exactly(true));
|
it("returns true", () => {
|
||||||
|
expect(myMultiStats.hasErrors()).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when one has an error", () => {
|
describe("when one has an error", () => {
|
||||||
|
@ -75,7 +80,9 @@ describe("MultiStats", () => {
|
||||||
myMultiStats = new MultiStats(stats);
|
myMultiStats = new MultiStats(stats);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns true", () => myMultiStats.hasErrors().should.be.exactly(true));
|
it("returns true", () => {
|
||||||
|
expect(myMultiStats.hasErrors()).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when none have errors", () => {
|
describe("when none have errors", () => {
|
||||||
|
@ -87,7 +94,9 @@ describe("MultiStats", () => {
|
||||||
myMultiStats = new MultiStats(stats);
|
myMultiStats = new MultiStats(stats);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns false", () => myMultiStats.hasErrors().should.be.exactly(false));
|
it("returns false", () => {
|
||||||
|
expect(myMultiStats.hasErrors()).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -105,7 +114,9 @@ describe("MultiStats", () => {
|
||||||
myMultiStats = new MultiStats(stats);
|
myMultiStats = new MultiStats(stats);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns true", () => myMultiStats.hasWarnings().should.be.exactly(true));
|
it("returns true", () => {
|
||||||
|
expect(myMultiStats.hasWarnings()).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when one has a warning", () => {
|
describe("when one has a warning", () => {
|
||||||
|
@ -119,7 +130,9 @@ describe("MultiStats", () => {
|
||||||
myMultiStats = new MultiStats(stats);
|
myMultiStats = new MultiStats(stats);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns true", () => myMultiStats.hasWarnings().should.be.exactly(true));
|
it("returns true", () => {
|
||||||
|
expect(myMultiStats.hasWarnings()).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when none have warnings", () => {
|
describe("when none have warnings", () => {
|
||||||
|
@ -131,7 +144,9 @@ describe("MultiStats", () => {
|
||||||
myMultiStats = new MultiStats(stats);
|
myMultiStats = new MultiStats(stats);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns false", () => myMultiStats.hasWarnings().should.be.exactly(false));
|
it("returns false", () => {
|
||||||
|
expect(myMultiStats.hasWarnings()).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -167,7 +182,7 @@ describe("MultiStats", () => {
|
||||||
version: false,
|
version: false,
|
||||||
hash: false
|
hash: false
|
||||||
});
|
});
|
||||||
result.should.deepEqual({
|
expect(result).toEqual({
|
||||||
errors: [
|
errors: [
|
||||||
"(abc123-compilation) abc123-error"
|
"(abc123-compilation) abc123-error"
|
||||||
],
|
],
|
||||||
|
@ -200,7 +215,7 @@ describe("MultiStats", () => {
|
||||||
it("returns plain object representation with json set to true", () => {
|
it("returns plain object representation with json set to true", () => {
|
||||||
myMultiStats = new MultiStats(stats);
|
myMultiStats = new MultiStats(stats);
|
||||||
result = myMultiStats.toJson(true);
|
result = myMultiStats.toJson(true);
|
||||||
result.should.deepEqual({
|
expect(result).toEqual({
|
||||||
errors: [
|
errors: [
|
||||||
"(abc123-compilation) abc123-error"
|
"(abc123-compilation) abc123-error"
|
||||||
],
|
],
|
||||||
|
@ -248,7 +263,7 @@ describe("MultiStats", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns string representation", () => {
|
it("returns string representation", () => {
|
||||||
result.should.be.exactly(
|
expect(result).toBe(
|
||||||
"Hash: abc123xyz890\n" +
|
"Hash: abc123xyz890\n" +
|
||||||
"Version: webpack 1.2.3\n" +
|
"Version: webpack 1.2.3\n" +
|
||||||
"Child abc123-compilation:\n" +
|
"Child abc123-compilation:\n" +
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
const Tapable = require("tapable").Tapable;
|
const Tapable = require("tapable").Tapable;
|
||||||
const SyncHook = require("tapable").SyncHook;
|
const SyncHook = require("tapable").SyncHook;
|
||||||
require("should");
|
|
||||||
const sinon = require("sinon");
|
const sinon = require("sinon");
|
||||||
const MultiWatching = require("../lib/MultiWatching");
|
const MultiWatching = require("../lib/MultiWatching");
|
||||||
|
|
||||||
const createWatching = function() {
|
const createWatching = () => {
|
||||||
return {
|
return {
|
||||||
invalidate: sinon.spy(),
|
invalidate: sinon.spy(),
|
||||||
close: sinon.spy()
|
close: sinon.spy()
|
||||||
|
@ -33,11 +32,13 @@ describe("MultiWatching", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("invalidate", () => {
|
describe("invalidate", () => {
|
||||||
beforeEach(() => myMultiWatching.invalidate());
|
beforeEach(() => {
|
||||||
|
myMultiWatching.invalidate();
|
||||||
|
});
|
||||||
|
|
||||||
it("invalidates each watching", () => {
|
it("invalidates each watching", () => {
|
||||||
watchings[0].invalidate.callCount.should.be.exactly(1);
|
expect(watchings[0].invalidate.callCount).toBe(1);
|
||||||
watchings[1].invalidate.callCount.should.be.exactly(1);
|
expect(watchings[1].invalidate.callCount).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -51,14 +52,14 @@ describe("MultiWatching", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("closes each watching", () => {
|
it("closes each watching", () => {
|
||||||
watchings[0].close.callCount.should.be.exactly(1);
|
expect(watchings[0].close.callCount).toBe(1);
|
||||||
watchings[1].close.callCount.should.be.exactly(1);
|
expect(watchings[1].close.callCount).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls callback after each watching has closed", () => {
|
it("calls callback after each watching has closed", () => {
|
||||||
callClosedFinishedCallback(watchings[0]);
|
callClosedFinishedCallback(watchings[0]);
|
||||||
callClosedFinishedCallback(watchings[1]);
|
callClosedFinishedCallback(watchings[1]);
|
||||||
callback.callCount.should.be.exactly(1);
|
expect(callback.callCount).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,220 +0,0 @@
|
||||||
/* globals describe it */
|
|
||||||
|
|
||||||
var should = require("should");
|
|
||||||
var NodeWatchFileSystem = require("../lib/node/NodeWatchFileSystem");
|
|
||||||
|
|
||||||
describe("NodeWatchFileSystem", function() {
|
|
||||||
it("should throw if 'files' argument is not an array", function() {
|
|
||||||
should(function() {
|
|
||||||
new NodeWatchFileSystem().watch(undefined);
|
|
||||||
}).throw("Invalid arguments: 'files'");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should throw if 'dirs' argument is not an array", function() {
|
|
||||||
should(function() {
|
|
||||||
new NodeWatchFileSystem().watch([], undefined);
|
|
||||||
}).throw("Invalid arguments: 'dirs'");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should throw if 'missing' argument is not an array", function() {
|
|
||||||
should(function() {
|
|
||||||
new NodeWatchFileSystem().watch([], [], undefined);
|
|
||||||
}).throw("Invalid arguments: 'missing'");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should throw if 'starttime' argument is missing", function() {
|
|
||||||
should(function() {
|
|
||||||
new NodeWatchFileSystem().watch([], [], [], "42", {}, function() {});
|
|
||||||
}).throw("Invalid arguments: 'startTime'");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should throw if 'callback' argument is missing", function() {
|
|
||||||
should(function() {
|
|
||||||
new NodeWatchFileSystem().watch([], [], [], 42, {}, undefined);
|
|
||||||
}).throw("Invalid arguments: 'callback'");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should throw if 'options' argument is invalid", function() {
|
|
||||||
should(function() {
|
|
||||||
new NodeWatchFileSystem().watch([], [], [], 42, "options", function() {});
|
|
||||||
}).throw("Invalid arguments: 'options'");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should throw if 'callbackUndelayed' argument is invalid", function() {
|
|
||||||
should(function() {
|
|
||||||
new NodeWatchFileSystem().watch([], [], [], 42, {}, function() {}, "undefined");
|
|
||||||
}).throw("Invalid arguments: 'callbackUndelayed'");
|
|
||||||
});
|
|
||||||
|
|
||||||
if(process.env.NO_WATCH_TESTS) {
|
|
||||||
it("long running tests excluded");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var path = require("path");
|
|
||||||
var fs = require("fs");
|
|
||||||
var fixtures = path.join(__dirname, "fixtures");
|
|
||||||
var fileDirect = path.join(fixtures, "watched-file.txt");
|
|
||||||
var fileSubdir = path.join(fixtures, "subdir", "watched-file.txt");
|
|
||||||
|
|
||||||
this.timeout(10000);
|
|
||||||
|
|
||||||
it("should register a file change (change delayed)", function(done) {
|
|
||||||
var startTime = new Date().getTime();
|
|
||||||
var wfs = new NodeWatchFileSystem();
|
|
||||||
var watcher = wfs.watch([fileDirect], [], [], startTime, {
|
|
||||||
aggregateTimeout: 1000
|
|
||||||
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps) {
|
|
||||||
if(err) throw err;
|
|
||||||
filesModified.should.be.eql([fileDirect]);
|
|
||||||
dirsModified.should.be.eql([]);
|
|
||||||
(typeof fileTimestamps.get(fileDirect)).should.be.eql("number");
|
|
||||||
watcher.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
fs.writeFile(fileDirect, "", function() {});
|
|
||||||
}, 500);
|
|
||||||
});
|
|
||||||
it("should register a file change (watch delayed)", function(done) {
|
|
||||||
var startTime = new Date().getTime();
|
|
||||||
setTimeout(function() {
|
|
||||||
var wfs = new NodeWatchFileSystem();
|
|
||||||
var watcher = wfs.watch([fileDirect], [], [], startTime, {
|
|
||||||
aggregateTimeout: 1000
|
|
||||||
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps) {
|
|
||||||
if(err) throw err;
|
|
||||||
filesModified.should.be.eql([fileDirect]);
|
|
||||||
dirsModified.should.be.eql([]);
|
|
||||||
(typeof fileTimestamps.get(fileDirect)).should.be.eql("number");
|
|
||||||
watcher.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
fs.writeFile(fileDirect, "", function() {});
|
|
||||||
});
|
|
||||||
it("should register a context change (change delayed)", function(done) {
|
|
||||||
var startTime = new Date().getTime();
|
|
||||||
var wfs = new NodeWatchFileSystem();
|
|
||||||
var watcher = wfs.watch([], [fixtures], [], startTime, {
|
|
||||||
aggregateTimeout: 1000
|
|
||||||
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
|
||||||
if(err) throw err;
|
|
||||||
filesModified.should.be.eql([]);
|
|
||||||
dirsModified.should.be.eql([fixtures]);
|
|
||||||
(typeof dirTimestamps.get(fixtures)).should.be.eql("number");
|
|
||||||
watcher.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
fs.writeFile(fileDirect, "", function() {});
|
|
||||||
}, 500);
|
|
||||||
});
|
|
||||||
it("should register a context change (watch delayed)", function(done) {
|
|
||||||
var startTime = new Date().getTime();
|
|
||||||
setTimeout(function() {
|
|
||||||
var wfs = new NodeWatchFileSystem();
|
|
||||||
var watcher = wfs.watch([], [fixtures], [], startTime, {
|
|
||||||
aggregateTimeout: 1000
|
|
||||||
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
|
||||||
if(err) throw err;
|
|
||||||
filesModified.should.be.eql([]);
|
|
||||||
dirsModified.should.be.eql([fixtures]);
|
|
||||||
(typeof dirTimestamps.get(fixtures)).should.be.eql("number");
|
|
||||||
watcher.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
fs.writeFile(fileDirect, "", function() {});
|
|
||||||
});
|
|
||||||
it("should register a context change (change delayed, subdirectory)", function(done) {
|
|
||||||
var startTime = new Date().getTime();
|
|
||||||
var wfs = new NodeWatchFileSystem();
|
|
||||||
var watcher = wfs.watch([], [fixtures], [], startTime, {
|
|
||||||
aggregateTimeout: 1000
|
|
||||||
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
|
||||||
if(err) throw err;
|
|
||||||
filesModified.should.be.eql([]);
|
|
||||||
dirsModified.should.be.eql([fixtures]);
|
|
||||||
(typeof dirTimestamps.get(fixtures)).should.be.eql("number");
|
|
||||||
watcher.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
fs.writeFile(fileSubdir, "", function() {});
|
|
||||||
}, 500);
|
|
||||||
});
|
|
||||||
it("should register a context change (watch delayed, subdirectory)", function(done) {
|
|
||||||
var startTime = new Date().getTime();
|
|
||||||
setTimeout(function() {
|
|
||||||
var wfs = new NodeWatchFileSystem();
|
|
||||||
var watcher = wfs.watch([], [fixtures], [], startTime, {
|
|
||||||
aggregateTimeout: 1000
|
|
||||||
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
|
||||||
if(err) throw err;
|
|
||||||
filesModified.should.be.eql([]);
|
|
||||||
dirsModified.should.be.eql([fixtures]);
|
|
||||||
(typeof dirTimestamps.get(fixtures)).should.be.eql("number");
|
|
||||||
watcher.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
fs.writeFile(fileSubdir, "", function() {});
|
|
||||||
});
|
|
||||||
it("should allow to combine all", function(done) {
|
|
||||||
var startTime = new Date().getTime();
|
|
||||||
setTimeout(function() {
|
|
||||||
var wfs = new NodeWatchFileSystem();
|
|
||||||
var watcher = wfs.watch([fileDirect, fileSubdir], [fixtures], [], startTime, {
|
|
||||||
aggregateTimeout: 1000
|
|
||||||
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
|
||||||
if(err) throw err;
|
|
||||||
filesModified.should.be.eql([fileSubdir, fileDirect]);
|
|
||||||
dirsModified.should.be.eql([fixtures]);
|
|
||||||
(typeof fileTimestamps.get(fileDirect)).should.be.eql("number");
|
|
||||||
(typeof fileTimestamps.get(fileSubdir)).should.be.eql("number");
|
|
||||||
(typeof dirTimestamps.get(fixtures)).should.be.eql("number");
|
|
||||||
watcher.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
fs.writeFile(fileDirect, "", function() {});
|
|
||||||
fs.writeFile(fileSubdir, "", function() {});
|
|
||||||
});
|
|
||||||
it("should sum up multiple changes", function(done) {
|
|
||||||
var startTime = new Date().getTime();
|
|
||||||
var wfs = new NodeWatchFileSystem();
|
|
||||||
var watcher = wfs.watch([fileDirect, fileSubdir], [fixtures], [], startTime, {
|
|
||||||
aggregateTimeout: 1000
|
|
||||||
}, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
|
||||||
if(err) throw err;
|
|
||||||
filesModified.should.be.eql([fileSubdir, fileDirect]);
|
|
||||||
dirsModified.should.be.eql([fixtures]);
|
|
||||||
(typeof fileTimestamps.get(fileDirect)).should.be.eql("number");
|
|
||||||
(typeof fileTimestamps.get(fileSubdir)).should.be.eql("number");
|
|
||||||
(typeof dirTimestamps.get(fixtures)).should.be.eql("number");
|
|
||||||
watcher.close();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
fs.writeFile(fileDirect, "", function() {});
|
|
||||||
setTimeout(function() {
|
|
||||||
fs.writeFile(fileDirect, "", function() {});
|
|
||||||
setTimeout(function() {
|
|
||||||
fs.writeFile(fileDirect, "", function() {});
|
|
||||||
setTimeout(function() {
|
|
||||||
fs.writeFile(fileSubdir, "", function() {});
|
|
||||||
}, 500);
|
|
||||||
}, 500);
|
|
||||||
}, 500);
|
|
||||||
}, 500);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* globals describe, it, beforeEach, afterEach */
|
/* globals describe, it, beforeEach, afterEach */
|
||||||
"use strict";
|
"use strict";
|
||||||
require("should");
|
|
||||||
const sinon = require("sinon");
|
const sinon = require("sinon");
|
||||||
const NormalModule = require("../lib/NormalModule");
|
const NormalModule = require("../lib/NormalModule");
|
||||||
const NullDependency = require("../lib/dependencies/NullDependency");
|
const NullDependency = require("../lib/dependencies/NullDependency");
|
||||||
|
@ -8,7 +8,7 @@ const SourceMapSource = require("webpack-sources").SourceMapSource;
|
||||||
const OriginalSource = require("webpack-sources").OriginalSource;
|
const OriginalSource = require("webpack-sources").OriginalSource;
|
||||||
const RawSource = require("webpack-sources").RawSource;
|
const RawSource = require("webpack-sources").RawSource;
|
||||||
|
|
||||||
describe("NormalModule", function() {
|
describe("NormalModule", () => {
|
||||||
let normalModule;
|
let normalModule;
|
||||||
let request;
|
let request;
|
||||||
let userRequest;
|
let userRequest;
|
||||||
|
@ -16,7 +16,7 @@ describe("NormalModule", function() {
|
||||||
let loaders;
|
let loaders;
|
||||||
let resource;
|
let resource;
|
||||||
let parser;
|
let parser;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
request = "some/request";
|
request = "some/request";
|
||||||
userRequest = "some/userRequest";
|
userRequest = "some/userRequest";
|
||||||
rawRequest = "some/rawRequest";
|
rawRequest = "some/rawRequest";
|
||||||
|
@ -38,37 +38,37 @@ describe("NormalModule", function() {
|
||||||
cacheable: true
|
cacheable: true
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
describe("#identifier", function() {
|
describe("#identifier", () => {
|
||||||
it("returns an identifier for this module", function() {
|
it("returns an identifier for this module", () => {
|
||||||
normalModule.identifier().should.eql(request);
|
expect(normalModule.identifier()).toBe(request);
|
||||||
});
|
});
|
||||||
it("returns an identifier from toString", function() {
|
it("returns an identifier from toString", () => {
|
||||||
normalModule.debugId = 1000;
|
normalModule.debugId = 1000;
|
||||||
normalModule.toString().should.eql("Module[1000]");
|
expect(normalModule.toString()).toBe("Module[1000]");
|
||||||
normalModule.id = 1;
|
normalModule.id = 1;
|
||||||
normalModule.toString().should.eql("Module[1]");
|
expect(normalModule.toString()).toBe("Module[1]");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#readableIdentifier", function() {
|
describe("#readableIdentifier", () => {
|
||||||
it("calls the given requestShortener with the user request", function() {
|
it("calls the given requestShortener with the user request", () => {
|
||||||
const spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
normalModule.readableIdentifier({
|
normalModule.readableIdentifier({
|
||||||
shorten: spy
|
shorten: spy
|
||||||
});
|
});
|
||||||
spy.callCount.should.eql(1);
|
expect(spy.callCount).toBe(1);
|
||||||
spy.args[0][0].should.eql(userRequest);
|
expect(spy.args[0][0]).toBe(userRequest);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#libIdent", function() {
|
describe("#libIdent", () => {
|
||||||
it("contextifies the userRequest of the module", function() {
|
it("contextifies the userRequest of the module", () => {
|
||||||
normalModule.libIdent({
|
expect(normalModule.libIdent({
|
||||||
context: "some/context"
|
context: "some/context"
|
||||||
}).should.eql("../userRequest");
|
})).toBe("../userRequest");
|
||||||
});
|
});
|
||||||
describe("given a userRequest containing loaders", function() {
|
describe("given a userRequest containing loaders", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
userRequest = "some/userRequest!some/other/userRequest!some/thing/is/off/here";
|
userRequest = "some/userRequest!some/other/userRequest!some/thing/is/off/here";
|
||||||
normalModule = new NormalModule(
|
normalModule = new NormalModule(
|
||||||
"javascript/auto",
|
"javascript/auto",
|
||||||
|
@ -80,14 +80,14 @@ describe("NormalModule", function() {
|
||||||
parser
|
parser
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("contextifies every path in the userRequest", function() {
|
it("contextifies every path in the userRequest", () => {
|
||||||
normalModule.libIdent({
|
expect(normalModule.libIdent({
|
||||||
context: "some/context"
|
context: "some/context"
|
||||||
}).should.eql("../userRequest!../other/userRequest!../thing/is/off/here");
|
})).toBe("../userRequest!../other/userRequest!../thing/is/off/here");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given a userRequest containing query parameters", function() {
|
describe("given a userRequest containing query parameters", () => {
|
||||||
it("ignores paths in query parameters", function() {
|
it("ignores paths in query parameters", () => {
|
||||||
userRequest = "some/context/loader?query=foo\\bar&otherPath=testpath/other";
|
userRequest = "some/context/loader?query=foo\\bar&otherPath=testpath/other";
|
||||||
normalModule = new NormalModule(
|
normalModule = new NormalModule(
|
||||||
"javascript/auto",
|
"javascript/auto",
|
||||||
|
@ -98,20 +98,20 @@ describe("NormalModule", function() {
|
||||||
resource,
|
resource,
|
||||||
parser
|
parser
|
||||||
);
|
);
|
||||||
normalModule.libIdent({
|
expect(normalModule.libIdent({
|
||||||
context: "some/context",
|
context: "some/context",
|
||||||
}).should.eql("./loader?query=foo\\bar&otherPath=testpath/other");
|
})).toBe("./loader?query=foo\\bar&otherPath=testpath/other");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#nameForCondition", function() {
|
describe("#nameForCondition", () => {
|
||||||
it("return the resource", function() {
|
it("return the resource", () => {
|
||||||
normalModule.nameForCondition().should.eql(resource);
|
expect(normalModule.nameForCondition()).toBe(resource);
|
||||||
});
|
});
|
||||||
describe("given a resource containing a ?-sign", function() {
|
describe("given a resource containing a ?-sign", () => {
|
||||||
const baseResource = "some/resource";
|
const baseResource = "some/resource";
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
resource = baseResource + "?some=query";
|
resource = baseResource + "?some=query";
|
||||||
normalModule = new NormalModule(
|
normalModule = new NormalModule(
|
||||||
"javascript/auto",
|
"javascript/auto",
|
||||||
|
@ -123,105 +123,105 @@ describe("NormalModule", function() {
|
||||||
parser
|
parser
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("return only the part before the ?-sign", function() {
|
it("return only the part before the ?-sign", () => {
|
||||||
normalModule.nameForCondition().should.eql(baseResource);
|
expect(normalModule.nameForCondition()).toBe(baseResource);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#createSourceForAsset", function() {
|
describe("#createSourceForAsset", () => {
|
||||||
let name;
|
let name;
|
||||||
let content;
|
let content;
|
||||||
let sourceMap;
|
let sourceMap;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
name = "some name";
|
name = "some name";
|
||||||
content = "some content";
|
content = "some content";
|
||||||
sourceMap = "some sourcemap";
|
sourceMap = "some sourcemap";
|
||||||
});
|
});
|
||||||
describe("given no sourcemap", function() {
|
describe("given no sourcemap", () => {
|
||||||
it("returns a RawSource", function() {
|
it("returns a RawSource", () => {
|
||||||
normalModule.createSourceForAsset(name, content).should.be.instanceOf(RawSource);
|
expect(normalModule.createSourceForAsset(name, content)).toBeInstanceOf(RawSource);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given a string as the sourcemap", function() {
|
describe("given a string as the sourcemap", () => {
|
||||||
it("returns a OriginalSource", function() {
|
it("returns a OriginalSource", () => {
|
||||||
normalModule.createSourceForAsset(name, content, sourceMap).should.be.instanceOf(OriginalSource);
|
expect(normalModule.createSourceForAsset(name, content, sourceMap)).toBeInstanceOf(OriginalSource);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given a some other kind of sourcemap", function() {
|
describe("given a some other kind of sourcemap", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
sourceMap = () => {};
|
sourceMap = () => {};
|
||||||
});
|
});
|
||||||
it("returns a SourceMapSource", function() {
|
it("returns a SourceMapSource", () => {
|
||||||
normalModule.createSourceForAsset(name, content, sourceMap).should.be.instanceOf(SourceMapSource);
|
expect(normalModule.createSourceForAsset(name, content, sourceMap)).toBeInstanceOf(SourceMapSource);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#source", function() {
|
describe("#source", () => {
|
||||||
describe("without the module having any source", function() {
|
describe("without the module having any source", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
normalModule._source = null;
|
normalModule._source = null;
|
||||||
});
|
});
|
||||||
it("returns a Source containing an Error", function() {
|
it("returns a Source containing an Error", () => {
|
||||||
normalModule.source().should.be.instanceOf(RawSource);
|
expect(normalModule.source()).toBeInstanceOf(RawSource);
|
||||||
normalModule.source().source().should.eql("throw new Error('No source available');");
|
expect(normalModule.source().source()).toBe("throw new Error('No source available');");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#originalSource", function() {
|
describe("#originalSource", () => {
|
||||||
let expectedSource = "some source";
|
let expectedSource = "some source";
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
normalModule._source = new RawSource(expectedSource);
|
normalModule._source = new RawSource(expectedSource);
|
||||||
});
|
});
|
||||||
it("returns an original Source", function() {
|
it("returns an original Source", () => {
|
||||||
normalModule.originalSource().should.eql(normalModule._source);
|
expect(normalModule.originalSource()).toBe(normalModule._source);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#updateHashWithSource", function() {
|
describe("#updateHashWithSource", () => {
|
||||||
let hashSpy;
|
let hashSpy;
|
||||||
let hash;
|
let hash;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
hashSpy = sinon.spy();
|
hashSpy = sinon.spy();
|
||||||
hash = {
|
hash = {
|
||||||
update: hashSpy
|
update: hashSpy
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
describe("without the module having any source", function() {
|
describe("without the module having any source", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
normalModule._source = null;
|
normalModule._source = null;
|
||||||
});
|
});
|
||||||
it("calls hash function with \"null\"", function() {
|
it("calls hash function with \"null\"", () => {
|
||||||
normalModule.updateHashWithSource(hash);
|
normalModule.updateHashWithSource(hash);
|
||||||
hashSpy.callCount.should.eql(1);
|
expect(hashSpy.callCount).toBe(1);
|
||||||
hashSpy.args[0][0].should.eql("null");
|
expect(hashSpy.args[0][0]).toBe("null");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("without the module having source", function() {
|
describe("without the module having source", () => {
|
||||||
let expectedSource = "some source";
|
let expectedSource = "some source";
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
normalModule._source = new RawSource(expectedSource);
|
normalModule._source = new RawSource(expectedSource);
|
||||||
});
|
});
|
||||||
it("calls hash function with \"source\" and then the actual source of the module", function() {
|
it("calls hash function with \"source\" and then the actual source of the module", function() {
|
||||||
normalModule.updateHashWithSource(hash);
|
normalModule.updateHashWithSource(hash);
|
||||||
hashSpy.callCount.should.eql(2);
|
expect(hashSpy.callCount).toBe(2);
|
||||||
hashSpy.args[0][0].should.eql("source");
|
expect(hashSpy.args[0][0]).toBe("source");
|
||||||
hashSpy.args[1][0].should.eql(expectedSource);
|
expect(hashSpy.args[1][0]).toBe(expectedSource);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("#hasDependencies", function() {
|
describe("#hasDependencies", () => {
|
||||||
it("returns true if has dependencies", function() {
|
it("returns true if has dependencies", () => {
|
||||||
normalModule.addDependency(new NullDependency());
|
normalModule.addDependency(new NullDependency());
|
||||||
normalModule.hasDependencies().should.eql(true);
|
expect(normalModule.hasDependencies()).toBe(true);
|
||||||
});
|
});
|
||||||
it("returns false if has dependencies", function() {
|
it("returns false if has dependencies", () => {
|
||||||
normalModule.hasDependencies().should.eql(false);
|
expect(normalModule.hasDependencies()).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("#needRebuild", function() {
|
describe("#needRebuild", () => {
|
||||||
let fileTimestamps;
|
let fileTimestamps;
|
||||||
let contextTimestamps;
|
let contextTimestamps;
|
||||||
let fileDependencies;
|
let fileDependencies;
|
||||||
|
@ -229,14 +229,12 @@ describe("NormalModule", function() {
|
||||||
let fileA;
|
let fileA;
|
||||||
let fileB;
|
let fileB;
|
||||||
|
|
||||||
function setDeps(
|
function setDeps(fileDependencies, contextDependencies) {
|
||||||
fileDependencies,
|
|
||||||
contextDependencies) {
|
|
||||||
normalModule.buildInfo.fileDependencies = fileDependencies;
|
normalModule.buildInfo.fileDependencies = fileDependencies;
|
||||||
normalModule.buildInfo.contextDependencies = contextDependencies;
|
normalModule.buildInfo.contextDependencies = contextDependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
fileA = "fileA";
|
fileA = "fileA";
|
||||||
fileB = "fileB";
|
fileB = "fileB";
|
||||||
fileDependencies = [fileA, fileB];
|
fileDependencies = [fileA, fileB];
|
||||||
|
@ -252,47 +250,47 @@ describe("NormalModule", function() {
|
||||||
normalModule.buildTimestamp = 2;
|
normalModule.buildTimestamp = 2;
|
||||||
setDeps(fileDependencies, contextDependencies);
|
setDeps(fileDependencies, contextDependencies);
|
||||||
});
|
});
|
||||||
describe("given all timestamps are older than the buildTimestamp", function() {
|
describe("given all timestamps are older than the buildTimestamp", () => {
|
||||||
it("returns false", function() {
|
it("returns false", () => {
|
||||||
normalModule.needRebuild(fileTimestamps, contextTimestamps).should.eql(false);
|
expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given a file timestamp is newer than the buildTimestamp", function() {
|
describe("given a file timestamp is newer than the buildTimestamp", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
fileTimestamps.set(fileA, 3);
|
fileTimestamps.set(fileA, 3);
|
||||||
});
|
});
|
||||||
it("returns true", function() {
|
it("returns true", () => {
|
||||||
normalModule.needRebuild(fileTimestamps, contextTimestamps).should.eql(true);
|
expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given a no file timestamp exists", function() {
|
describe("given a no file timestamp exists", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
fileTimestamps = new Map();
|
fileTimestamps = new Map();
|
||||||
});
|
});
|
||||||
it("returns true", function() {
|
it("returns true", () => {
|
||||||
normalModule.needRebuild(fileTimestamps, contextTimestamps).should.eql(true);
|
expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given a context timestamp is newer than the buildTimestamp", function() {
|
describe("given a context timestamp is newer than the buildTimestamp", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
contextTimestamps.set(fileA, 3);
|
contextTimestamps.set(fileA, 3);
|
||||||
});
|
});
|
||||||
it("returns true", function() {
|
it("returns true", () => {
|
||||||
normalModule.needRebuild(fileTimestamps, contextTimestamps).should.eql(true);
|
expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given a no context timestamp exists", function() {
|
describe("given a no context timestamp exists", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
contextTimestamps = new Map();
|
contextTimestamps = new Map();
|
||||||
});
|
});
|
||||||
it("returns true", function() {
|
it("returns true", () => {
|
||||||
normalModule.needRebuild(fileTimestamps, contextTimestamps).should.eql(true);
|
expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("#splitVariablesInUniqueNamedChunks", function() {
|
describe("#splitVariablesInUniqueNamedChunks", () => {
|
||||||
let variables;
|
let variables;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
variables = [{
|
variables = [{
|
||||||
name: "foo"
|
name: "foo"
|
||||||
}, {
|
}, {
|
||||||
|
@ -305,147 +303,147 @@ describe("NormalModule", function() {
|
||||||
name: "more"
|
name: "more"
|
||||||
}];
|
}];
|
||||||
});
|
});
|
||||||
describe("given an empty array of vars", function() {
|
describe("given an empty array of vars", () => {
|
||||||
it("returns an empty array", function() {
|
it("returns an empty array", () => {
|
||||||
normalModule.splitVariablesInUniqueNamedChunks([]).should.eql([
|
expect(normalModule.splitVariablesInUniqueNamedChunks([])).toEqual([
|
||||||
[]
|
[]
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given an array of distrinct variables", function() {
|
describe("given an array of distrinct variables", () => {
|
||||||
it("returns an array containing an array containing the variables", function() {
|
it("returns an array containing an array containing the variables", () => {
|
||||||
normalModule.splitVariablesInUniqueNamedChunks(variables).should.eql([variables]);
|
expect(normalModule.splitVariablesInUniqueNamedChunks(variables)).toEqual([variables]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given an array with duplicate variables", function() {
|
describe("given an array with duplicate variables", () => {
|
||||||
it("returns several arrays each containing only distinct variable names", function() {
|
it("returns several arrays each containing only distinct variable names", () => {
|
||||||
normalModule.splitVariablesInUniqueNamedChunks(variables.concat(variables)).should.eql([variables, variables]);
|
expect(normalModule.splitVariablesInUniqueNamedChunks(variables.concat(variables))).toEqual([variables, variables]);
|
||||||
});
|
});
|
||||||
describe("and a duplicate as the last variable", function() {
|
describe("and a duplicate as the last variable", () => {
|
||||||
it("returns correctly split distinct arrays", function() {
|
it("returns correctly split distinct arrays", () => {
|
||||||
normalModule.splitVariablesInUniqueNamedChunks(variables.concat(variables).concat(variables[0])).should.eql([variables, variables, [variables[0]]]);
|
expect(normalModule.splitVariablesInUniqueNamedChunks(variables.concat(variables).concat(variables[0]))).toEqual([variables, variables, [variables[0]]]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#applyNoParseRule", function() {
|
describe("#applyNoParseRule", () => {
|
||||||
let rule;
|
let rule;
|
||||||
let content;
|
let content;
|
||||||
describe("given a string as rule", function() {
|
describe("given a string as rule", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
rule = "some-rule";
|
rule = "some-rule";
|
||||||
});
|
});
|
||||||
describe("and the content starting with the string specified in rule", function() {
|
describe("and the content starting with the string specified in rule", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
content = rule + "some-content";
|
content = rule + "some-content";
|
||||||
});
|
});
|
||||||
it("returns true", function() {
|
it("returns true", () => {
|
||||||
normalModule.shouldPreventParsing(rule, content).should.eql(true);
|
expect(normalModule.shouldPreventParsing(rule, content)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("and the content does not start with the string specified in rule", function() {
|
describe("and the content does not start with the string specified in rule", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
content = "some-content";
|
content = "some-content";
|
||||||
});
|
});
|
||||||
it("returns false", function() {
|
it("returns false", () => {
|
||||||
normalModule.shouldPreventParsing(rule, content).should.eql(false);
|
expect(normalModule.shouldPreventParsing(rule, content)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given a regex as rule", function() {
|
describe("given a regex as rule", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
rule = /some-rule/;
|
rule = /some-rule/;
|
||||||
});
|
});
|
||||||
describe("and the content matches the rule", function() {
|
describe("and the content matches the rule", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
content = rule + "some-content";
|
content = rule + "some-content";
|
||||||
});
|
});
|
||||||
it("returns true", function() {
|
it("returns true", () => {
|
||||||
normalModule.shouldPreventParsing(rule, content).should.eql(true);
|
expect(normalModule.shouldPreventParsing(rule, content)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("and the content does not match the rule", function() {
|
describe("and the content does not match the rule", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
content = "some-content";
|
content = "some-content";
|
||||||
});
|
});
|
||||||
it("returns false", function() {
|
it("returns false", () => {
|
||||||
normalModule.shouldPreventParsing(rule, content).should.eql(false);
|
expect(normalModule.shouldPreventParsing(rule, content)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#shouldPreventParsing", function() {
|
describe("#shouldPreventParsing", () => {
|
||||||
let applyNoParseRuleSpy;
|
let applyNoParseRuleSpy;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
applyNoParseRuleSpy = sinon.stub();
|
applyNoParseRuleSpy = sinon.stub();
|
||||||
normalModule.applyNoParseRule = applyNoParseRuleSpy;
|
normalModule.applyNoParseRule = applyNoParseRuleSpy;
|
||||||
});
|
});
|
||||||
describe("given no noParseRule", function() {
|
describe("given no noParseRule", () => {
|
||||||
it("returns false", function() {
|
it("returns false", () => {
|
||||||
normalModule.shouldPreventParsing().should.eql(false);
|
expect(normalModule.shouldPreventParsing()).toBe(false);
|
||||||
applyNoParseRuleSpy.callCount.should.eql(0);
|
expect(applyNoParseRuleSpy.callCount).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("given a noParseRule", function() {
|
describe("given a noParseRule", () => {
|
||||||
let returnValOfSpy;
|
let returnValOfSpy;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
returnValOfSpy = true;
|
returnValOfSpy = true;
|
||||||
applyNoParseRuleSpy.returns(returnValOfSpy);
|
applyNoParseRuleSpy.returns(returnValOfSpy);
|
||||||
});
|
});
|
||||||
describe("that is a string", function() {
|
describe("that is a string", () => {
|
||||||
it("calls and returns whatever applyNoParseRule returns", function() {
|
it("calls and returns whatever applyNoParseRule returns", () => {
|
||||||
normalModule.shouldPreventParsing("some rule").should.eql(returnValOfSpy);
|
expect(normalModule.shouldPreventParsing("some rule")).toBe(returnValOfSpy);
|
||||||
applyNoParseRuleSpy.callCount.should.eql(1);
|
expect(applyNoParseRuleSpy.callCount).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("that is a regex", function() {
|
describe("that is a regex", () => {
|
||||||
it("calls and returns whatever applyNoParseRule returns", function() {
|
it("calls and returns whatever applyNoParseRule returns", () => {
|
||||||
normalModule.shouldPreventParsing("some rule").should.eql(returnValOfSpy);
|
expect(normalModule.shouldPreventParsing("some rule")).toBe(returnValOfSpy);
|
||||||
applyNoParseRuleSpy.callCount.should.eql(1);
|
expect(applyNoParseRuleSpy.callCount).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("that is an array", function() {
|
describe("that is an array", () => {
|
||||||
describe("of strings and or regexs", function() {
|
describe("of strings and or regexs", () => {
|
||||||
let someRules;
|
let someRules;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
someRules = [
|
someRules = [
|
||||||
"some rule",
|
"some rule",
|
||||||
/some rule1/,
|
/some rule1/,
|
||||||
"some rule2",
|
"some rule2",
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
describe("and none of them match", function() {
|
describe("and none of them match", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
returnValOfSpy = false;
|
returnValOfSpy = false;
|
||||||
applyNoParseRuleSpy.returns(returnValOfSpy);
|
applyNoParseRuleSpy.returns(returnValOfSpy);
|
||||||
});
|
});
|
||||||
it("returns false", function() {
|
it("returns false", () => {
|
||||||
normalModule.shouldPreventParsing(someRules).should.eql(returnValOfSpy);
|
expect(normalModule.shouldPreventParsing(someRules)).toBe(returnValOfSpy);
|
||||||
applyNoParseRuleSpy.callCount.should.eql(3);
|
expect(applyNoParseRuleSpy.callCount).toBe(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("and the first of them matches", function() {
|
describe("and the first of them matches", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
returnValOfSpy = true;
|
returnValOfSpy = true;
|
||||||
applyNoParseRuleSpy.returns(returnValOfSpy);
|
applyNoParseRuleSpy.returns(returnValOfSpy);
|
||||||
});
|
});
|
||||||
it("returns true", function() {
|
it("returns true", () => {
|
||||||
normalModule.shouldPreventParsing(someRules).should.eql(returnValOfSpy);
|
expect(normalModule.shouldPreventParsing(someRules)).toBe(returnValOfSpy);
|
||||||
applyNoParseRuleSpy.callCount.should.eql(1);
|
expect(applyNoParseRuleSpy.callCount).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("and the last of them matches", function() {
|
describe("and the last of them matches", () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
returnValOfSpy = true;
|
returnValOfSpy = true;
|
||||||
applyNoParseRuleSpy.onCall(0).returns(false);
|
applyNoParseRuleSpy.onCall(0).returns(false);
|
||||||
applyNoParseRuleSpy.onCall(1).returns(false);
|
applyNoParseRuleSpy.onCall(1).returns(false);
|
||||||
applyNoParseRuleSpy.onCall(2).returns(true);
|
applyNoParseRuleSpy.onCall(2).returns(true);
|
||||||
});
|
});
|
||||||
it("returns true", function() {
|
it("returns true", () => {
|
||||||
normalModule.shouldPreventParsing(someRules).should.eql(returnValOfSpy);
|
expect(normalModule.shouldPreventParsing(someRules)).toBe(returnValOfSpy);
|
||||||
applyNoParseRuleSpy.callCount.should.eql(3);
|
expect(applyNoParseRuleSpy.callCount).toBe(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,39 +1,12 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("should");
|
|
||||||
const sinon = require("sinon");
|
|
||||||
const NullDependency = require("../lib/dependencies/NullDependency");
|
const NullDependency = require("../lib/dependencies/NullDependency");
|
||||||
|
|
||||||
describe("NullDependency", () => {
|
describe("NullDependency", () => {
|
||||||
let env;
|
|
||||||
|
|
||||||
beforeEach(() => env = {});
|
|
||||||
|
|
||||||
it("is a function", () => NullDependency.should.be.a.Function());
|
|
||||||
|
|
||||||
describe("when created", () => {
|
describe("when created", () => {
|
||||||
beforeEach(() => env.nullDependency = new NullDependency());
|
it("has a null type", () => {
|
||||||
|
const nullDependency = new NullDependency();
|
||||||
it("has a null type", () => env.nullDependency.type.should.be.exactly("null"));
|
expect(nullDependency.type).toBe("null");
|
||||||
|
|
||||||
it("has update hash function", () => env.nullDependency.updateHash.should.be.Function());
|
|
||||||
|
|
||||||
it("does not update hash", () => {
|
|
||||||
const hash = {
|
|
||||||
update: sinon.stub()
|
|
||||||
};
|
|
||||||
env.nullDependency.updateHash(hash);
|
|
||||||
hash.update.called.should.be.false();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Template", () => {
|
|
||||||
it("is a function", () => NullDependency.Template.should.be.a.Function());
|
|
||||||
|
|
||||||
describe("when created", () => {
|
|
||||||
beforeEach(() => env.nullDependencyTemplate = new NullDependency.Template());
|
|
||||||
|
|
||||||
it("has apply function", () => env.nullDependencyTemplate.apply.should.be.Function());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const should = require("should");
|
|
||||||
|
|
||||||
const Parser = require("../lib/Parser");
|
const Parser = require("../lib/Parser");
|
||||||
const BasicEvaluatedExpression = require("../lib/BasicEvaluatedExpression");
|
const BasicEvaluatedExpression = require("../lib/BasicEvaluatedExpression");
|
||||||
|
|
||||||
|
@ -281,8 +279,8 @@ describe("Parser", () => {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
const actual = testParser.parse(source);
|
const actual = testParser.parse(source);
|
||||||
should.strictEqual(typeof actual, "object");
|
expect(typeof actual).toBe("object");
|
||||||
actual.should.be.eql(state);
|
expect(actual).toEqual(state);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -304,13 +302,13 @@ describe("Parser", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const actual = testParser.parse(source);
|
const actual = testParser.parse(source);
|
||||||
should.strictEqual(typeof actual, "object");
|
expect(typeof actual).toBe("object");
|
||||||
should.strictEqual(typeof actual.comments, "object");
|
expect(typeof actual.comments).toBe("object");
|
||||||
actual.comments.forEach((element, index) => {
|
actual.comments.forEach((element, index) => {
|
||||||
should.strictEqual(typeof element.type, "string");
|
expect(typeof element.type).toBe("string");
|
||||||
should.strictEqual(typeof element.value, "string");
|
expect(typeof element.value).toBe("string");
|
||||||
element.type.should.be.eql(state[index].type);
|
expect(element.type).toBe(state[index].type);
|
||||||
element.value.should.be.eql(state[index].value);
|
expect(element.value).toBe(state[index].value);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -458,7 +456,7 @@ describe("Parser", () => {
|
||||||
|
|
||||||
it("should eval " + key, () => {
|
it("should eval " + key, () => {
|
||||||
const evalExpr = evaluateInParser(key);
|
const evalExpr = evaluateInParser(key);
|
||||||
evalExprToString(evalExpr).should.be.eql(testCases[key] ? key + " " + testCases[key] : key);
|
expect(evalExprToString(evalExpr)).toBe(testCases[key] ? key + " " + testCases[key] : key);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -475,7 +473,7 @@ describe("Parser", () => {
|
||||||
const expr = cases[name];
|
const expr = cases[name];
|
||||||
it(name, () => {
|
it(name, () => {
|
||||||
const actual = parser.parse(expr);
|
const actual = parser.parse(expr);
|
||||||
should.strictEqual(typeof actual, "object");
|
expect(typeof actual).toBe("object");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -506,7 +504,7 @@ describe("Parser", () => {
|
||||||
Object.keys(cases).forEach((name) => {
|
Object.keys(cases).forEach((name) => {
|
||||||
it(name, () => {
|
it(name, () => {
|
||||||
const actual = parser.parse(cases[name][0]);
|
const actual = parser.parse(cases[name][0]);
|
||||||
actual.should.be.eql(cases[name][1]);
|
expect(actual).toEqual(cases[name][1]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("should");
|
|
||||||
const ProfilingPlugin = require("../lib/debug/ProfilingPlugin");
|
const ProfilingPlugin = require("../lib/debug/ProfilingPlugin");
|
||||||
|
|
||||||
describe("Profiling Plugin", () => {
|
describe("Profiling Plugin", () => {
|
||||||
|
@ -8,55 +7,36 @@ describe("Profiling Plugin", () => {
|
||||||
const plugin = new ProfilingPlugin({
|
const plugin = new ProfilingPlugin({
|
||||||
outPath: "invest_in_doge_coin"
|
outPath: "invest_in_doge_coin"
|
||||||
});
|
});
|
||||||
plugin.outPath.should.equal("invest_in_doge_coin");
|
expect(plugin.outPath).toBe("invest_in_doge_coin");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle no options", () => {
|
it("should handle no options", () => {
|
||||||
const plugin = new ProfilingPlugin();
|
const plugin = new ProfilingPlugin();
|
||||||
plugin.outPath.should.equal("events.json");
|
expect(plugin.outPath).toBe("events.json");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle when unable to require the inspector", (done) => {
|
it("should handle when unable to require the inspector", () => {
|
||||||
const profiler = new ProfilingPlugin.Profiler();
|
const profiler = new ProfilingPlugin.Profiler();
|
||||||
|
return profiler.startProfiling();
|
||||||
profiler.startProfiling().then(() => {
|
|
||||||
done();
|
|
||||||
}).catch(e => {
|
|
||||||
done(e);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle when unable to start a profiling session", (done) => {
|
it("should handle when unable to start a profiling session", () => {
|
||||||
const profiler = new ProfilingPlugin.Profiler({
|
const profiler = new ProfilingPlugin.Profiler({
|
||||||
Session() {
|
Session() {
|
||||||
throw new Error("Sean Larkin was here.");
|
throw new Error("Sean Larkin was here.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
profiler.startProfiling().then(() => {
|
return profiler.startProfiling();
|
||||||
done();
|
|
||||||
}).catch(e => {
|
|
||||||
done(e);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("handles sending a profiling message when no session", (done) => {
|
it("handles sending a profiling message when no session", () => {
|
||||||
const profiler = new ProfilingPlugin.Profiler();
|
const profiler = new ProfilingPlugin.Profiler();
|
||||||
|
return profiler.sendCommand("randy", "is a puppers");
|
||||||
profiler.sendCommand("randy", "is a puppers").then(() => {
|
|
||||||
done();
|
|
||||||
}).catch(e => {
|
|
||||||
done(e);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("handles destroying when no session", (done) => {
|
it("handles destroying when no session", () => {
|
||||||
const profiler = new ProfilingPlugin.Profiler();
|
const profiler = new ProfilingPlugin.Profiler();
|
||||||
|
return profiler.destroy();
|
||||||
profiler.destroy().then(() => {
|
|
||||||
done();
|
|
||||||
}).catch(e => {
|
|
||||||
done(e);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,29 +4,25 @@ const RawModule = require("../lib/RawModule");
|
||||||
const OriginalSource = require("webpack-sources").OriginalSource;
|
const OriginalSource = require("webpack-sources").OriginalSource;
|
||||||
const RawSource = require("webpack-sources").RawSource;
|
const RawSource = require("webpack-sources").RawSource;
|
||||||
const RequestShortener = require("../lib/RequestShortener");
|
const RequestShortener = require("../lib/RequestShortener");
|
||||||
const should = require("should");
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const crypto = require("crypto");
|
const crypto = require("crypto");
|
||||||
|
|
||||||
describe("RawModule", () => {
|
describe("RawModule", () => {
|
||||||
let myRawModule;
|
|
||||||
|
|
||||||
before(() => {
|
|
||||||
const source = "sourceStr attribute";
|
const source = "sourceStr attribute";
|
||||||
const identifier = "identifierStr attribute";
|
const identifier = "identifierStr attribute";
|
||||||
const readableIdentifier = "readableIdentifierStr attribute";
|
const readableIdentifier = "readableIdentifierStr attribute";
|
||||||
myRawModule = new RawModule(source, identifier, readableIdentifier);
|
const myRawModule = new RawModule(source, identifier, readableIdentifier);
|
||||||
});
|
|
||||||
|
|
||||||
describe("identifier", () => {
|
describe("identifier", () => {
|
||||||
it("returns value for identifierStr attribute", () =>
|
it("returns value for identifierStr attribute", () => {
|
||||||
should(myRawModule.identifier()).be.exactly("identifierStr attribute"));
|
expect(myRawModule.identifier()).toBe("identifierStr attribute");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("size", () => {
|
describe("size", () => {
|
||||||
it("returns value for sourceStr attribute\"s length property", () => {
|
it("returns value for sourceStr attribute\"s length property", () => {
|
||||||
const sourceStrLength = myRawModule.sourceStr.length;
|
const sourceStrLength = myRawModule.sourceStr.length;
|
||||||
should(myRawModule.size()).be.exactly(sourceStrLength);
|
expect(myRawModule.size()).toBe(sourceStrLength);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -35,13 +31,15 @@ describe("RawModule", () => {
|
||||||
"on readableIdentifierStr attribute",
|
"on readableIdentifierStr attribute",
|
||||||
() => {
|
() => {
|
||||||
const requestShortener = new RequestShortener(path.resolve());
|
const requestShortener = new RequestShortener(path.resolve());
|
||||||
should.exist(myRawModule.readableIdentifier(requestShortener));
|
expect(myRawModule.readableIdentifier(requestShortener)).toBeDefined();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("needRebuild", () => {
|
describe("needRebuild", () => {
|
||||||
it("returns false", () => should(myRawModule.needRebuild()).be.false());
|
it("returns false", () => {
|
||||||
|
expect(myRawModule.needRebuild()).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("source", () => {
|
describe("source", () => {
|
||||||
|
@ -50,7 +48,7 @@ describe("RawModule", () => {
|
||||||
() => {
|
() => {
|
||||||
const originalSource = new OriginalSource(myRawModule.sourceStr, myRawModule.identifier());
|
const originalSource = new OriginalSource(myRawModule.sourceStr, myRawModule.identifier());
|
||||||
myRawModule.useSourceMap = true;
|
myRawModule.useSourceMap = true;
|
||||||
myRawModule.source().should.match(originalSource);
|
expect(myRawModule.source()).toEqual(originalSource);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -59,7 +57,7 @@ describe("RawModule", () => {
|
||||||
() => {
|
() => {
|
||||||
const rawSource = new RawSource(myRawModule.sourceStr);
|
const rawSource = new RawSource(myRawModule.sourceStr);
|
||||||
myRawModule.useSourceMap = false;
|
myRawModule.useSourceMap = false;
|
||||||
myRawModule.source().should.match(rawSource);
|
expect(myRawModule.source()).toEqual(rawSource);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -74,7 +72,7 @@ describe("RawModule", () => {
|
||||||
|
|
||||||
const hashFoo = hashModule(new RawModule("\"foo\""));
|
const hashFoo = hashModule(new RawModule("\"foo\""));
|
||||||
const hashBar = hashModule(new RawModule("\"bar\""));
|
const hashBar = hashModule(new RawModule("\"bar\""));
|
||||||
hashFoo.should.not.equal(hashBar);
|
expect(hashFoo).not.toBe(hashBar);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,18 +22,18 @@ function match(ruleSet, resource) {
|
||||||
describe("RuleSet", () => {
|
describe("RuleSet", () => {
|
||||||
it("should create RuleSet with a blank array", () => {
|
it("should create RuleSet with a blank array", () => {
|
||||||
const loader = new RuleSet([]);
|
const loader = new RuleSet([]);
|
||||||
(loader.rules).should.eql([]);
|
expect(loader.rules).toEqual([]);
|
||||||
});
|
});
|
||||||
it("should create RuleSet and match with empty array", () => {
|
it("should create RuleSet and match with empty array", () => {
|
||||||
const loader = new RuleSet([]);
|
const loader = new RuleSet([]);
|
||||||
(match(loader, "something")).should.eql([]);
|
expect(match(loader, "something")).toEqual([]);
|
||||||
});
|
});
|
||||||
it("should not match with loaders array", () => {
|
it("should not match with loaders array", () => {
|
||||||
const loader = new RuleSet([{
|
const loader = new RuleSet([{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "something")).should.eql([]);
|
expect(match(loader, "something")).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should match with regex", () => {
|
it("should match with regex", () => {
|
||||||
|
@ -41,7 +41,7 @@ describe("RuleSet", () => {
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should match with string", () => {
|
it("should match with string", () => {
|
||||||
|
@ -49,7 +49,7 @@ describe("RuleSet", () => {
|
||||||
test: "style.css",
|
test: "style.css",
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should match with function", () => {
|
it("should match with function", () => {
|
||||||
|
@ -59,19 +59,19 @@ describe("RuleSet", () => {
|
||||||
},
|
},
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw if invalid test", () => {
|
it("should throw if invalid test", () => {
|
||||||
should.throws(() => {
|
expect(() => {
|
||||||
const loader = new RuleSet([{
|
const loader = new RuleSet([{
|
||||||
test: {
|
test: {
|
||||||
invalid: "test"
|
invalid: "test"
|
||||||
},
|
},
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
match(loader, "style.css");
|
||||||
}, /Unexcepted property invalid in condition/);
|
}).toThrow(/Unexcepted property invalid in condition/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should accept multiple test array that all match", () => {
|
it("should accept multiple test array that all match", () => {
|
||||||
|
@ -82,7 +82,7 @@ describe("RuleSet", () => {
|
||||||
],
|
],
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should accept multiple test array that not all match", () => {
|
it("should accept multiple test array that not all match", () => {
|
||||||
|
@ -93,7 +93,7 @@ describe("RuleSet", () => {
|
||||||
],
|
],
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not match if include does not match", () => {
|
it("should not match if include does not match", () => {
|
||||||
|
@ -102,7 +102,7 @@ describe("RuleSet", () => {
|
||||||
include: /output.css/,
|
include: /output.css/,
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql([]);
|
expect(match(loader, "style.css")).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should match if include matches", () => {
|
it("should match if include matches", () => {
|
||||||
|
@ -111,7 +111,7 @@ describe("RuleSet", () => {
|
||||||
include: /style.css/,
|
include: /style.css/,
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not match if exclude matches", () => {
|
it("should not match if exclude matches", () => {
|
||||||
|
@ -120,7 +120,7 @@ describe("RuleSet", () => {
|
||||||
exclude: /style.css/,
|
exclude: /style.css/,
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql([]);
|
expect(match(loader, "style.css")).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should match if exclude does not match", () => {
|
it("should match if exclude does not match", () => {
|
||||||
|
@ -129,15 +129,15 @@ describe("RuleSet", () => {
|
||||||
exclude: /output.css/,
|
exclude: /output.css/,
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work if a loader is applied to all files", () => {
|
it("should work if a loader is applied to all files", () => {
|
||||||
const loader = new RuleSet([{
|
const loader = new RuleSet([{
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
(match(loader, "scripts.js")).should.eql(["css"]);
|
expect(match(loader, "scripts.js")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using loader as string", () => {
|
it("should work with using loader as string", () => {
|
||||||
|
@ -145,7 +145,7 @@ describe("RuleSet", () => {
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using loader as array", () => {
|
it("should work with using loader as array", () => {
|
||||||
|
@ -153,7 +153,7 @@ describe("RuleSet", () => {
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loader: ["css"]
|
loader: ["css"]
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using loaders as string", () => {
|
it("should work with using loaders as string", () => {
|
||||||
|
@ -161,7 +161,7 @@ describe("RuleSet", () => {
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loaders: "css"
|
loaders: "css"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using loaders as array", () => {
|
it("should work with using loaders as array", () => {
|
||||||
|
@ -169,19 +169,19 @@ describe("RuleSet", () => {
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loaders: ["css"]
|
loaders: ["css"]
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw if using loaders with non-string or array", () => {
|
it("should throw if using loaders with non-string or array", () => {
|
||||||
should.throws(function() {
|
expect(() => {
|
||||||
const loader = new RuleSet([{
|
const loader = new RuleSet([{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loaders: {
|
loaders: {
|
||||||
someObj: true
|
someObj: true
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
match(loader, "style.css");
|
||||||
}, /No loader specified/);
|
}).toThrow(/No loader specified/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using loader with inline query", () => {
|
it("should work with using loader with inline query", () => {
|
||||||
|
@ -189,7 +189,7 @@ describe("RuleSet", () => {
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loader: "css?modules=1"
|
loader: "css?modules=1"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css?modules=1"]);
|
expect(match(loader, "style.css")).toEqual(["css?modules=1"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using loader with string query", () => {
|
it("should work with using loader with string query", () => {
|
||||||
|
@ -198,7 +198,7 @@ describe("RuleSet", () => {
|
||||||
loader: "css",
|
loader: "css",
|
||||||
query: "modules=1"
|
query: "modules=1"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css?modules=1"]);
|
expect(match(loader, "style.css")).toEqual(["css?modules=1"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using loader with object query", () => {
|
it("should work with using loader with object query", () => {
|
||||||
|
@ -209,7 +209,7 @@ describe("RuleSet", () => {
|
||||||
modules: 1
|
modules: 1
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css?{\"modules\":1}"]);
|
expect(match(loader, "style.css")).toEqual(["css?{\"modules\":1}"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using array loaders with basic object notation", () => {
|
it("should work with using array loaders with basic object notation", () => {
|
||||||
|
@ -219,11 +219,11 @@ describe("RuleSet", () => {
|
||||||
loader: "css"
|
loader: "css"
|
||||||
}]
|
}]
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
expect(match(loader, "style.css")).toEqual(["css"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw if using array loaders with object notation without specifying a loader", () => {
|
it("should throw if using array loaders with object notation without specifying a loader", () => {
|
||||||
should.throws(() => {
|
expect(() => {
|
||||||
const loader = new RuleSet([{
|
const loader = new RuleSet([{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loaders: [{
|
loaders: [{
|
||||||
|
@ -231,7 +231,7 @@ describe("RuleSet", () => {
|
||||||
}]
|
}]
|
||||||
}]);
|
}]);
|
||||||
match(loader, "style.css");
|
match(loader, "style.css");
|
||||||
}, /No loader specified/);
|
}).toThrow(/No loader specified/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using array loaders with object notation", () => {
|
it("should work with using array loaders with object notation", () => {
|
||||||
|
@ -242,7 +242,7 @@ describe("RuleSet", () => {
|
||||||
query: "modules=1"
|
query: "modules=1"
|
||||||
}]
|
}]
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css?modules=1"]);
|
expect(match(loader, "style.css")).toEqual(["css?modules=1"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using multiple array loaders with object notation", () => {
|
it("should work with using multiple array loaders with object notation", () => {
|
||||||
|
@ -256,7 +256,7 @@ describe("RuleSet", () => {
|
||||||
query: "modules=1"
|
query: "modules=1"
|
||||||
}]
|
}]
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["style?filesize=1000", "css?modules=1"]);
|
expect(match(loader, "style.css")).toEqual(["style?filesize=1000", "css?modules=1"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with using string multiple loaders", () => {
|
it("should work with using string multiple loaders", () => {
|
||||||
|
@ -264,18 +264,18 @@ describe("RuleSet", () => {
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loaders: "style?filesize=1000!css?modules=1"
|
loaders: "style?filesize=1000!css?modules=1"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["style?filesize=1000", "css?modules=1"]);
|
expect(match(loader, "style.css")).toEqual(["style?filesize=1000", "css?modules=1"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw if using array loaders with a single legacy", () => {
|
it("should throw if using array loaders with a single legacy", () => {
|
||||||
should.throws(() => {
|
expect(() => {
|
||||||
const loader = new RuleSet([{
|
const loader = new RuleSet([{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loaders: ["style-loader", "css-loader"],
|
loaders: ["style-loader", "css-loader"],
|
||||||
query: "modules=1"
|
query: "modules=1"
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
match(loader, "style.css");
|
||||||
}, /options\/query cannot be used with loaders/);
|
}).toThrow(/options\/query cannot be used with loaders/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work when using array loaders", () => {
|
it("should work when using array loaders", () => {
|
||||||
|
@ -283,7 +283,7 @@ describe("RuleSet", () => {
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loaders: ["style-loader", "css-loader"]
|
loaders: ["style-loader", "css-loader"]
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["style-loader", "css-loader"]);
|
expect(match(loader, "style.css")).toEqual(["style-loader", "css-loader"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work when using an array of functions returning a loader", () => {
|
it("should work when using an array of functions returning a loader", () => {
|
||||||
|
@ -302,7 +302,7 @@ describe("RuleSet", () => {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["style-loader", "css-loader"]);
|
expect(match(loader, "style.css")).toEqual(["style-loader", "css-loader"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work when using an array of either functions or strings returning a loader", () => {
|
it("should work when using an array of either functions or strings returning a loader", () => {
|
||||||
|
@ -317,7 +317,7 @@ describe("RuleSet", () => {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["style-loader", "css-loader"]);
|
expect(match(loader, "style.css")).toEqual(["style-loader", "css-loader"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work when using an array of functions returning either a loader obejct or loader name string", () => {
|
it("should work when using an array of functions returning either a loader obejct or loader name string", () => {
|
||||||
|
@ -334,33 +334,31 @@ describe("RuleSet", () => {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["style-loader", "css-loader"]);
|
expect(match(loader, "style.css")).toEqual(["style-loader", "css-loader"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw if using array loaders with invalid type", () => {
|
it("should throw if using array loaders with invalid type", () => {
|
||||||
should.throws(() => {
|
expect(() => {
|
||||||
const loader = new RuleSet([{
|
const loader = new RuleSet([{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loaders: ["style-loader", "css-loader", 5],
|
loaders: ["style-loader", "css-loader", 5],
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
match(loader, "style.css");
|
||||||
}, /No loader specified/);
|
}).toThrow(/No loader specified/);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when exclude array holds an undefined item", () => {
|
describe("when exclude array holds an undefined item", () => {
|
||||||
function errorHasContext(err) {
|
function errorHasContext(err) {
|
||||||
if(/Expected condition but got falsy value/.test(err) &&
|
return /Expected condition but got falsy value/.test(err) &&
|
||||||
/test/.test(err) &&
|
/test/.test(err) &&
|
||||||
/include/.test(err) &&
|
/include/.test(err) &&
|
||||||
/exclude/.test(err) &&
|
/exclude/.test(err) &&
|
||||||
/node_modules/.test(err) &&
|
/node_modules/.test(err) &&
|
||||||
/undefined/.test(err)) {
|
/undefined/.test(err);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should throw with context", () => {
|
it("should throw with context", () => {
|
||||||
should.throws(() => {
|
try {
|
||||||
const loader = new RuleSet([{
|
const loader = new RuleSet([{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loader: "css",
|
loader: "css",
|
||||||
|
@ -372,11 +370,14 @@ describe("RuleSet", () => {
|
||||||
undefined,
|
undefined,
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
match(loader, "style.css");
|
||||||
}, errorHasContext);
|
throw new Error("unreachable");
|
||||||
|
} catch(e) {
|
||||||
|
expect(errorHasContext(e.message)).toBe(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
it("in resource should throw with context", () => {
|
it("in resource should throw with context", () => {
|
||||||
should.throws(() => {
|
try {
|
||||||
const loader = new RuleSet([{
|
const loader = new RuleSet([{
|
||||||
resource: {
|
resource: {
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
|
@ -389,12 +390,14 @@ describe("RuleSet", () => {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
match(loader, "style.css");
|
||||||
}, errorHasContext);
|
throw new Error("unreachable");
|
||||||
|
} catch(e) {
|
||||||
|
expect(errorHasContext(e.message)).toBe(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("in issuer should throw with context", () => {
|
it("in issuer should throw with context", () => {
|
||||||
should.throws(() => {
|
try {
|
||||||
const loader = new RuleSet([{
|
const loader = new RuleSet([{
|
||||||
issuer: {
|
issuer: {
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
|
@ -407,8 +410,11 @@ describe("RuleSet", () => {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}]);
|
}]);
|
||||||
(match(loader, "style.css")).should.eql(["css"]);
|
match(loader, "style.css");
|
||||||
}, errorHasContext);
|
throw new Error("unreachable");
|
||||||
|
} catch(e) {
|
||||||
|
expect(errorHasContext(e.message)).toBe(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,41 +1,40 @@
|
||||||
/* globals describe, it, beforeEach */
|
/* globals describe, it, beforeEach */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const should = require("should");
|
|
||||||
const SizeFormatHelpers = require("../lib/SizeFormatHelpers");
|
const SizeFormatHelpers = require("../lib/SizeFormatHelpers");
|
||||||
|
|
||||||
describe("SizeFormatHelpers", () => {
|
describe("SizeFormatHelpers", () => {
|
||||||
describe("formatSize", () => {
|
describe("formatSize", () => {
|
||||||
it("should handle zero size", () => {
|
it("should handle zero size", () => {
|
||||||
should(SizeFormatHelpers.formatSize(0)).be.eql("0 bytes");
|
expect(SizeFormatHelpers.formatSize(0)).toBe("0 bytes");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle bytes", () => {
|
it("should handle bytes", () => {
|
||||||
should(SizeFormatHelpers.formatSize(1000)).be.eql("1000 bytes");
|
expect(SizeFormatHelpers.formatSize(1000)).toBe("1000 bytes");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle integer kibibytes", () => {
|
it("should handle integer kibibytes", () => {
|
||||||
should(SizeFormatHelpers.formatSize(2048)).be.eql("2 KiB");
|
expect(SizeFormatHelpers.formatSize(2048)).toBe("2 KiB");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle float kibibytes", () => {
|
it("should handle float kibibytes", () => {
|
||||||
should(SizeFormatHelpers.formatSize(2560)).be.eql("2.5 KiB");
|
expect(SizeFormatHelpers.formatSize(2560)).toBe("2.5 KiB");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle integer mebibytes", () => {
|
it("should handle integer mebibytes", () => {
|
||||||
should(SizeFormatHelpers.formatSize(10 * 1024 * 1024)).be.eql("10 MiB");
|
expect(SizeFormatHelpers.formatSize(10 * 1024 * 1024)).toBe("10 MiB");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle float mebibytes", () => {
|
it("should handle float mebibytes", () => {
|
||||||
should(SizeFormatHelpers.formatSize(12.5 * 1024 * 1024)).be.eql("12.5 MiB");
|
expect(SizeFormatHelpers.formatSize(12.5 * 1024 * 1024)).toBe("12.5 MiB");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle integer gibibytes", () => {
|
it("should handle integer gibibytes", () => {
|
||||||
should(SizeFormatHelpers.formatSize(3 * 1024 * 1024 * 1024)).be.eql("3 GiB");
|
expect(SizeFormatHelpers.formatSize(3 * 1024 * 1024 * 1024)).toBe("3 GiB");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle float gibibytes", () => {
|
it("should handle float gibibytes", () => {
|
||||||
should(SizeFormatHelpers.formatSize(1.2 * 1024 * 1024 * 1024)).be.eql("1.2 GiB");
|
expect(SizeFormatHelpers.formatSize(1.2 * 1024 * 1024 * 1024)).toBe("1.2 GiB");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,7 +6,7 @@ const SortableSet = require("../lib/util/SortableSet");
|
||||||
describe("util/SortableSet", () => {
|
describe("util/SortableSet", () => {
|
||||||
it("Can be constructed like a normal Set", () => {
|
it("Can be constructed like a normal Set", () => {
|
||||||
const sortableSet = new SortableSet([1, 1, 1, 1, 1, 4, 5, 2], () => {});
|
const sortableSet = new SortableSet([1, 1, 1, 1, 1, 4, 5, 2], () => {});
|
||||||
Array.from(sortableSet).should.eql([1, 4, 5, 2]);
|
expect(Array.from(sortableSet)).toEqual([1, 4, 5, 2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Can sort its content", () => {
|
it("Can sort its content", () => {
|
||||||
|
@ -15,7 +15,7 @@ describe("util/SortableSet", () => {
|
||||||
(a, b) => a - b
|
(a, b) => a - b
|
||||||
);
|
);
|
||||||
sortableSet.sort();
|
sortableSet.sort();
|
||||||
Array.from(sortableSet).should.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
expect(Array.from(sortableSet)).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Can sort by a specified function", () => {
|
it("Can sort by a specified function", () => {
|
||||||
|
@ -24,6 +24,6 @@ describe("util/SortableSet", () => {
|
||||||
(a, b) => a - b
|
(a, b) => a - b
|
||||||
);
|
);
|
||||||
sortableSet.sortWith((a, b) => b - a);
|
sortableSet.sortWith((a, b) => b - a);
|
||||||
Array.from(sortableSet).should.eql([9, 8, 7, 6, 5, 4, 3, 2, 1, 0]);
|
expect(Array.from(sortableSet)).toEqual([9, 8, 7, 6, 5, 4, 3, 2, 1, 0]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("should");
|
|
||||||
const SourceMapDevToolModuleOptionsPlugin = require("../lib/SourceMapDevToolModuleOptionsPlugin");
|
const SourceMapDevToolModuleOptionsPlugin = require("../lib/SourceMapDevToolModuleOptionsPlugin");
|
||||||
const applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
|
const applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
|
||||||
|
|
||||||
|
@ -8,35 +7,44 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => {
|
||||||
describe("when applied", () => {
|
describe("when applied", () => {
|
||||||
let eventBindings;
|
let eventBindings;
|
||||||
|
|
||||||
beforeEach(() => eventBindings = undefined);
|
beforeEach(() => {
|
||||||
|
eventBindings = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
describe("with module false and line-to-line false", () => {
|
describe("with module false and line-to-line false", () => {
|
||||||
beforeEach(() =>
|
beforeEach(() => {
|
||||||
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
|
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
|
||||||
module: false,
|
module: false,
|
||||||
lineToLine: false
|
lineToLine: false
|
||||||
}));
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("does not bind any event handlers", () => eventBindings.length.should.be.exactly(0));
|
it("does not bind any event handlers", () => {
|
||||||
|
expect(eventBindings.length).toBe(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("with module true", () => {
|
describe("with module true", () => {
|
||||||
beforeEach(() =>
|
beforeEach(() => {
|
||||||
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
|
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
|
||||||
module: true,
|
module: true,
|
||||||
lineToLine: false
|
lineToLine: false
|
||||||
}));
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("binds one event handler", () => eventBindings.length.should.be.exactly(1));
|
it("binds one event handler", () => {
|
||||||
|
expect(eventBindings.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
describe("event handler", () => {
|
describe("event handler", () => {
|
||||||
it("binds to build-module event", () =>
|
it("binds to build-module event", () => {
|
||||||
eventBindings[0].name.should.be.exactly("build-module"));
|
expect(eventBindings[0].name).toBe("build-module");
|
||||||
|
});
|
||||||
|
|
||||||
it("sets source map flag", () => {
|
it("sets source map flag", () => {
|
||||||
const module = {};
|
const module = {};
|
||||||
eventBindings[0].handler(module);
|
eventBindings[0].handler(module);
|
||||||
module.should.deepEqual({
|
expect(module).toEqual({
|
||||||
useSourceMap: true
|
useSourceMap: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -50,15 +58,19 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => {
|
||||||
lineToLine: true
|
lineToLine: true
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("binds one event handler", () => eventBindings.length.should.be.exactly(1));
|
it("binds one event handler", () => {
|
||||||
|
expect(eventBindings.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
describe("event handler", () => {
|
describe("event handler", () => {
|
||||||
it("binds to build-module event", () => eventBindings[0].name.should.be.exactly("build-module"));
|
it("binds to build-module event", () => {
|
||||||
|
expect(eventBindings[0].name).toBe("build-module");
|
||||||
|
});
|
||||||
|
|
||||||
it("sets line-to-line flag", () => {
|
it("sets line-to-line flag", () => {
|
||||||
const module = {};
|
const module = {};
|
||||||
eventBindings[0].handler(module);
|
eventBindings[0].handler(module);
|
||||||
module.should.deepEqual({
|
expect(module).toEqual({
|
||||||
lineToLine: true
|
lineToLine: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -66,22 +78,27 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("with line-to-line object", () => {
|
describe("with line-to-line object", () => {
|
||||||
beforeEach(() =>
|
beforeEach(() => {
|
||||||
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
|
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
|
||||||
module: false,
|
module: false,
|
||||||
lineToLine: {}
|
lineToLine: {}
|
||||||
}));
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("binds one event handler", () => eventBindings.length.should.be.exactly(1));
|
it("binds one event handler", () => {
|
||||||
|
expect(eventBindings.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
describe("event handler", () => {
|
describe("event handler", () => {
|
||||||
it("binds to build-module event", () => eventBindings[0].name.should.be.exactly("build-module"));
|
it("binds to build-module event", () => {
|
||||||
|
expect(eventBindings[0].name).toBe("build-module");
|
||||||
|
});
|
||||||
|
|
||||||
describe("when module has no resource", () => {
|
describe("when module has no resource", () => {
|
||||||
it("makes no changes", () => {
|
it("makes no changes", () => {
|
||||||
const module = {};
|
const module = {};
|
||||||
eventBindings[0].handler(module);
|
eventBindings[0].handler(module);
|
||||||
module.should.deepEqual({});
|
expect(module).toEqual({});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -91,7 +108,7 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => {
|
||||||
resource: "foo"
|
resource: "foo"
|
||||||
};
|
};
|
||||||
eventBindings[0].handler(module);
|
eventBindings[0].handler(module);
|
||||||
module.should.deepEqual({
|
expect(module).toEqual({
|
||||||
lineToLine: true,
|
lineToLine: true,
|
||||||
resource: "foo"
|
resource: "foo"
|
||||||
});
|
});
|
||||||
|
@ -104,7 +121,7 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => {
|
||||||
resource: "foo?bar"
|
resource: "foo?bar"
|
||||||
};
|
};
|
||||||
eventBindings[0].handler(module);
|
eventBindings[0].handler(module);
|
||||||
module.should.deepEqual({
|
expect(module).toEqual({
|
||||||
lineToLine: true,
|
lineToLine: true,
|
||||||
resource: "foo?bar"
|
resource: "foo?bar"
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
/*globals describe it */
|
/*globals describe it */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("should");
|
|
||||||
|
|
||||||
const Stats = require("../lib/Stats");
|
const Stats = require("../lib/Stats");
|
||||||
|
|
||||||
describe("Stats", () => {
|
describe("Stats", () => {
|
||||||
|
@ -17,7 +15,7 @@ describe("Stats", () => {
|
||||||
context: ""
|
context: ""
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mockStats.hasErrors().should.be.ok();
|
expect(mockStats.hasErrors()).toBe(true);
|
||||||
});
|
});
|
||||||
it("hasWarnings", () => {
|
it("hasWarnings", () => {
|
||||||
const mockStats = new Stats({
|
const mockStats = new Stats({
|
||||||
|
@ -28,7 +26,7 @@ describe("Stats", () => {
|
||||||
context: ""
|
context: ""
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mockStats.hasWarnings().should.be.ok();
|
expect(mockStats.hasWarnings()).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("does not have", () => {
|
describe("does not have", () => {
|
||||||
|
@ -41,7 +39,7 @@ describe("Stats", () => {
|
||||||
context: ""
|
context: ""
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mockStats.hasErrors().should.not.be.ok();
|
expect(mockStats.hasErrors()).toBe(false);
|
||||||
});
|
});
|
||||||
it("hasWarnings", () => {
|
it("hasWarnings", () => {
|
||||||
const mockStats = new Stats({
|
const mockStats = new Stats({
|
||||||
|
@ -52,7 +50,7 @@ describe("Stats", () => {
|
||||||
context: ""
|
context: ""
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mockStats.hasWarnings().should.not.be.ok();
|
expect(mockStats.hasWarnings()).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("children have", () => {
|
describe("children have", () => {
|
||||||
|
@ -67,7 +65,7 @@ describe("Stats", () => {
|
||||||
errors: [],
|
errors: [],
|
||||||
hash: "1234"
|
hash: "1234"
|
||||||
});
|
});
|
||||||
mockStats.hasErrors().should.be.ok();
|
expect(mockStats.hasErrors()).toBe(true);
|
||||||
});
|
});
|
||||||
it("hasWarnings", () => {
|
it("hasWarnings", () => {
|
||||||
const mockStats = new Stats({
|
const mockStats = new Stats({
|
||||||
|
@ -80,7 +78,7 @@ describe("Stats", () => {
|
||||||
warnings: [],
|
warnings: [],
|
||||||
hash: "1234"
|
hash: "1234"
|
||||||
});
|
});
|
||||||
mockStats.hasWarnings().should.be.ok();
|
expect(mockStats.hasWarnings()).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("formatError handles string errors", () => {
|
it("formatError handles string errors", () => {
|
||||||
|
@ -101,35 +99,35 @@ describe("Stats", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const obj = mockStats.toJson();
|
const obj = mockStats.toJson();
|
||||||
obj.errors[0].should.be.equal("firstError");
|
expect(obj.errors[0]).toEqual("firstError");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("Presets", () => {
|
describe("Presets", () => {
|
||||||
describe("presetToOptions", () => {
|
describe("presetToOptions", () => {
|
||||||
it("returns correct object with 'Normal'", () => {
|
it("returns correct object with 'Normal'", () => {
|
||||||
Stats.presetToOptions("Normal").should.eql({});
|
expect(Stats.presetToOptions("Normal")).toEqual({});
|
||||||
});
|
});
|
||||||
it("truthy values behave as 'normal'", () => {
|
it("truthy values behave as 'normal'", () => {
|
||||||
const normalOpts = Stats.presetToOptions("normal");
|
const normalOpts = Stats.presetToOptions("normal");
|
||||||
Stats.presetToOptions("pizza").should.eql(normalOpts);
|
expect(Stats.presetToOptions("pizza")).toEqual(normalOpts);
|
||||||
Stats.presetToOptions(true).should.eql(normalOpts);
|
expect(Stats.presetToOptions(true)).toEqual(normalOpts);
|
||||||
Stats.presetToOptions(1).should.eql(normalOpts);
|
expect(Stats.presetToOptions(1)).toEqual(normalOpts);
|
||||||
|
|
||||||
Stats.presetToOptions("verbose").should.not.eql(normalOpts);
|
expect(Stats.presetToOptions("verbose")).not.toEqual(normalOpts);
|
||||||
Stats.presetToOptions(false).should.not.eql(normalOpts);
|
expect(Stats.presetToOptions(false)).not.toEqual(normalOpts);
|
||||||
});
|
});
|
||||||
it("returns correct object with 'none'", () => {
|
it("returns correct object with 'none'", () => {
|
||||||
Stats.presetToOptions("none").should.eql({
|
expect(Stats.presetToOptions("none")).toEqual({
|
||||||
all: false
|
all: false
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("falsy values behave as 'none'", () => {
|
it("falsy values behave as 'none'", () => {
|
||||||
const noneOpts = Stats.presetToOptions("none");
|
const noneOpts = Stats.presetToOptions("none");
|
||||||
Stats.presetToOptions("").should.eql(noneOpts);
|
expect(Stats.presetToOptions("")).toEqual(noneOpts);
|
||||||
Stats.presetToOptions(null).should.eql(noneOpts);
|
expect(Stats.presetToOptions(null)).toEqual(noneOpts);
|
||||||
Stats.presetToOptions().should.eql(noneOpts);
|
expect(Stats.presetToOptions()).toEqual(noneOpts);
|
||||||
Stats.presetToOptions(0).should.eql(noneOpts);
|
expect(Stats.presetToOptions(0)).toEqual(noneOpts);
|
||||||
Stats.presetToOptions(false).should.eql(noneOpts);
|
expect(Stats.presetToOptions(false)).toEqual(noneOpts);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,27 +1,22 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("should");
|
|
||||||
|
|
||||||
const Template = require("../lib/Template");
|
const Template = require("../lib/Template");
|
||||||
|
|
||||||
describe("Template", () => {
|
describe("Template", () => {
|
||||||
it("should generate valid identifiers", () =>
|
it("should generate valid identifiers", () => {
|
||||||
Template.toIdentifier("0abc-def9").should.equal("_0abc_def9"));
|
expect(Template.toIdentifier("0abc-def9")).toBe("_0abc_def9");
|
||||||
|
});
|
||||||
it("should generate valid number identifiers", () => {
|
it("should generate valid number identifiers", () => {
|
||||||
const items = [];
|
const items = [];
|
||||||
let item;
|
let item;
|
||||||
for(let i = 0; i < 80; i += 1) {
|
for(let i = 0; i < 80; i += 1) {
|
||||||
item = Template.numberToIdentifer(i);
|
item = Template.numberToIdentifer(i);
|
||||||
if(item === "") {
|
expect(item).not.toBe("");
|
||||||
throw new Error("empty number identifier");
|
expect(items).not.toContain(item);
|
||||||
} else if(items.indexOf(item) > -1) {
|
|
||||||
throw new Error("duplicate number identifier");
|
|
||||||
} else {
|
|
||||||
items.push(item);
|
items.push(item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
it("should generate sanitized path identifiers", () => {
|
it("should generate sanitized path identifiers", () => {
|
||||||
Template.toPath("path/to-sdfas/sadfome$$.js").should.equal("path-to-sdfas-sadfome$$-js");
|
expect(Template.toPath("path/to-sdfas/sadfome$$.js")).toBe("path-to-sdfas-sadfome$$-js");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,23 +1,18 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const should = require("should");
|
|
||||||
const WebEnvironmentPlugin = require("../lib/web/WebEnvironmentPlugin");
|
const WebEnvironmentPlugin = require("../lib/web/WebEnvironmentPlugin");
|
||||||
|
|
||||||
describe("WebEnvironmentPlugin", () => {
|
describe("WebEnvironmentPlugin", () => {
|
||||||
let WebEnvironmentPluginInstance;
|
|
||||||
|
|
||||||
before(() => WebEnvironmentPluginInstance = new WebEnvironmentPlugin("inputFileSystem", "outputFileSystem"));
|
|
||||||
|
|
||||||
describe("apply", () => {
|
describe("apply", () => {
|
||||||
let compileSpy;
|
const WebEnvironmentPluginInstance = new WebEnvironmentPlugin("inputFileSystem", "outputFileSystem");
|
||||||
before(() => {
|
const compileSpy = {
|
||||||
compileSpy = {
|
|
||||||
outputFileSystem: "otherOutputFileSystem"
|
outputFileSystem: "otherOutputFileSystem"
|
||||||
};
|
};
|
||||||
WebEnvironmentPluginInstance.apply(compileSpy);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should set compiler.outputFileSystem information with the same as setted in WebEnvironmentPlugin", () =>
|
WebEnvironmentPluginInstance.apply(compileSpy);
|
||||||
should(compileSpy.outputFileSystem).be.eql(WebEnvironmentPluginInstance.outputFileSystem));
|
|
||||||
|
it("should set compiler.outputFileSystem information with the same as setted in WebEnvironmentPlugin", () => {
|
||||||
|
expect(compileSpy.outputFileSystem).toBe(WebEnvironmentPluginInstance.outputFileSystem);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const path = require("path");
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
|
|
||||||
require("should");
|
|
||||||
const WebpackError = require("../lib/WebpackError");
|
const WebpackError = require("../lib/WebpackError");
|
||||||
|
|
||||||
describe("WebpackError", () => {
|
describe("WebpackError", () => {
|
||||||
|
@ -18,12 +18,12 @@ describe("WebpackError", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
it("Should provide inspect method for use by for util.inspect", function() {
|
it("Should provide inspect method for use by for util.inspect", () => {
|
||||||
const errorStr = util.inspect(new CustomError("Message"));
|
const errorStr = util.inspect(new CustomError("Message"));
|
||||||
const errorArr = errorStr.split("\n");
|
const errorArr = errorStr.split("\n");
|
||||||
|
|
||||||
errorArr[0].should.equal("CustomError: CustomMessage");
|
expect(errorArr[0]).toBe("CustomError: CustomMessage");
|
||||||
errorArr[1].should.containEql("WebpackError.unittest.js");
|
expect(errorArr[1]).toMatch(path.basename(__filename));
|
||||||
errorArr[errorArr.length - 1].should.equal("CustomDetails");
|
expect(errorArr[errorArr.length - 1]).toBe("CustomDetails");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,28 +1,27 @@
|
||||||
/* globals describe, it */
|
/* globals describe, it */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const should = require("should");
|
|
||||||
const WebpackMissingModule = require("../lib/dependencies/WebpackMissingModule");
|
const WebpackMissingModule = require("../lib/dependencies/WebpackMissingModule");
|
||||||
|
|
||||||
describe("WebpackMissingModule", () => {
|
describe("WebpackMissingModule", () => {
|
||||||
describe("#moduleCode", () => {
|
describe("#moduleCode", () => {
|
||||||
it("returns an error message based on given error message", () => {
|
it("returns an error message based on given error message", () => {
|
||||||
const errorMessage = WebpackMissingModule.moduleCode("mock message");
|
const errorMessage = WebpackMissingModule.moduleCode("mock message");
|
||||||
should(errorMessage).be.eql("var e = new Error(\"Cannot find module \\\"mock message\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e;");
|
expect(errorMessage).toBe("var e = new Error(\"Cannot find module \\\"mock message\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e;");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#promise", () => {
|
describe("#promise", () => {
|
||||||
it("returns an error message based on given error message", () => {
|
it("returns an error message based on given error message", () => {
|
||||||
const errorMessage = WebpackMissingModule.promise("mock message");
|
const errorMessage = WebpackMissingModule.promise("mock message");
|
||||||
should(errorMessage).be.eql("Promise.reject(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"mock message\\\"\"); e.code = 'MODULE_NOT_FOUND'; return e; }())");
|
expect(errorMessage).toBe("Promise.reject(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"mock message\\\"\"); e.code = 'MODULE_NOT_FOUND'; return e; }())");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#module", () => {
|
describe("#module", () => {
|
||||||
it("returns an error message based on given error message", () => {
|
it("returns an error message based on given error message", () => {
|
||||||
const errorMessage = WebpackMissingModule.module("mock message");
|
const errorMessage = WebpackMissingModule.module("mock message");
|
||||||
should(errorMessage).be.eql("!(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"mock message\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())");
|
expect(errorMessage).toBe("!(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"mock message\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const should = require("should");
|
|
||||||
const compareLocations = require("../lib/compareLocations");
|
const compareLocations = require("../lib/compareLocations");
|
||||||
const createPosition = function(overides) {
|
const createPosition = (overides) => {
|
||||||
return Object.assign({
|
return Object.assign({
|
||||||
line: 10,
|
line: 10,
|
||||||
column: 5
|
column: 5
|
||||||
}, overides);
|
}, overides);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createLocation = function(start, end, index) {
|
const createLocation = (start, end, index) => {
|
||||||
return {
|
return {
|
||||||
start: createPosition(start),
|
start: createPosition(start),
|
||||||
end: createPosition(end),
|
end: createPosition(end),
|
||||||
|
@ -19,14 +18,17 @@ const createLocation = function(start, end, index) {
|
||||||
|
|
||||||
describe("compareLocations", () => {
|
describe("compareLocations", () => {
|
||||||
describe("string location comparison", () => {
|
describe("string location comparison", () => {
|
||||||
it("returns -1 when the first string comes before the second string", () =>
|
it("returns -1 when the first string comes before the second string", () => {
|
||||||
compareLocations("alpha", "beta").should.be.exactly(-1));
|
expect(compareLocations("alpha", "beta")).toBe(-1);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns 1 when the first string comes after the second string", () =>
|
it("returns 1 when the first string comes after the second string", () => {
|
||||||
compareLocations("beta", "alpha").should.be.exactly(1));
|
expect(compareLocations("beta", "alpha")).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns 0 when the first string is the same as the second string", () =>
|
it("returns 0 when the first string is the same as the second string", () => {
|
||||||
compareLocations("charlie", "charlie").should.be.exactly(0));
|
expect(compareLocations("charlie", "charlie")).toBe(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("object location comparison", () => {
|
describe("object location comparison", () => {
|
||||||
|
@ -43,11 +45,12 @@ describe("compareLocations", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns -1 when the first location line number comes before the second location line number", () => {
|
it("returns -1 when the first location line number comes before the second location line number", () => {
|
||||||
return compareLocations(a, b).should.be.exactly(-1);
|
expect(compareLocations(a, b)).toBe(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns 1 when the first location line number comes after the second location line number", () =>
|
it("returns 1 when the first location line number comes after the second location line number", () => {
|
||||||
compareLocations(b, a).should.be.exactly(1));
|
expect(compareLocations(b, a)).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("location column number", () => {
|
describe("location column number", () => {
|
||||||
|
@ -60,11 +63,13 @@ describe("compareLocations", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns -1 when the first location column number comes before the second location column number", () =>
|
it("returns -1 when the first location column number comes before the second location column number", () => {
|
||||||
compareLocations(a, b).should.be.exactly(-1));
|
expect(compareLocations(a, b)).toBe(-1);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns 1 when the first location column number comes after the second location column number", () =>
|
it("returns 1 when the first location column number comes after the second location column number", () => {
|
||||||
compareLocations(b, a).should.be.exactly(1));
|
expect(compareLocations(b, a)).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("location index number", () => {
|
describe("location index number", () => {
|
||||||
|
@ -73,11 +78,13 @@ describe("compareLocations", () => {
|
||||||
b = createLocation(null, null, 20);
|
b = createLocation(null, null, 20);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns -1 when the first location index number comes before the second location index number", () =>
|
it("returns -1 when the first location index number comes before the second location index number", () => {
|
||||||
compareLocations(a, b).should.be.exactly(-1));
|
expect(compareLocations(a, b)).toBe(-1);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns 1 when the first location index number comes after the second location index number", () =>
|
it("returns 1 when the first location index number comes after the second location index number", () => {
|
||||||
compareLocations(b, a).should.be.exactly(1));
|
expect(compareLocations(b, a)).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("same location", () => {
|
describe("same location", () => {
|
||||||
|
@ -87,34 +94,40 @@ describe("compareLocations", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns 0", () => {
|
it("returns 0", () => {
|
||||||
compareLocations(a, b).should.be.exactly(0);
|
expect(compareLocations(a, b)).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("string and object location comparison", () => {
|
describe("string and object location comparison", () => {
|
||||||
it("returns 1 when the first parameter is a string and the second parameter is an object", () =>
|
it("returns 1 when the first parameter is a string and the second parameter is an object", () => {
|
||||||
compareLocations("alpha", createLocation()).should.be.exactly(1));
|
expect(compareLocations("alpha", createLocation())).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns -1 when the first parameter is an object and the second parameter is a string", () =>
|
it("returns -1 when the first parameter is an object and the second parameter is a string", () => {
|
||||||
compareLocations(createLocation(), "alpha").should.be.exactly(-1));
|
expect(compareLocations(createLocation(), "alpha")).toBe(-1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("unknown location type comparison", () => {
|
describe("unknown location type comparison", () => {
|
||||||
it("returns 0 when the first parameter is an object and the second parameter is a number", () =>
|
it("returns 0 when the first parameter is an object and the second parameter is a number", () => {
|
||||||
compareLocations(createLocation(), 123).should.be.exactly(0));
|
expect(compareLocations(createLocation(), 123)).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns undefined when the first parameter is a number and the second parameter is an object", () =>
|
it("returns undefined when the first parameter is a number and the second parameter is an object", () => {
|
||||||
should(compareLocations(123, createLocation())).be.undefined());
|
expect(compareLocations(123, createLocation())).toBe(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns 0 when the first parameter is a string and the second parameter is a number", () =>
|
it("returns 0 when the first parameter is a string and the second parameter is a number", () => {
|
||||||
compareLocations("alpha", 123).should.be.exactly(0));
|
expect(compareLocations("alpha", 123)).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns undefined when the first parameter is a number and the second parameter is a string", () =>
|
it("returns undefined when the first parameter is a number and the second parameter is a string", () => {
|
||||||
should(compareLocations(123, "alpha")).be.undefined());
|
expect(compareLocations(123, "alpha")).toBe(undefined);
|
||||||
|
});
|
||||||
it("returns undefined when both the first parameter and the second parameter is a number", () =>
|
|
||||||
should(compareLocations(123, 456)).be.undefined());
|
|
||||||
|
|
||||||
|
it("returns undefined when both the first parameter and the second parameter is a number", () => {
|
||||||
|
expect(compareLocations(123, 456)).toBe(undefined);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("should");
|
|
||||||
const formatLocation = require("../lib/formatLocation");
|
const formatLocation = require("../lib/formatLocation");
|
||||||
|
|
||||||
describe("formatLocation", () => {
|
describe("formatLocation", () => {
|
||||||
|
@ -90,7 +89,7 @@ describe("formatLocation", () => {
|
||||||
}];
|
}];
|
||||||
testCases.forEach(testCase => {
|
testCases.forEach(testCase => {
|
||||||
it(`should format location correctly for ${testCase.name}`, () => {
|
it(`should format location correctly for ${testCase.name}`, () => {
|
||||||
formatLocation(testCase.loc).should.be.eql(testCase.result);
|
expect(formatLocation(testCase.loc)).toEqual(testCase.result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
/* globals describe, beforeEach, it */
|
/* globals describe, beforeEach, it */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const should = require("should");
|
|
||||||
|
|
||||||
const identifierUtil = require("../lib/util/identifier");
|
const identifierUtil = require("../lib/util/identifier");
|
||||||
|
|
||||||
describe("util/identifier", () => {
|
describe("util/identifier", () => {
|
||||||
|
@ -16,7 +14,7 @@ describe("util/identifier", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("computes the correct relative results for the path construct", () => {
|
it("computes the correct relative results for the path construct", () => {
|
||||||
should(identifierUtil.makePathsRelative(context, pathConstruct)).be.exactly(expected);
|
expect(identifierUtil.makePathsRelative(context, pathConstruct)).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
/* globals describe it */
|
/* globals describe it */
|
||||||
|
|
||||||
require("should");
|
|
||||||
|
|
||||||
var objectToMap = require("../lib/util/objectToMap");
|
var objectToMap = require("../lib/util/objectToMap");
|
||||||
|
|
||||||
describe("objectToMap", function() {
|
describe("objectToMap", () => {
|
||||||
it("should convert a plain object into a Map successfully", function() {
|
it("should convert a plain object into a Map successfully", () => {
|
||||||
const map = objectToMap({
|
const map = objectToMap({
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
bar: "baz"
|
bar: "baz"
|
||||||
});
|
});
|
||||||
|
|
||||||
map.get("foo").should.eql("bar");
|
expect(map.get("foo")).toBe("bar");
|
||||||
map.get("bar").should.eql("baz");
|
expect(map.get("bar")).toBe("baz");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue