Migrate unit tests to Jest

This commit is contained in:
Florent Cailhol 2018-01-24 13:17:21 +01:00
parent 02f8c96925
commit 2f4910b4c3
34 changed files with 1984 additions and 951 deletions

View File

@ -43,6 +43,7 @@
"istanbul": "^0.4.5",
"jade": "^1.11.0",
"jade-loader": "~0.8.0",
"jest": "^22.1.4",
"js-beautify": "^1.5.10",
"json-loader": "^0.5.7",
"less": "^2.5.1",
@ -86,9 +87,9 @@
"schemas/"
],
"scripts": {
"test": "mocha test/*.test.js test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation",
"test:integration": "mocha test/*.test.js --max-old-space-size=4096 --harmony --trace-deprecation",
"test:unit": "mocha test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation",
"test": "jest",
"test:integration": "jest --testMatch '<rootDir>/test/*.test.js'",
"test:unit": "jest --testMatch '<rootDir>/test/*.unittest.js'",
"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:lint": "npm run lint-files",
@ -114,5 +115,8 @@
"cover:report": "istanbul report",
"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"
},
"jest": {
"testEnvironment": "node"
}
}

View File

@ -1,6 +1,5 @@
"use strict";
require("should");
const CachePlugin = require("../lib/CachePlugin");
describe("CachePlugin", () => {
@ -16,26 +15,28 @@ describe("CachePlugin", () => {
});
describe("applyMtime", () => {
beforeEach(() => env.plugin = new CachePlugin());
beforeEach(() => {
env.plugin = new CachePlugin();
});
it("sets file system accuracy to 1 for granular modification timestamp", () => {
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", () => {
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", () => {
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", () => {
env.plugin.applyMtime(1483819067400);
env.plugin.FS_ACCURENCY.should.be.exactly(1000);
expect(env.plugin.FS_ACCURENCY).toBe(1000);
});
});
});

View File

@ -1,9 +1,8 @@
"use strict";
require("should");
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) => {
return {
module: createModule(`${identifier}-reason-${index}`)
@ -29,10 +28,12 @@ describe("CaseSensitiveModulesWarning", () => {
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", () => {
myCaseSensitiveModulesWarning.message.should.be.exactly(`
expect(myCaseSensitiveModulesWarning.message).toBe(`
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.
Use equal casing. Compare these module identifiers:
@ -46,9 +47,11 @@ Use equal casing. Compare these module identifiers:
`.trim());
});
it("has the an origin", () =>
myCaseSensitiveModulesWarning.origin.should.be.exactly(modules[0]));
it("has the an origin", () => {
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]);
});
});

View File

@ -1,99 +1,114 @@
/* globals describe, it, beforeEach */
"use strict";
const should = require("should");
const sinon = require("sinon");
const Chunk = require("../lib/Chunk");
describe("Chunk", () => {
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", () => {
it("returns an error if get entry", () =>
should(() => {
it("returns an error if get entry", () => {
expect(() => {
ChunkInstance.entry;
}).throw("Chunk.entry was removed. Use hasRuntime()"));
}).toThrow("Chunk.entry was removed. Use hasRuntime()");
});
it("returns an error if set an entry", () =>
should(() => {
it("returns an error if set an entry", () => {
expect(() => {
ChunkInstance.entry = 10;
}).throw("Chunk.entry was removed. Use hasRuntime()"));
}).toThrow("Chunk.entry was removed. Use hasRuntime()");
});
});
describe("initial", () => {
it("returns an error if get initial", () =>
should(() => {
it("returns an error if get initial", () => {
expect(() => {
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", () =>
should(() => {
it("returns an error if set an initial", () => {
expect(() => {
ChunkInstance.initial = 10;
}).throw("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()"));
}).toThrow("Chunk.initial was removed. Use canBeInitial/isOnlyInitial()");
});
});
describe("hasRuntime", () => {
it("returns false", () => should(ChunkInstance.hasRuntime()).be.false());
it("returns false", () => {
expect(ChunkInstance.hasRuntime()).toBe(false);
});
});
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", () => {
it("should NOT have any module by default", () =>
should(ChunkInstance.size({
it("should NOT have any module by default", () => {
expect(ChunkInstance.size({
chunkOverhead: 10,
entryChunkMultiplicator: 2
})).be.exactly(10));
})).toBe(10);
});
});
describe("removeModule", function() {
describe("removeModule", () => {
let module;
let removeChunkSpy;
beforeEach(function() {
beforeEach(() => {
removeChunkSpy = sinon.spy();
module = {
removeChunk: removeChunkSpy
};
});
describe("and the chunk does not contain this module", function() {
it("returns false", function() {
ChunkInstance.removeModule(module).should.eql(false);
describe("and the chunk does not contain this module", () => {
it("returns false", () => {
expect(ChunkInstance.removeModule(module)).toBe(false);
});
});
describe("and the chunk does contain this module", function() {
beforeEach(function() {
describe("and the chunk does contain this module", () => {
beforeEach(() => {
ChunkInstance._modules = new Set([module]);
});
it("calls module.removeChunk with itself and returns true", function() {
ChunkInstance.removeModule(module).should.eql(true);
it("calls module.removeChunk with itself and returns true", () => {
expect(ChunkInstance.removeModule(module)).toBe(true);
removeChunkSpy.callCount.should.eql(1);
removeChunkSpy.args[0][0].should.eql(ChunkInstance);
expect(removeChunkSpy.callCount).toBe(1);
expect(removeChunkSpy.args[0][0]).toBe(ChunkInstance);
});
});
describe("getNumberOfGroups", function() {
beforeEach(function() {
describe("getNumberOfGroups", () => {
beforeEach(() => {
ChunkInstance._groups = new Set();
});
it("should return the number of chunk groups contained by the chunk", function() {
ChunkInstance.getNumberOfGroups().should.eql(0);
it("should return the number of chunk groups contained by the chunk", () => {
expect(ChunkInstance.getNumberOfGroups()).toBe(0);
});
});
});

View File

@ -1,17 +1,17 @@
/* globals describe, it, beforeEach */
"use strict";
require("should");
const MemoryFs = require("memory-fs");
const ContextModuleFactory = require("../lib/ContextModuleFactory");
describe("ContextModuleFactory", function() {
describe("resolveDependencies", function() {
describe("ContextModuleFactory", () => {
describe("resolveDependencies", () => {
let factory, memfs;
beforeEach(function() {
beforeEach(() => {
factory = new ContextModuleFactory([]);
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) => {
setTimeout(() => callback(null, ["/file"]));
};
@ -25,13 +25,13 @@ describe("ContextModuleFactory", function() {
recursive: true,
regExp: /.*/
}, (err, res) => {
(!!err).should.be.false();
res.should.be.an.Array();
res.length.should.be.exactly(0);
expect(err).toBeFalsy();
expect(Array.isArray(res)).toBe(true);
expect(res.length).toBe(0);
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) => {
setTimeout(() => callback(null, ["/file"]));
};
@ -45,8 +45,8 @@ describe("ContextModuleFactory", function() {
recursive: true,
regExp: /.*/
}, (err, res) => {
err.should.be.an.Error();
(!!res).should.be.false();
expect(err).toBeInstanceOf(Error);
expect(res).toBeFalsy();
done();
});
});

View File

@ -1,10 +1,10 @@
/* globals describe, it, beforeEach */
"use strict";
require("should");
const DelegatedModule = require("../lib/DelegatedModule");
describe("DelegatedModule", function() {
describe("#updateHash", function() {
describe("DelegatedModule", () => {
describe("#updateHash", () => {
const sourceRequest = "dll-reference dll_e54c0fb67f8152792ad2";
const data = {
id: "/xg9"
@ -13,7 +13,7 @@ describe("DelegatedModule", function() {
const userRequest = "./library.js";
let hashedText;
let hash;
beforeEach(function() {
beforeEach(() => {
hashedText = "";
hash = {
update: (text) => {
@ -23,11 +23,11 @@ describe("DelegatedModule", function() {
const delegatedModule = new DelegatedModule(sourceRequest, data, type, userRequest);
delegatedModule.updateHash(hash);
});
it("updates hash with delegated module ID", function() {
hashedText.should.containEql("/xg9");
it("updates hash with delegated module ID", () => {
expect(hashedText).toMatch("/xg9");
});
it("updates hash with delegation type", function() {
hashedText.should.containEql("require");
it("updates hash with delegation type", () => {
expect(hashedText).toMatch("require");
});
});
});

View File

@ -1,68 +1,62 @@
"use strict";
const should = require("should");
const sinon = require("sinon");
const DependenciesBlockVariable = require("../lib/DependenciesBlockVariable");
describe("DependenciesBlockVariable", () => {
let DependenciesBlockVariableInstance,
dependencyMock,
sandbox;
const sandbox = sinon.sandbox.create();
const dependencyMock = {
constructor: {
name: "DependencyMock"
},
disconnect: sandbox.spy(),
updateHash: sandbox.spy()
};
const DependenciesBlockVariableInstance = new DependenciesBlockVariable("dependencies-name", "expression", [dependencyMock]);
before(() => {
sandbox = sinon.sandbox.create();
dependencyMock = {
constructor: {
name: "DependencyMock"
},
disconnect: sandbox.spy(),
updateHash: sandbox.spy()
};
DependenciesBlockVariableInstance = new DependenciesBlockVariable(
"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", () =>
it("returns `true` if has dependencies", () =>
should(DependenciesBlockVariableInstance.hasDependencies()).be.true()));
describe("disconnect", () =>
describe("disconnect", () => {
it("trigger dependencies disconnection", () => {
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);
const hash = {
update: sandbox.spy()
};
DependenciesBlockVariableInstance.updateHash(hash);
it("should update hash dependencies with name", () => {
expect(hash.update.calledWith("dependencies-name")).toBe(true);
});
it("should update hash dependencies with name", () =>
should(hash.update.calledWith("dependencies-name")).be.true());
it("should update hash dependencies with expression", () => {
expect(hash.update.calledWith("expression")).toBe(true);
});
it("should update hash dependencies with expression", () =>
should(hash.update.calledWith("expression")).be.true());
it("should update hash inside dependencies", () =>
should(dependencyMock.updateHash.calledOnce).be.true());
it("should update hash inside dependencies", () => {
expect(dependencyMock.updateHash.calledOnce).toBe(true);
});
});
describe("expressionSource", () => {
let dependencyTemplates,
applyMock;
before(() => applyMock = sandbox.spy());
const applyMock = sandbox.spy();
it("aplies information inside dependency templates", () => {
dependencyTemplates = {
get: function() {
const dependencyTemplates = {
get() {
return {
apply: applyMock
};
@ -71,20 +65,20 @@ describe("DependenciesBlockVariable", () => {
DependenciesBlockVariableInstance.expressionSource(
dependencyTemplates, {}, {}
);
should(applyMock.calledOnce).be.true();
expect(applyMock.calledOnce).toBe(true);
});
it("aplies information inside dependency templates", () => {
dependencyTemplates = {
get: function() {
const dependencyTemplates = {
get() {
return false;
}
};
should(() => {
expect(() => {
DependenciesBlockVariableInstance.expressionSource(
dependencyTemplates, {}, {}
);
}).throw("No template for dependency: DependencyMock");
}).toThrow("No template for dependency: DependencyMock");
});
});
});

View File

@ -1,16 +1,16 @@
/* globals describe, it, beforeEach */
"use strict";
require("should");
const sinon = require("sinon");
const ExternalModule = require("../lib/ExternalModule");
const OriginalSource = require("webpack-sources").OriginalSource;
const RawSource = require("webpack-sources").RawSource;
describe("ExternalModule", function() {
describe("ExternalModule", () => {
let externalModule;
let request;
let type;
beforeEach(function() {
beforeEach(() => {
request = "some/request";
type = "some-type";
externalModule = new ExternalModule(
@ -19,34 +19,34 @@ describe("ExternalModule", function() {
`${type} ${request}`
);
});
describe("#identifier", function() {
it("returns an identifier for this module", function() {
describe("#identifier", () => {
it("returns an identifier for this module", () => {
const expected = `external "${request}"`;
externalModule.identifier().should.eql(expected);
expect(externalModule.identifier()).toBe(expected);
});
});
describe("#readableIdentifier", function() {
it("returns an identifier for this module", function() {
describe("#readableIdentifier", () => {
it("returns an identifier for this module", () => {
const expected = `external "${request}"`;
externalModule.identifier().should.eql(expected);
expect(externalModule.identifier()).toBe(expected);
});
});
describe("#needRebuild", function() {
it("always returns false", function() {
externalModule.needRebuild().should.eql(false);
describe("#needRebuild", () => {
it("always returns false", () => {
expect(externalModule.needRebuild()).toBe(false);
});
});
describe("#size", function() {
it("always returns 42", function() {
externalModule.size().should.eql(42);
describe("#size", () => {
it("always returns 42", () => {
expect(externalModule.size()).toBe(42);
});
});
describe("#source", function() {
it("calls getSource with the result of getSourceString", function() {
describe("#source", () => {
it("calls getSource with the result of getSourceString", () => {
// set up
const expectedString = "something expected stringy";
const expectedSource = "something expected sourcy";
@ -57,19 +57,19 @@ describe("ExternalModule", function() {
const result = externalModule.source();
// check
externalModule.getSource.callCount.should.eql(1);
externalModule.getSourceString.callCount.should.eql(1);
externalModule.getSource.args[0][0].should.eql(expectedString);
result.should.eql(expectedSource);
expect(externalModule.getSource.callCount).toBe(1);
expect(externalModule.getSourceString.callCount).toBe(1);
expect(externalModule.getSource.args[0][0]).toBe(expectedString);
expect(result).toBe(expectedSource);
});
});
describe("#getSource", function() {
describe("given it should use source maps", function() {
beforeEach(function() {
describe("#getSource", () => {
describe("given it should use source maps", () => {
beforeEach(() => {
externalModule.useSourceMap = true;
});
it("returns an instance of OriginalSource", function() {
it("returns an instance of OriginalSource", () => {
// set up
const someSourceString = "some source string";
@ -77,14 +77,14 @@ describe("ExternalModule", function() {
const result = externalModule.getSource(someSourceString);
// check
result.should.be.instanceOf(OriginalSource);
expect(result).toBeInstanceOf(OriginalSource);
});
});
describe("given it does not use source maps", function() {
beforeEach(function() {
describe("given it does not use source maps", () => {
beforeEach(() => {
externalModule.useSourceMap = false;
});
it("returns an instance of RawSource", function() {
it("returns an instance of RawSource", () => {
// set up
const someSourceString = "some source string";
@ -92,14 +92,14 @@ describe("ExternalModule", function() {
const result = externalModule.getSource(someSourceString);
// check
result.should.be.instanceOf(RawSource);
expect(result).toBeInstanceOf(RawSource);
});
});
});
describe("#getSourceForGlobalVariableExternal", function() {
describe("given an array as variable name in the global namespace", function() {
it("use the array as lookup in the global object", function() {
describe("#getSourceForGlobalVariableExternal", () => {
describe("given an array as variable name in the global namespace", () => {
it("use the array as lookup in the global object", () => {
// set up
const type = "window";
const varName = ["foo", "bar"];
@ -109,11 +109,11 @@ describe("ExternalModule", function() {
const result = externalModule.getSourceForGlobalVariableExternal(varName, type);
// check
result.should.eql(expected);
expect(result).toBe(expected);
});
});
describe("given an single variable name", function() {
it("look it up in the global namespace", function() {
describe("given an single variable name", () => {
it("look it up in the global namespace", () => {
// set up
const type = "window";
const varName = "foo";
@ -123,14 +123,14 @@ describe("ExternalModule", function() {
const result = externalModule.getSourceForGlobalVariableExternal(varName, type);
// check
result.should.eql(expected);
expect(result).toBe(expected);
});
});
});
describe("#getSourceForCommonJsExternal", function() {
describe("given an array as names in the global namespace", function() {
it("use the first to require a module and the rest as lookup on the required module", function() {
describe("#getSourceForCommonJsExternal", () => {
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", () => {
// set up
const varName = ["module", "look", "up"];
const expected = "module.exports = require(module)[\"look\"][\"up\"];";
@ -139,11 +139,11 @@ describe("ExternalModule", function() {
const result = externalModule.getSourceForCommonJsExternal(varName, type);
// check
result.should.eql(expected);
expect(result).toBe(expected);
});
});
describe("given an single variable name", function() {
it("require a module with that name", function() {
describe("given an single variable name", () => {
it("require a module with that name", () => {
// set up
const type = "window";
const varName = "foo";
@ -153,13 +153,13 @@ describe("ExternalModule", function() {
const result = externalModule.getSourceForCommonJsExternal(varName, type);
// check
result.should.eql(expected);
expect(result).toBe(expected);
});
});
});
describe("#checkExternalVariable", function() {
it("creates a check that fails if a variable does not exist", function() {
describe("#checkExternalVariable", () => {
it("creates a check that fails if a variable does not exist", () => {
// set up
const variableToCheck = "foo";
const request = "bar";
@ -170,12 +170,12 @@ describe("ExternalModule", function() {
const result = externalModule.checkExternalVariable(variableToCheck, request);
// check
result.should.eql(expected);
expect(result).toBe(expected);
});
});
describe("#getSourceForAmdOrUmdExternal", function() {
it("looks up a global variable as specified by the id", function() {
describe("#getSourceForAmdOrUmdExternal", () => {
it("looks up a global variable as specified by the id", () => {
// set up
const id = "someId";
const optional = false;
@ -185,10 +185,10 @@ describe("ExternalModule", function() {
const result = externalModule.getSourceForAmdOrUmdExternal(id, optional, request);
// check
result.should.eql(expected);
expect(result).toBe(expected);
});
describe("given an optinal check is set", function() {
it("ads a check for the existance of the variable before looking it up", function() {
describe("given an optinal check is set", () => {
it("ads a check for the existance of the variable before looking it up", () => {
// set up
const id = "someId";
const optional = true;
@ -199,13 +199,13 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_someId__;`;
const result = externalModule.getSourceForAmdOrUmdExternal(id, optional, request);
// check
result.should.eql(expected);
expect(result).toBe(expected);
});
});
});
describe("#getSourceForDefaultCase", function() {
it("returns the given request as lookup", function() {
describe("#getSourceForDefaultCase", () => {
it("returns the given request as lookup", () => {
// set up
const optional = false;
const expected = "module.exports = some/request;";
@ -214,10 +214,10 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_someId__;`;
const result = externalModule.getSourceForDefaultCase(optional, request);
// check
result.should.eql(expected);
expect(result).toBe(expected);
});
describe("given an optinal check is requested", function() {
it("checks for the existance of the request setting it", function() {
describe("given an optinal check is requested", () => {
it("checks for the existance of the request setting it", () => {
// set up
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;}
@ -227,15 +227,15 @@ module.exports = some/request;`;
const result = externalModule.getSourceForDefaultCase(optional, request);
// check
result.should.eql(expected);
expect(result).toBe(expected);
});
});
});
describe("#updateHash", function() {
describe("#updateHash", () => {
let hashedText;
let hash;
beforeEach(function() {
beforeEach(() => {
hashedText = "";
hash = {
update: (text) => {
@ -245,21 +245,21 @@ module.exports = some/request;`;
externalModule.id = 12345678;
externalModule.updateHash(hash);
});
it("updates hash with request", function() {
hashedText.should.containEql("some/request");
it("updates hash with request", () => {
expect(hashedText).toMatch("some/request");
});
it("updates hash with type", function() {
hashedText.should.containEql("some-type");
it("updates hash with type", () => {
expect(hashedText).toMatch("some-type");
});
it("updates hash with module id", function() {
hashedText.should.containEql("12345678");
it("updates hash with module id", () => {
expect(hashedText).toMatch("12345678");
});
});
describe("#updateHash without optional", function() {
describe("#updateHash without optional", () => {
let hashedText;
let hash;
beforeEach(function() {
beforeEach(() => {
hashedText = "";
hash = {
update: (text) => {
@ -270,17 +270,17 @@ module.exports = some/request;`;
externalModule.id = 12345678;
externalModule.updateHash(hash);
});
it("updates hash with request", function() {
hashedText.should.containEql("some/request");
it("updates hash with request", () => {
expect(hashedText).toMatch("some/request");
});
it("updates hash with type", function() {
hashedText.should.containEql("some-type");
it("updates hash with type", () => {
expect(hashedText).toMatch("some-type");
});
it("updates hash with optional flag", function() {
hashedText.should.containEql("false");
it("updates hash with optional flag", () => {
expect(hashedText).toMatch("false");
});
it("updates hash with module id", function() {
hashedText.should.containEql("12345678");
it("updates hash with module id", () => {
expect(hashedText).toMatch("12345678");
});
});
});

View File

@ -1,15 +1,14 @@
/* globals describe, it, beforeEach */
"use strict";
const should = require("should");
const HarmonyExportImportedSpecifierDependency = require("../lib/dependencies/HarmonyExportImportedSpecifierDependency");
describe("HarmonyExportImportedSpecifierDependency", () => {
describe("getHashValue", () => {
it("should return empty string on missing module", () => { // see e.g. PR #4368
var instance = new HarmonyExportImportedSpecifierDependency();
should(instance.getHashValue(undefined)).be.eql("");
should(instance.getHashValue(null)).be.eql("");
expect(instance.getHashValue(undefined)).toBe("");
expect(instance.getHashValue(null)).toBe("");
});
});
});

View File

@ -1,24 +1,24 @@
/* globals describe, it */
"use strict";
const should = require("should");
const LocalModulesHelpers = require("../lib/dependencies/LocalModulesHelpers");
describe("LocalModulesHelpers", () => {
describe("addLocalModule", () => {
it("returns a module var without special characters", () => {
const state = {
module: "module_sample",
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",
name: "local_module_sample",
idx: 2,
used: false
});
should(state.localModules.length).be.eql(3);
expect(state.localModules.length).toBe(3);
});
});
@ -32,7 +32,7 @@ describe("LocalModulesHelpers", () => {
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", () => {
@ -44,7 +44,7 @@ describe("LocalModulesHelpers", () => {
name: "second"
}]
};
should(LocalModulesHelpers.getLocalModule(state, "first")).be.eql({
expect(LocalModulesHelpers.getLocalModule(state, "first")).toEqual({
name: "first"
});
});

View File

@ -1,15 +1,14 @@
"use strict";
const path = require("path");
require("should");
const ModuleDependencyError = require("../lib/ModuleDependencyError");
describe("ModuleDependencyError", () => {
let env;
beforeEach(() => env = {});
it("is a function", () => ModuleDependencyError.should.be.a.Function());
beforeEach(() => {
env = {};
});
describe("when new error created", () => {
beforeEach(() => {
@ -17,17 +16,28 @@ describe("ModuleDependencyError", () => {
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 error property", () => env.moduleDependencyError.error.should.be.exactly(env.error));
it("has an origin property", () => {
expect(env.moduleDependencyError.origin).toBe("myModule");
});
it("has an error property", () => {
expect(env.moduleDependencyError.error).toBe(env.error);
});
});
});

View File

@ -4,7 +4,6 @@ const Module = require("../lib/Module");
const Chunk = require("../lib/Chunk");
const Dependency = require("../lib/Dependency");
const ModuleReason = require("../lib/ModuleReason");
const should = require("should");
describe("ModuleReason", () => {
let myModule;
@ -23,11 +22,13 @@ describe("ModuleReason", () => {
});
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", () => {
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.rewriteChunks(myChunk, [myChunk2]);
should(myModuleReason.hasChunk(myChunk)).be.false();
should(myModuleReason.hasChunk(myChunk2)).be.true();
expect(myModuleReason.hasChunk(myChunk)).toBe(false);
expect(myModuleReason.hasChunk(myChunk2)).toBe(true);
});
it("if old chunk is not present, new chunks are not added", () => {
myModuleReason.rewriteChunks(myChunk, [myChunk2]);
should(myModuleReason.hasChunk(myChunk)).be.false();
should(myModuleReason.hasChunk(myChunk2)).be.false();
expect(myModuleReason.hasChunk(myChunk)).toBe(false);
expect(myModuleReason.hasChunk(myChunk2)).toBe(false);
});
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(myChunk2, [myChunk]);
should(myModuleReason.hasChunk(myChunk)).be.true();
should(myModuleReason.hasChunk(myChunk2)).be.false();
expect(myModuleReason.hasChunk(myChunk)).toBe(true);
expect(myModuleReason.hasChunk(myChunk2)).toBe(false);
});
});
});

View File

@ -1,6 +1,5 @@
"use strict";
require("should");
const packageJSON = require("../package.json");
const MultiStats = require("../lib/MultiStats");
@ -29,7 +28,9 @@ describe("MultiStats", () => {
packageJSON.version = "1.2.3";
});
afterEach(() => packageJSON.version = packageVersion);
afterEach(() => {
packageJSON.version = packageVersion;
});
describe("created", () => {
beforeEach(() => {
@ -44,7 +45,9 @@ describe("MultiStats", () => {
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", () => {
@ -61,7 +64,9 @@ describe("MultiStats", () => {
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", () => {
@ -75,7 +80,9 @@ describe("MultiStats", () => {
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", () => {
@ -87,7 +94,9 @@ describe("MultiStats", () => {
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);
});
it("returns true", () => myMultiStats.hasWarnings().should.be.exactly(true));
it("returns true", () => {
expect(myMultiStats.hasWarnings()).toBe(true);
});
});
describe("when one has a warning", () => {
@ -119,7 +130,9 @@ describe("MultiStats", () => {
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", () => {
@ -131,7 +144,9 @@ describe("MultiStats", () => {
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,
hash: false
});
result.should.deepEqual({
expect(result).toEqual({
errors: [
"(abc123-compilation) abc123-error"
],
@ -200,7 +215,7 @@ describe("MultiStats", () => {
it("returns plain object representation with json set to true", () => {
myMultiStats = new MultiStats(stats);
result = myMultiStats.toJson(true);
result.should.deepEqual({
expect(result).toEqual({
errors: [
"(abc123-compilation) abc123-error"
],
@ -248,7 +263,7 @@ describe("MultiStats", () => {
});
it("returns string representation", () => {
result.should.be.exactly(
expect(result).toBe(
"Hash: abc123xyz890\n" +
"Version: webpack 1.2.3\n" +
"Child abc123-compilation:\n" +

View File

@ -2,11 +2,10 @@
const Tapable = require("tapable").Tapable;
const SyncHook = require("tapable").SyncHook;
require("should");
const sinon = require("sinon");
const MultiWatching = require("../lib/MultiWatching");
const createWatching = function() {
const createWatching = () => {
return {
invalidate: sinon.spy(),
close: sinon.spy()
@ -33,11 +32,13 @@ describe("MultiWatching", () => {
});
describe("invalidate", () => {
beforeEach(() => myMultiWatching.invalidate());
beforeEach(() => {
myMultiWatching.invalidate();
});
it("invalidates each watching", () => {
watchings[0].invalidate.callCount.should.be.exactly(1);
watchings[1].invalidate.callCount.should.be.exactly(1);
expect(watchings[0].invalidate.callCount).toBe(1);
expect(watchings[1].invalidate.callCount).toBe(1);
});
});
@ -51,14 +52,14 @@ describe("MultiWatching", () => {
});
it("closes each watching", () => {
watchings[0].close.callCount.should.be.exactly(1);
watchings[1].close.callCount.should.be.exactly(1);
expect(watchings[0].close.callCount).toBe(1);
expect(watchings[1].close.callCount).toBe(1);
});
it("calls callback after each watching has closed", () => {
callClosedFinishedCallback(watchings[0]);
callClosedFinishedCallback(watchings[1]);
callback.callCount.should.be.exactly(1);
expect(callback.callCount).toBe(1);
});
});
});

View File

@ -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);
});
});

View File

@ -1,6 +1,6 @@
/* globals describe, it, beforeEach, afterEach */
"use strict";
require("should");
const sinon = require("sinon");
const NormalModule = require("../lib/NormalModule");
const NullDependency = require("../lib/dependencies/NullDependency");
@ -8,7 +8,7 @@ const SourceMapSource = require("webpack-sources").SourceMapSource;
const OriginalSource = require("webpack-sources").OriginalSource;
const RawSource = require("webpack-sources").RawSource;
describe("NormalModule", function() {
describe("NormalModule", () => {
let normalModule;
let request;
let userRequest;
@ -16,7 +16,7 @@ describe("NormalModule", function() {
let loaders;
let resource;
let parser;
beforeEach(function() {
beforeEach(() => {
request = "some/request";
userRequest = "some/userRequest";
rawRequest = "some/rawRequest";
@ -38,37 +38,37 @@ describe("NormalModule", function() {
cacheable: true
};
});
describe("#identifier", function() {
it("returns an identifier for this module", function() {
normalModule.identifier().should.eql(request);
describe("#identifier", () => {
it("returns an identifier for this module", () => {
expect(normalModule.identifier()).toBe(request);
});
it("returns an identifier from toString", function() {
it("returns an identifier from toString", () => {
normalModule.debugId = 1000;
normalModule.toString().should.eql("Module[1000]");
expect(normalModule.toString()).toBe("Module[1000]");
normalModule.id = 1;
normalModule.toString().should.eql("Module[1]");
expect(normalModule.toString()).toBe("Module[1]");
});
});
describe("#readableIdentifier", function() {
it("calls the given requestShortener with the user request", function() {
describe("#readableIdentifier", () => {
it("calls the given requestShortener with the user request", () => {
const spy = sinon.spy();
normalModule.readableIdentifier({
shorten: spy
});
spy.callCount.should.eql(1);
spy.args[0][0].should.eql(userRequest);
expect(spy.callCount).toBe(1);
expect(spy.args[0][0]).toBe(userRequest);
});
});
describe("#libIdent", function() {
it("contextifies the userRequest of the module", function() {
normalModule.libIdent({
describe("#libIdent", () => {
it("contextifies the userRequest of the module", () => {
expect(normalModule.libIdent({
context: "some/context"
}).should.eql("../userRequest");
})).toBe("../userRequest");
});
describe("given a userRequest containing loaders", function() {
beforeEach(function() {
describe("given a userRequest containing loaders", () => {
beforeEach(() => {
userRequest = "some/userRequest!some/other/userRequest!some/thing/is/off/here";
normalModule = new NormalModule(
"javascript/auto",
@ -80,14 +80,14 @@ describe("NormalModule", function() {
parser
);
});
it("contextifies every path in the userRequest", function() {
normalModule.libIdent({
it("contextifies every path in the userRequest", () => {
expect(normalModule.libIdent({
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() {
it("ignores paths in query parameters", function() {
describe("given a userRequest containing query parameters", () => {
it("ignores paths in query parameters", () => {
userRequest = "some/context/loader?query=foo\\bar&otherPath=testpath/other";
normalModule = new NormalModule(
"javascript/auto",
@ -98,20 +98,20 @@ describe("NormalModule", function() {
resource,
parser
);
normalModule.libIdent({
expect(normalModule.libIdent({
context: "some/context",
}).should.eql("./loader?query=foo\\bar&otherPath=testpath/other");
})).toBe("./loader?query=foo\\bar&otherPath=testpath/other");
});
});
});
describe("#nameForCondition", function() {
it("return the resource", function() {
normalModule.nameForCondition().should.eql(resource);
describe("#nameForCondition", () => {
it("return the 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";
beforeEach(function() {
beforeEach(() => {
resource = baseResource + "?some=query";
normalModule = new NormalModule(
"javascript/auto",
@ -123,105 +123,105 @@ describe("NormalModule", function() {
parser
);
});
it("return only the part before the ?-sign", function() {
normalModule.nameForCondition().should.eql(baseResource);
it("return only the part before the ?-sign", () => {
expect(normalModule.nameForCondition()).toBe(baseResource);
});
});
});
describe("#createSourceForAsset", function() {
describe("#createSourceForAsset", () => {
let name;
let content;
let sourceMap;
beforeEach(function() {
beforeEach(() => {
name = "some name";
content = "some content";
sourceMap = "some sourcemap";
});
describe("given no sourcemap", function() {
it("returns a RawSource", function() {
normalModule.createSourceForAsset(name, content).should.be.instanceOf(RawSource);
describe("given no sourcemap", () => {
it("returns a RawSource", () => {
expect(normalModule.createSourceForAsset(name, content)).toBeInstanceOf(RawSource);
});
});
describe("given a string as the sourcemap", function() {
it("returns a OriginalSource", function() {
normalModule.createSourceForAsset(name, content, sourceMap).should.be.instanceOf(OriginalSource);
describe("given a string as the sourcemap", () => {
it("returns a OriginalSource", () => {
expect(normalModule.createSourceForAsset(name, content, sourceMap)).toBeInstanceOf(OriginalSource);
});
});
describe("given a some other kind of sourcemap", function() {
beforeEach(function() {
describe("given a some other kind of sourcemap", () => {
beforeEach(() => {
sourceMap = () => {};
});
it("returns a SourceMapSource", function() {
normalModule.createSourceForAsset(name, content, sourceMap).should.be.instanceOf(SourceMapSource);
it("returns a SourceMapSource", () => {
expect(normalModule.createSourceForAsset(name, content, sourceMap)).toBeInstanceOf(SourceMapSource);
});
});
});
describe("#source", function() {
describe("without the module having any source", function() {
beforeEach(function() {
describe("#source", () => {
describe("without the module having any source", () => {
beforeEach(() => {
normalModule._source = null;
});
it("returns a Source containing an Error", function() {
normalModule.source().should.be.instanceOf(RawSource);
normalModule.source().source().should.eql("throw new Error('No source available');");
it("returns a Source containing an Error", () => {
expect(normalModule.source()).toBeInstanceOf(RawSource);
expect(normalModule.source().source()).toBe("throw new Error('No source available');");
});
});
});
describe("#originalSource", function() {
describe("#originalSource", () => {
let expectedSource = "some source";
beforeEach(function() {
beforeEach(() => {
normalModule._source = new RawSource(expectedSource);
});
it("returns an original Source", function() {
normalModule.originalSource().should.eql(normalModule._source);
it("returns an original Source", () => {
expect(normalModule.originalSource()).toBe(normalModule._source);
});
});
describe("#updateHashWithSource", function() {
describe("#updateHashWithSource", () => {
let hashSpy;
let hash;
beforeEach(function() {
beforeEach(() => {
hashSpy = sinon.spy();
hash = {
update: hashSpy
};
});
describe("without the module having any source", function() {
beforeEach(function() {
describe("without the module having any source", () => {
beforeEach(() => {
normalModule._source = null;
});
it("calls hash function with \"null\"", function() {
it("calls hash function with \"null\"", () => {
normalModule.updateHashWithSource(hash);
hashSpy.callCount.should.eql(1);
hashSpy.args[0][0].should.eql("null");
expect(hashSpy.callCount).toBe(1);
expect(hashSpy.args[0][0]).toBe("null");
});
});
describe("without the module having source", function() {
describe("without the module having source", () => {
let expectedSource = "some source";
beforeEach(function() {
beforeEach(() => {
normalModule._source = new RawSource(expectedSource);
});
it("calls hash function with \"source\" and then the actual source of the module", function() {
normalModule.updateHashWithSource(hash);
hashSpy.callCount.should.eql(2);
hashSpy.args[0][0].should.eql("source");
hashSpy.args[1][0].should.eql(expectedSource);
expect(hashSpy.callCount).toBe(2);
expect(hashSpy.args[0][0]).toBe("source");
expect(hashSpy.args[1][0]).toBe(expectedSource);
});
});
});
describe("#hasDependencies", function() {
it("returns true if has dependencies", function() {
describe("#hasDependencies", () => {
it("returns true if has dependencies", () => {
normalModule.addDependency(new NullDependency());
normalModule.hasDependencies().should.eql(true);
expect(normalModule.hasDependencies()).toBe(true);
});
it("returns false if has dependencies", function() {
normalModule.hasDependencies().should.eql(false);
it("returns false if has dependencies", () => {
expect(normalModule.hasDependencies()).toBe(false);
});
});
describe("#needRebuild", function() {
describe("#needRebuild", () => {
let fileTimestamps;
let contextTimestamps;
let fileDependencies;
@ -229,14 +229,12 @@ describe("NormalModule", function() {
let fileA;
let fileB;
function setDeps(
fileDependencies,
contextDependencies) {
function setDeps(fileDependencies, contextDependencies) {
normalModule.buildInfo.fileDependencies = fileDependencies;
normalModule.buildInfo.contextDependencies = contextDependencies;
}
beforeEach(function() {
beforeEach(() => {
fileA = "fileA";
fileB = "fileB";
fileDependencies = [fileA, fileB];
@ -252,47 +250,47 @@ describe("NormalModule", function() {
normalModule.buildTimestamp = 2;
setDeps(fileDependencies, contextDependencies);
});
describe("given all timestamps are older than the buildTimestamp", function() {
it("returns false", function() {
normalModule.needRebuild(fileTimestamps, contextTimestamps).should.eql(false);
describe("given all timestamps are older than the buildTimestamp", () => {
it("returns false", () => {
expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(false);
});
});
describe("given a file timestamp is newer than the buildTimestamp", function() {
beforeEach(function() {
describe("given a file timestamp is newer than the buildTimestamp", () => {
beforeEach(() => {
fileTimestamps.set(fileA, 3);
});
it("returns true", function() {
normalModule.needRebuild(fileTimestamps, contextTimestamps).should.eql(true);
it("returns true", () => {
expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true);
});
});
describe("given a no file timestamp exists", function() {
beforeEach(function() {
describe("given a no file timestamp exists", () => {
beforeEach(() => {
fileTimestamps = new Map();
});
it("returns true", function() {
normalModule.needRebuild(fileTimestamps, contextTimestamps).should.eql(true);
it("returns true", () => {
expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true);
});
});
describe("given a context timestamp is newer than the buildTimestamp", function() {
beforeEach(function() {
describe("given a context timestamp is newer than the buildTimestamp", () => {
beforeEach(() => {
contextTimestamps.set(fileA, 3);
});
it("returns true", function() {
normalModule.needRebuild(fileTimestamps, contextTimestamps).should.eql(true);
it("returns true", () => {
expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true);
});
});
describe("given a no context timestamp exists", function() {
beforeEach(function() {
describe("given a no context timestamp exists", () => {
beforeEach(() => {
contextTimestamps = new Map();
});
it("returns true", function() {
normalModule.needRebuild(fileTimestamps, contextTimestamps).should.eql(true);
it("returns true", () => {
expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true);
});
});
});
describe("#splitVariablesInUniqueNamedChunks", function() {
describe("#splitVariablesInUniqueNamedChunks", () => {
let variables;
beforeEach(function() {
beforeEach(() => {
variables = [{
name: "foo"
}, {
@ -305,147 +303,147 @@ describe("NormalModule", function() {
name: "more"
}];
});
describe("given an empty array of vars", function() {
it("returns an empty array", function() {
normalModule.splitVariablesInUniqueNamedChunks([]).should.eql([
describe("given an empty array of vars", () => {
it("returns an empty array", () => {
expect(normalModule.splitVariablesInUniqueNamedChunks([])).toEqual([
[]
]);
});
});
describe("given an array of distrinct variables", function() {
it("returns an array containing an array containing the variables", function() {
normalModule.splitVariablesInUniqueNamedChunks(variables).should.eql([variables]);
describe("given an array of distrinct variables", () => {
it("returns an array containing an array containing the variables", () => {
expect(normalModule.splitVariablesInUniqueNamedChunks(variables)).toEqual([variables]);
});
});
describe("given an array with duplicate variables", function() {
it("returns several arrays each containing only distinct variable names", function() {
normalModule.splitVariablesInUniqueNamedChunks(variables.concat(variables)).should.eql([variables, variables]);
describe("given an array with duplicate variables", () => {
it("returns several arrays each containing only distinct variable names", () => {
expect(normalModule.splitVariablesInUniqueNamedChunks(variables.concat(variables))).toEqual([variables, variables]);
});
describe("and a duplicate as the last variable", function() {
it("returns correctly split distinct arrays", function() {
normalModule.splitVariablesInUniqueNamedChunks(variables.concat(variables).concat(variables[0])).should.eql([variables, variables, [variables[0]]]);
describe("and a duplicate as the last variable", () => {
it("returns correctly split distinct arrays", () => {
expect(normalModule.splitVariablesInUniqueNamedChunks(variables.concat(variables).concat(variables[0]))).toEqual([variables, variables, [variables[0]]]);
});
});
});
});
describe("#applyNoParseRule", function() {
describe("#applyNoParseRule", () => {
let rule;
let content;
describe("given a string as rule", function() {
beforeEach(function() {
describe("given a string as rule", () => {
beforeEach(() => {
rule = "some-rule";
});
describe("and the content starting with the string specified in rule", function() {
beforeEach(function() {
describe("and the content starting with the string specified in rule", () => {
beforeEach(() => {
content = rule + "some-content";
});
it("returns true", function() {
normalModule.shouldPreventParsing(rule, content).should.eql(true);
it("returns true", () => {
expect(normalModule.shouldPreventParsing(rule, content)).toBe(true);
});
});
describe("and the content does not start with the string specified in rule", function() {
beforeEach(function() {
describe("and the content does not start with the string specified in rule", () => {
beforeEach(() => {
content = "some-content";
});
it("returns false", function() {
normalModule.shouldPreventParsing(rule, content).should.eql(false);
it("returns false", () => {
expect(normalModule.shouldPreventParsing(rule, content)).toBe(false);
});
});
});
describe("given a regex as rule", function() {
beforeEach(function() {
describe("given a regex as rule", () => {
beforeEach(() => {
rule = /some-rule/;
});
describe("and the content matches the rule", function() {
beforeEach(function() {
describe("and the content matches the rule", () => {
beforeEach(() => {
content = rule + "some-content";
});
it("returns true", function() {
normalModule.shouldPreventParsing(rule, content).should.eql(true);
it("returns true", () => {
expect(normalModule.shouldPreventParsing(rule, content)).toBe(true);
});
});
describe("and the content does not match the rule", function() {
beforeEach(function() {
describe("and the content does not match the rule", () => {
beforeEach(() => {
content = "some-content";
});
it("returns false", function() {
normalModule.shouldPreventParsing(rule, content).should.eql(false);
it("returns false", () => {
expect(normalModule.shouldPreventParsing(rule, content)).toBe(false);
});
});
});
});
describe("#shouldPreventParsing", function() {
describe("#shouldPreventParsing", () => {
let applyNoParseRuleSpy;
beforeEach(function() {
beforeEach(() => {
applyNoParseRuleSpy = sinon.stub();
normalModule.applyNoParseRule = applyNoParseRuleSpy;
});
describe("given no noParseRule", function() {
it("returns false", function() {
normalModule.shouldPreventParsing().should.eql(false);
applyNoParseRuleSpy.callCount.should.eql(0);
describe("given no noParseRule", () => {
it("returns false", () => {
expect(normalModule.shouldPreventParsing()).toBe(false);
expect(applyNoParseRuleSpy.callCount).toBe(0);
});
});
describe("given a noParseRule", function() {
describe("given a noParseRule", () => {
let returnValOfSpy;
beforeEach(function() {
beforeEach(() => {
returnValOfSpy = true;
applyNoParseRuleSpy.returns(returnValOfSpy);
});
describe("that is a string", function() {
it("calls and returns whatever applyNoParseRule returns", function() {
normalModule.shouldPreventParsing("some rule").should.eql(returnValOfSpy);
applyNoParseRuleSpy.callCount.should.eql(1);
describe("that is a string", () => {
it("calls and returns whatever applyNoParseRule returns", () => {
expect(normalModule.shouldPreventParsing("some rule")).toBe(returnValOfSpy);
expect(applyNoParseRuleSpy.callCount).toBe(1);
});
});
describe("that is a regex", function() {
it("calls and returns whatever applyNoParseRule returns", function() {
normalModule.shouldPreventParsing("some rule").should.eql(returnValOfSpy);
applyNoParseRuleSpy.callCount.should.eql(1);
describe("that is a regex", () => {
it("calls and returns whatever applyNoParseRule returns", () => {
expect(normalModule.shouldPreventParsing("some rule")).toBe(returnValOfSpy);
expect(applyNoParseRuleSpy.callCount).toBe(1);
});
});
describe("that is an array", function() {
describe("of strings and or regexs", function() {
describe("that is an array", () => {
describe("of strings and or regexs", () => {
let someRules;
beforeEach(function() {
beforeEach(() => {
someRules = [
"some rule",
/some rule1/,
"some rule2",
];
});
describe("and none of them match", function() {
beforeEach(function() {
describe("and none of them match", () => {
beforeEach(() => {
returnValOfSpy = false;
applyNoParseRuleSpy.returns(returnValOfSpy);
});
it("returns false", function() {
normalModule.shouldPreventParsing(someRules).should.eql(returnValOfSpy);
applyNoParseRuleSpy.callCount.should.eql(3);
it("returns false", () => {
expect(normalModule.shouldPreventParsing(someRules)).toBe(returnValOfSpy);
expect(applyNoParseRuleSpy.callCount).toBe(3);
});
});
describe("and the first of them matches", function() {
beforeEach(function() {
describe("and the first of them matches", () => {
beforeEach(() => {
returnValOfSpy = true;
applyNoParseRuleSpy.returns(returnValOfSpy);
});
it("returns true", function() {
normalModule.shouldPreventParsing(someRules).should.eql(returnValOfSpy);
applyNoParseRuleSpy.callCount.should.eql(1);
it("returns true", () => {
expect(normalModule.shouldPreventParsing(someRules)).toBe(returnValOfSpy);
expect(applyNoParseRuleSpy.callCount).toBe(1);
});
});
describe("and the last of them matches", function() {
beforeEach(function() {
describe("and the last of them matches", () => {
beforeEach(() => {
returnValOfSpy = true;
applyNoParseRuleSpy.onCall(0).returns(false);
applyNoParseRuleSpy.onCall(1).returns(false);
applyNoParseRuleSpy.onCall(2).returns(true);
});
it("returns true", function() {
normalModule.shouldPreventParsing(someRules).should.eql(returnValOfSpy);
applyNoParseRuleSpy.callCount.should.eql(3);
it("returns true", () => {
expect(normalModule.shouldPreventParsing(someRules)).toBe(returnValOfSpy);
expect(applyNoParseRuleSpy.callCount).toBe(3);
});
});
});

View File

@ -1,39 +1,12 @@
"use strict";
require("should");
const sinon = require("sinon");
const NullDependency = require("../lib/dependencies/NullDependency");
describe("NullDependency", () => {
let env;
beforeEach(() => env = {});
it("is a function", () => NullDependency.should.be.a.Function());
describe("when created", () => {
beforeEach(() => env.nullDependency = new NullDependency());
it("has a null type", () => env.nullDependency.type.should.be.exactly("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());
it("has a null type", () => {
const nullDependency = new NullDependency();
expect(nullDependency.type).toBe("null");
});
});
});

View File

@ -1,7 +1,5 @@
"use strict";
const should = require("should");
const Parser = require("../lib/Parser");
const BasicEvaluatedExpression = require("../lib/BasicEvaluatedExpression");
@ -281,8 +279,8 @@ describe("Parser", () => {
return true;
});
const actual = testParser.parse(source);
should.strictEqual(typeof actual, "object");
actual.should.be.eql(state);
expect(typeof actual).toBe("object");
expect(actual).toEqual(state);
});
});
@ -304,13 +302,13 @@ describe("Parser", () => {
});
const actual = testParser.parse(source);
should.strictEqual(typeof actual, "object");
should.strictEqual(typeof actual.comments, "object");
expect(typeof actual).toBe("object");
expect(typeof actual.comments).toBe("object");
actual.comments.forEach((element, index) => {
should.strictEqual(typeof element.type, "string");
should.strictEqual(typeof element.value, "string");
element.type.should.be.eql(state[index].type);
element.value.should.be.eql(state[index].value);
expect(typeof element.type).toBe("string");
expect(typeof element.value).toBe("string");
expect(element.type).toBe(state[index].type);
expect(element.value).toBe(state[index].value);
});
});
@ -458,7 +456,7 @@ describe("Parser", () => {
it("should eval " + 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];
it(name, () => {
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) => {
it(name, () => {
const actual = parser.parse(cases[name][0]);
actual.should.be.eql(cases[name][1]);
expect(actual).toEqual(cases[name][1]);
});
});
});

View File

@ -1,6 +1,5 @@
"use strict";
require("should");
const ProfilingPlugin = require("../lib/debug/ProfilingPlugin");
describe("Profiling Plugin", () => {
@ -8,55 +7,36 @@ describe("Profiling Plugin", () => {
const plugin = new ProfilingPlugin({
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", () => {
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();
profiler.startProfiling().then(() => {
done();
}).catch(e => {
done(e);
});
return profiler.startProfiling();
});
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({
Session() {
throw new Error("Sean Larkin was here.");
}
});
profiler.startProfiling().then(() => {
done();
}).catch(e => {
done(e);
});
return profiler.startProfiling();
});
it("handles sending a profiling message when no session", (done) => {
it("handles sending a profiling message when no session", () => {
const profiler = new ProfilingPlugin.Profiler();
profiler.sendCommand("randy", "is a puppers").then(() => {
done();
}).catch(e => {
done(e);
});
return profiler.sendCommand("randy", "is a puppers");
});
it("handles destroying when no session", (done) => {
it("handles destroying when no session", () => {
const profiler = new ProfilingPlugin.Profiler();
profiler.destroy().then(() => {
done();
}).catch(e => {
done(e);
});
return profiler.destroy();
});
});

View File

@ -4,29 +4,25 @@ const RawModule = require("../lib/RawModule");
const OriginalSource = require("webpack-sources").OriginalSource;
const RawSource = require("webpack-sources").RawSource;
const RequestShortener = require("../lib/RequestShortener");
const should = require("should");
const path = require("path");
const crypto = require("crypto");
describe("RawModule", () => {
let myRawModule;
before(() => {
const source = "sourceStr attribute";
const identifier = "identifierStr attribute";
const readableIdentifier = "readableIdentifierStr attribute";
myRawModule = new RawModule(source, identifier, readableIdentifier);
});
const source = "sourceStr attribute";
const identifier = "identifierStr attribute";
const readableIdentifier = "readableIdentifierStr attribute";
const myRawModule = new RawModule(source, identifier, readableIdentifier);
describe("identifier", () => {
it("returns value for identifierStr attribute", () =>
should(myRawModule.identifier()).be.exactly("identifierStr attribute"));
it("returns value for identifierStr attribute", () => {
expect(myRawModule.identifier()).toBe("identifierStr attribute");
});
});
describe("size", () => {
it("returns value for sourceStr attribute\"s length property", () => {
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",
() => {
const requestShortener = new RequestShortener(path.resolve());
should.exist(myRawModule.readableIdentifier(requestShortener));
expect(myRawModule.readableIdentifier(requestShortener)).toBeDefined();
}
);
});
describe("needRebuild", () => {
it("returns false", () => should(myRawModule.needRebuild()).be.false());
it("returns false", () => {
expect(myRawModule.needRebuild()).toBe(false);
});
});
describe("source", () => {
@ -50,7 +48,7 @@ describe("RawModule", () => {
() => {
const originalSource = new OriginalSource(myRawModule.sourceStr, myRawModule.identifier());
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);
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 hashBar = hashModule(new RawModule("\"bar\""));
hashFoo.should.not.equal(hashBar);
expect(hashFoo).not.toBe(hashBar);
});
});
});

View File

@ -22,18 +22,18 @@ function match(ruleSet, resource) {
describe("RuleSet", () => {
it("should create RuleSet with a blank array", () => {
const loader = new RuleSet([]);
(loader.rules).should.eql([]);
expect(loader.rules).toEqual([]);
});
it("should create RuleSet and match with empty array", () => {
const loader = new RuleSet([]);
(match(loader, "something")).should.eql([]);
expect(match(loader, "something")).toEqual([]);
});
it("should not match with loaders array", () => {
const loader = new RuleSet([{
test: /\.css$/,
loader: "css"
}]);
(match(loader, "something")).should.eql([]);
expect(match(loader, "something")).toEqual([]);
});
it("should match with regex", () => {
@ -41,7 +41,7 @@ describe("RuleSet", () => {
test: /\.css$/,
loader: "css"
}]);
(match(loader, "style.css")).should.eql(["css"]);
expect(match(loader, "style.css")).toEqual(["css"]);
});
it("should match with string", () => {
@ -49,7 +49,7 @@ describe("RuleSet", () => {
test: "style.css",
loader: "css"
}]);
(match(loader, "style.css")).should.eql(["css"]);
expect(match(loader, "style.css")).toEqual(["css"]);
});
it("should match with function", () => {
@ -59,19 +59,19 @@ describe("RuleSet", () => {
},
loader: "css"
}]);
(match(loader, "style.css")).should.eql(["css"]);
expect(match(loader, "style.css")).toEqual(["css"]);
});
it("should throw if invalid test", () => {
should.throws(() => {
expect(() => {
const loader = new RuleSet([{
test: {
invalid: "test"
},
loader: "css"
}]);
(match(loader, "style.css")).should.eql(["css"]);
}, /Unexcepted property invalid in condition/);
match(loader, "style.css");
}).toThrow(/Unexcepted property invalid in condition/);
});
it("should accept multiple test array that all match", () => {
@ -82,7 +82,7 @@ describe("RuleSet", () => {
],
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", () => {
@ -93,7 +93,7 @@ describe("RuleSet", () => {
],
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", () => {
@ -102,7 +102,7 @@ describe("RuleSet", () => {
include: /output.css/,
loader: "css"
}]);
(match(loader, "style.css")).should.eql([]);
expect(match(loader, "style.css")).toEqual([]);
});
it("should match if include matches", () => {
@ -111,7 +111,7 @@ describe("RuleSet", () => {
include: /style.css/,
loader: "css"
}]);
(match(loader, "style.css")).should.eql(["css"]);
expect(match(loader, "style.css")).toEqual(["css"]);
});
it("should not match if exclude matches", () => {
@ -120,7 +120,7 @@ describe("RuleSet", () => {
exclude: /style.css/,
loader: "css"
}]);
(match(loader, "style.css")).should.eql([]);
expect(match(loader, "style.css")).toEqual([]);
});
it("should match if exclude does not match", () => {
@ -129,15 +129,15 @@ describe("RuleSet", () => {
exclude: /output.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", () => {
const loader = new RuleSet([{
loader: "css"
}]);
(match(loader, "style.css")).should.eql(["css"]);
(match(loader, "scripts.js")).should.eql(["css"]);
expect(match(loader, "style.css")).toEqual(["css"]);
expect(match(loader, "scripts.js")).toEqual(["css"]);
});
it("should work with using loader as string", () => {
@ -145,7 +145,7 @@ describe("RuleSet", () => {
test: /\.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", () => {
@ -153,7 +153,7 @@ describe("RuleSet", () => {
test: /\.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", () => {
@ -161,7 +161,7 @@ describe("RuleSet", () => {
test: /\.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", () => {
@ -169,19 +169,19 @@ describe("RuleSet", () => {
test: /\.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", () => {
should.throws(function() {
expect(() => {
const loader = new RuleSet([{
test: /\.css$/,
loaders: {
someObj: true
}
}]);
(match(loader, "style.css")).should.eql(["css"]);
}, /No loader specified/);
match(loader, "style.css");
}).toThrow(/No loader specified/);
});
it("should work with using loader with inline query", () => {
@ -189,7 +189,7 @@ describe("RuleSet", () => {
test: /\.css$/,
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", () => {
@ -198,7 +198,7 @@ describe("RuleSet", () => {
loader: "css",
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", () => {
@ -209,7 +209,7 @@ describe("RuleSet", () => {
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", () => {
@ -219,11 +219,11 @@ describe("RuleSet", () => {
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", () => {
should.throws(() => {
expect(() => {
const loader = new RuleSet([{
test: /\.css$/,
loaders: [{
@ -231,7 +231,7 @@ describe("RuleSet", () => {
}]
}]);
match(loader, "style.css");
}, /No loader specified/);
}).toThrow(/No loader specified/);
});
it("should work with using array loaders with object notation", () => {
@ -242,7 +242,7 @@ describe("RuleSet", () => {
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", () => {
@ -256,7 +256,7 @@ describe("RuleSet", () => {
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", () => {
@ -264,18 +264,18 @@ describe("RuleSet", () => {
test: /\.css$/,
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", () => {
should.throws(() => {
expect(() => {
const loader = new RuleSet([{
test: /\.css$/,
loaders: ["style-loader", "css-loader"],
query: "modules=1"
}]);
(match(loader, "style.css")).should.eql(["css"]);
}, /options\/query cannot be used with loaders/);
match(loader, "style.css");
}).toThrow(/options\/query cannot be used with loaders/);
});
it("should work when using array loaders", () => {
@ -283,7 +283,7 @@ describe("RuleSet", () => {
test: /\.css$/,
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", () => {
@ -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", () => {
@ -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", () => {
@ -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", () => {
should.throws(() => {
expect(() => {
const loader = new RuleSet([{
test: /\.css$/,
loaders: ["style-loader", "css-loader", 5],
}]);
(match(loader, "style.css")).should.eql(["css"]);
}, /No loader specified/);
match(loader, "style.css");
}).toThrow(/No loader specified/);
});
describe("when exclude array holds an undefined item", () => {
function errorHasContext(err) {
if(/Expected condition but got falsy value/.test(err) &&
return /Expected condition but got falsy value/.test(err) &&
/test/.test(err) &&
/include/.test(err) &&
/exclude/.test(err) &&
/node_modules/.test(err) &&
/undefined/.test(err)) {
return true;
}
/undefined/.test(err);
}
it("should throw with context", () => {
should.throws(() => {
try {
const loader = new RuleSet([{
test: /\.css$/,
loader: "css",
@ -372,11 +370,14 @@ describe("RuleSet", () => {
undefined,
],
}]);
(match(loader, "style.css")).should.eql(["css"]);
}, errorHasContext);
match(loader, "style.css");
throw new Error("unreachable");
} catch(e) {
expect(errorHasContext(e.message)).toBe(true);
}
});
it("in resource should throw with context", () => {
should.throws(() => {
try {
const loader = new RuleSet([{
resource: {
test: /\.css$/,
@ -389,12 +390,14 @@ describe("RuleSet", () => {
],
},
}]);
(match(loader, "style.css")).should.eql(["css"]);
}, errorHasContext);
match(loader, "style.css");
throw new Error("unreachable");
} catch(e) {
expect(errorHasContext(e.message)).toBe(true);
}
});
it("in issuer should throw with context", () => {
should.throws(() => {
try {
const loader = new RuleSet([{
issuer: {
test: /\.css$/,
@ -407,8 +410,11 @@ describe("RuleSet", () => {
],
},
}]);
(match(loader, "style.css")).should.eql(["css"]);
}, errorHasContext);
match(loader, "style.css");
throw new Error("unreachable");
} catch(e) {
expect(errorHasContext(e.message)).toBe(true);
}
});
});
});

View File

@ -1,41 +1,40 @@
/* globals describe, it, beforeEach */
"use strict";
const should = require("should");
const SizeFormatHelpers = require("../lib/SizeFormatHelpers");
describe("SizeFormatHelpers", () => {
describe("formatSize", () => {
it("should handle zero size", () => {
should(SizeFormatHelpers.formatSize(0)).be.eql("0 bytes");
expect(SizeFormatHelpers.formatSize(0)).toBe("0 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", () => {
should(SizeFormatHelpers.formatSize(2048)).be.eql("2 KiB");
expect(SizeFormatHelpers.formatSize(2048)).toBe("2 KiB");
});
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", () => {
should(SizeFormatHelpers.formatSize(10 * 1024 * 1024)).be.eql("10 MiB");
expect(SizeFormatHelpers.formatSize(10 * 1024 * 1024)).toBe("10 MiB");
});
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", () => {
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", () => {
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");
});
});
});

View File

@ -6,7 +6,7 @@ const SortableSet = require("../lib/util/SortableSet");
describe("util/SortableSet", () => {
it("Can be constructed like a normal Set", () => {
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", () => {
@ -15,7 +15,7 @@ describe("util/SortableSet", () => {
(a, b) => a - b
);
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", () => {
@ -24,6 +24,6 @@ describe("util/SortableSet", () => {
(a, b) => a - b
);
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]);
});
});

View File

@ -1,6 +1,5 @@
"use strict";
require("should");
const SourceMapDevToolModuleOptionsPlugin = require("../lib/SourceMapDevToolModuleOptionsPlugin");
const applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
@ -8,35 +7,44 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => {
describe("when applied", () => {
let eventBindings;
beforeEach(() => eventBindings = undefined);
beforeEach(() => {
eventBindings = undefined;
});
describe("with module false and line-to-line false", () => {
beforeEach(() =>
beforeEach(() => {
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
module: 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", () => {
beforeEach(() =>
beforeEach(() => {
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
module: true,
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", () => {
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 source map flag", () => {
const module = {};
eventBindings[0].handler(module);
module.should.deepEqual({
expect(module).toEqual({
useSourceMap: true
});
});
@ -50,15 +58,19 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => {
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", () => {
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", () => {
const module = {};
eventBindings[0].handler(module);
module.should.deepEqual({
expect(module).toEqual({
lineToLine: true
});
});
@ -66,22 +78,27 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => {
});
describe("with line-to-line object", () => {
beforeEach(() =>
beforeEach(() => {
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
module: false,
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", () => {
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", () => {
it("makes no changes", () => {
const module = {};
eventBindings[0].handler(module);
module.should.deepEqual({});
expect(module).toEqual({});
});
});
@ -91,7 +108,7 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => {
resource: "foo"
};
eventBindings[0].handler(module);
module.should.deepEqual({
expect(module).toEqual({
lineToLine: true,
resource: "foo"
});
@ -104,7 +121,7 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => {
resource: "foo?bar"
};
eventBindings[0].handler(module);
module.should.deepEqual({
expect(module).toEqual({
lineToLine: true,
resource: "foo?bar"
});

View File

@ -1,8 +1,6 @@
/*globals describe it */
"use strict";
require("should");
const Stats = require("../lib/Stats");
describe("Stats", () => {
@ -17,7 +15,7 @@ describe("Stats", () => {
context: ""
}
});
mockStats.hasErrors().should.be.ok();
expect(mockStats.hasErrors()).toBe(true);
});
it("hasWarnings", () => {
const mockStats = new Stats({
@ -28,7 +26,7 @@ describe("Stats", () => {
context: ""
}
});
mockStats.hasWarnings().should.be.ok();
expect(mockStats.hasWarnings()).toBe(true);
});
});
describe("does not have", () => {
@ -41,7 +39,7 @@ describe("Stats", () => {
context: ""
}
});
mockStats.hasErrors().should.not.be.ok();
expect(mockStats.hasErrors()).toBe(false);
});
it("hasWarnings", () => {
const mockStats = new Stats({
@ -52,7 +50,7 @@ describe("Stats", () => {
context: ""
}
});
mockStats.hasWarnings().should.not.be.ok();
expect(mockStats.hasWarnings()).toBe(false);
});
});
describe("children have", () => {
@ -67,7 +65,7 @@ describe("Stats", () => {
errors: [],
hash: "1234"
});
mockStats.hasErrors().should.be.ok();
expect(mockStats.hasErrors()).toBe(true);
});
it("hasWarnings", () => {
const mockStats = new Stats({
@ -80,7 +78,7 @@ describe("Stats", () => {
warnings: [],
hash: "1234"
});
mockStats.hasWarnings().should.be.ok();
expect(mockStats.hasWarnings()).toBe(true);
});
});
it("formatError handles string errors", () => {
@ -101,35 +99,35 @@ describe("Stats", () => {
}
});
const obj = mockStats.toJson();
obj.errors[0].should.be.equal("firstError");
expect(obj.errors[0]).toEqual("firstError");
});
});
describe("Presets", () => {
describe("presetToOptions", () => {
it("returns correct object with 'Normal'", () => {
Stats.presetToOptions("Normal").should.eql({});
expect(Stats.presetToOptions("Normal")).toEqual({});
});
it("truthy values behave as 'normal'", () => {
const normalOpts = Stats.presetToOptions("normal");
Stats.presetToOptions("pizza").should.eql(normalOpts);
Stats.presetToOptions(true).should.eql(normalOpts);
Stats.presetToOptions(1).should.eql(normalOpts);
expect(Stats.presetToOptions("pizza")).toEqual(normalOpts);
expect(Stats.presetToOptions(true)).toEqual(normalOpts);
expect(Stats.presetToOptions(1)).toEqual(normalOpts);
Stats.presetToOptions("verbose").should.not.eql(normalOpts);
Stats.presetToOptions(false).should.not.eql(normalOpts);
expect(Stats.presetToOptions("verbose")).not.toEqual(normalOpts);
expect(Stats.presetToOptions(false)).not.toEqual(normalOpts);
});
it("returns correct object with 'none'", () => {
Stats.presetToOptions("none").should.eql({
expect(Stats.presetToOptions("none")).toEqual({
all: false
});
});
it("falsy values behave as 'none'", () => {
const noneOpts = Stats.presetToOptions("none");
Stats.presetToOptions("").should.eql(noneOpts);
Stats.presetToOptions(null).should.eql(noneOpts);
Stats.presetToOptions().should.eql(noneOpts);
Stats.presetToOptions(0).should.eql(noneOpts);
Stats.presetToOptions(false).should.eql(noneOpts);
expect(Stats.presetToOptions("")).toEqual(noneOpts);
expect(Stats.presetToOptions(null)).toEqual(noneOpts);
expect(Stats.presetToOptions()).toEqual(noneOpts);
expect(Stats.presetToOptions(0)).toEqual(noneOpts);
expect(Stats.presetToOptions(false)).toEqual(noneOpts);
});
});
});

View File

@ -1,27 +1,22 @@
"use strict";
require("should");
const Template = require("../lib/Template");
describe("Template", () => {
it("should generate valid identifiers", () =>
Template.toIdentifier("0abc-def9").should.equal("_0abc_def9"));
it("should generate valid identifiers", () => {
expect(Template.toIdentifier("0abc-def9")).toBe("_0abc_def9");
});
it("should generate valid number identifiers", () => {
const items = [];
let item;
for(let i = 0; i < 80; i += 1) {
item = Template.numberToIdentifer(i);
if(item === "") {
throw new Error("empty number identifier");
} else if(items.indexOf(item) > -1) {
throw new Error("duplicate number identifier");
} else {
items.push(item);
}
expect(item).not.toBe("");
expect(items).not.toContain(item);
items.push(item);
}
});
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");
});
});

View File

@ -1,23 +1,18 @@
"use strict";
const should = require("should");
const WebEnvironmentPlugin = require("../lib/web/WebEnvironmentPlugin");
describe("WebEnvironmentPlugin", () => {
let WebEnvironmentPluginInstance;
before(() => WebEnvironmentPluginInstance = new WebEnvironmentPlugin("inputFileSystem", "outputFileSystem"));
describe("apply", () => {
let compileSpy;
before(() => {
compileSpy = {
outputFileSystem: "otherOutputFileSystem"
};
WebEnvironmentPluginInstance.apply(compileSpy);
});
const WebEnvironmentPluginInstance = new WebEnvironmentPlugin("inputFileSystem", "outputFileSystem");
const compileSpy = {
outputFileSystem: "otherOutputFileSystem"
};
it("should set compiler.outputFileSystem information with the same as setted in WebEnvironmentPlugin", () =>
should(compileSpy.outputFileSystem).be.eql(WebEnvironmentPluginInstance.outputFileSystem));
WebEnvironmentPluginInstance.apply(compileSpy);
it("should set compiler.outputFileSystem information with the same as setted in WebEnvironmentPlugin", () => {
expect(compileSpy.outputFileSystem).toBe(WebEnvironmentPluginInstance.outputFileSystem);
});
});
});

View File

@ -1,8 +1,8 @@
"use strict";
const path = require("path");
const util = require("util");
require("should");
const WebpackError = require("../lib/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 errorArr = errorStr.split("\n");
errorArr[0].should.equal("CustomError: CustomMessage");
errorArr[1].should.containEql("WebpackError.unittest.js");
errorArr[errorArr.length - 1].should.equal("CustomDetails");
expect(errorArr[0]).toBe("CustomError: CustomMessage");
expect(errorArr[1]).toMatch(path.basename(__filename));
expect(errorArr[errorArr.length - 1]).toBe("CustomDetails");
});
});

View File

@ -1,28 +1,27 @@
/* globals describe, it */
"use strict";
const should = require("should");
const WebpackMissingModule = require("../lib/dependencies/WebpackMissingModule");
describe("WebpackMissingModule", () => {
describe("#moduleCode", () => {
it("returns an error message based on given error 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", () => {
it("returns an error message based on given error 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", () => {
it("returns an error message based on given error 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; }())");
});
});
});

View File

@ -1,15 +1,14 @@
"use strict";
const should = require("should");
const compareLocations = require("../lib/compareLocations");
const createPosition = function(overides) {
const createPosition = (overides) => {
return Object.assign({
line: 10,
column: 5
}, overides);
};
const createLocation = function(start, end, index) {
const createLocation = (start, end, index) => {
return {
start: createPosition(start),
end: createPosition(end),
@ -19,14 +18,17 @@ const createLocation = function(start, end, index) {
describe("compareLocations", () => {
describe("string location comparison", () => {
it("returns -1 when the first string comes before the second string", () =>
compareLocations("alpha", "beta").should.be.exactly(-1));
it("returns -1 when the first string comes before the second string", () => {
expect(compareLocations("alpha", "beta")).toBe(-1);
});
it("returns 1 when the first string comes after the second string", () =>
compareLocations("beta", "alpha").should.be.exactly(1));
it("returns 1 when the first string comes after the second string", () => {
expect(compareLocations("beta", "alpha")).toBe(1);
});
it("returns 0 when the first string is the same as the second string", () =>
compareLocations("charlie", "charlie").should.be.exactly(0));
it("returns 0 when the first string is the same as the second string", () => {
expect(compareLocations("charlie", "charlie")).toBe(0);
});
});
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", () => {
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", () =>
compareLocations(b, a).should.be.exactly(1));
it("returns 1 when the first location line number comes after the second location line number", () => {
expect(compareLocations(b, a)).toBe(1);
});
});
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", () =>
compareLocations(a, b).should.be.exactly(-1));
it("returns -1 when the first location column number comes before the second location column number", () => {
expect(compareLocations(a, b)).toBe(-1);
});
it("returns 1 when the first location column number comes after the second location column number", () =>
compareLocations(b, a).should.be.exactly(1));
it("returns 1 when the first location column number comes after the second location column number", () => {
expect(compareLocations(b, a)).toBe(1);
});
});
describe("location index number", () => {
@ -73,11 +78,13 @@ describe("compareLocations", () => {
b = createLocation(null, null, 20);
});
it("returns -1 when the first location index number comes before the second location index number", () =>
compareLocations(a, b).should.be.exactly(-1));
it("returns -1 when the first location index number comes before the second location index number", () => {
expect(compareLocations(a, b)).toBe(-1);
});
it("returns 1 when the first location index number comes after the second location index number", () =>
compareLocations(b, a).should.be.exactly(1));
it("returns 1 when the first location index number comes after the second location index number", () => {
expect(compareLocations(b, a)).toBe(1);
});
});
describe("same location", () => {
@ -87,34 +94,40 @@ describe("compareLocations", () => {
});
it("returns 0", () => {
compareLocations(a, b).should.be.exactly(0);
expect(compareLocations(a, b)).toBe(0);
});
});
});
describe("string and object location comparison", () => {
it("returns 1 when the first parameter is a string and the second parameter is an object", () =>
compareLocations("alpha", createLocation()).should.be.exactly(1));
it("returns 1 when the first parameter is a string and the second parameter is an object", () => {
expect(compareLocations("alpha", createLocation())).toBe(1);
});
it("returns -1 when the first parameter is an object and the second parameter is a string", () =>
compareLocations(createLocation(), "alpha").should.be.exactly(-1));
it("returns -1 when the first parameter is an object and the second parameter is a string", () => {
expect(compareLocations(createLocation(), "alpha")).toBe(-1);
});
});
describe("unknown location type comparison", () => {
it("returns 0 when the first parameter is an object and the second parameter is a number", () =>
compareLocations(createLocation(), 123).should.be.exactly(0));
it("returns 0 when the first parameter is an object and the second parameter is a number", () => {
expect(compareLocations(createLocation(), 123)).toBe(0);
});
it("returns undefined when the first parameter is a number and the second parameter is an object", () =>
should(compareLocations(123, createLocation())).be.undefined());
it("returns undefined when the first parameter is a number and the second parameter is an object", () => {
expect(compareLocations(123, createLocation())).toBe(undefined);
});
it("returns 0 when the first parameter is a string and the second parameter is a number", () =>
compareLocations("alpha", 123).should.be.exactly(0));
it("returns 0 when the first parameter is a string and the second parameter is a number", () => {
expect(compareLocations("alpha", 123)).toBe(0);
});
it("returns undefined when the first parameter is a number and the second parameter is a string", () =>
should(compareLocations(123, "alpha")).be.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 the first parameter is a number and the second parameter is a string", () => {
expect(compareLocations(123, "alpha")).toBe(undefined);
});
it("returns undefined when both the first parameter and the second parameter is a number", () => {
expect(compareLocations(123, 456)).toBe(undefined);
});
});
});

View File

@ -1,6 +1,5 @@
"use strict";
require("should");
const formatLocation = require("../lib/formatLocation");
describe("formatLocation", () => {
@ -90,7 +89,7 @@ describe("formatLocation", () => {
}];
testCases.forEach(testCase => {
it(`should format location correctly for ${testCase.name}`, () => {
formatLocation(testCase.loc).should.be.eql(testCase.result);
expect(formatLocation(testCase.loc)).toEqual(testCase.result);
});
});
});

View File

@ -1,8 +1,6 @@
/* globals describe, beforeEach, it */
"use strict";
const should = require("should");
const identifierUtil = require("../lib/util/identifier");
describe("util/identifier", () => {
@ -16,7 +14,7 @@ describe("util/identifier", () => {
});
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);
});
});
});

View File

@ -1,17 +1,15 @@
/* globals describe it */
require("should");
var objectToMap = require("../lib/util/objectToMap");
describe("objectToMap", function() {
it("should convert a plain object into a Map successfully", function() {
describe("objectToMap", () => {
it("should convert a plain object into a Map successfully", () => {
const map = objectToMap({
foo: "bar",
bar: "baz"
});
map.get("foo").should.eql("bar");
map.get("bar").should.eql("baz");
expect(map.get("foo")).toBe("bar");
expect(map.get("bar")).toBe("baz");
});
});

1316
yarn.lock

File diff suppressed because it is too large Load Diff