-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea1fc48
commit 8c03c4b
Showing
8 changed files
with
381 additions
and
110 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_1 = require("../../index"); | ||
describe("immutability and configurability of option arguments", () => { | ||
const testArr = [1, 2, 3, 4, 5]; | ||
const defaultOptions = index_1.NodeLogger.defaultOptions; | ||
describe("given that a NodeLogger instance is created with options", () => { | ||
it("should NOT allow options to be set by the log func", () => { | ||
const logger = new index_1.NodeLogger("Test", { | ||
ignoreIterators: true, | ||
onlyFirstElem: true, | ||
}); | ||
const calledWith = JSON.stringify(logger._options); | ||
// const escapedCalledWith = calledWith.replace(/\"/g, '\\"'); | ||
const expectedErrorMsg = new RegExp(`Cannot redefine _options in the instance if the constructor is called with options.\nAlready called with: ${calledWith}`); | ||
expect(() => { | ||
testArr.forEach((num) => { | ||
logger.log({ num }, { ignoreIterators: false }); | ||
}); | ||
}).toThrow(expectedErrorMsg); | ||
}); | ||
it("logger instances should retain the original option values", () => { | ||
const logger = new index_1.NodeLogger("Test", { | ||
ignoreIterators: true, | ||
onlyFirstElem: true, | ||
}); | ||
expect(() => { | ||
testArr.forEach((num) => { | ||
logger.log({ num }); | ||
}); | ||
}).not.toThrow(); | ||
expect(logger._options).toStrictEqual({ | ||
ignoreIterators: true, | ||
onlyFirstElem: true, | ||
}); | ||
}); | ||
}); | ||
describe("given that a NodeLogger instance is NOT created with options", () => { | ||
it("should allow options to be set by the log func", () => { | ||
const logger = new index_1.NodeLogger("Test"); | ||
expect(() => { | ||
testArr.map((num) => { | ||
logger.log({ num }, { ignoreIterators: true, onlyFirstElem: true }); | ||
}); | ||
}).not.toThrow(); | ||
expect(logger._options).toStrictEqual({ | ||
ignoreIterators: true, | ||
onlyFirstElem: true, | ||
}); | ||
}); | ||
it("should allow reconfiguration of the options by the same instance", () => { | ||
const logger = new index_1.NodeLogger("Test"); | ||
expect(() => { | ||
testArr.map((num) => { | ||
logger.log({ num }, { ignoreIterators: true }); | ||
logger.log({ num }, { ignoreIterators: false, onlyFirstElem: true }); | ||
}); | ||
}).not.toThrow(); | ||
expect(logger._options).toStrictEqual({ | ||
ignoreIterators: false, | ||
onlyFirstElem: true, | ||
}); | ||
}); | ||
it("missing options provided to the instance must use default values", () => { | ||
const logger = new index_1.NodeLogger("Test"); | ||
expect(logger._options).toStrictEqual(defaultOptions); | ||
//missing one option | ||
testArr.map((num) => { | ||
logger.log({ num }, { ignoreIterators: true }); | ||
}); | ||
expect(logger._options).toStrictEqual({ | ||
...defaultOptions, | ||
ignoreIterators: true, | ||
}); | ||
//all options provided | ||
testArr.map((num) => { | ||
logger.log({ num }, { ignoreIterators: false, onlyFirstElem: true }); | ||
}); | ||
expect(logger._options).toStrictEqual({ | ||
...defaultOptions, | ||
ignoreIterators: false, | ||
onlyFirstElem: true, | ||
}); | ||
//turn back missing to default | ||
testArr.map((num) => { | ||
logger.log({ num }, { ignoreIterators: true }); | ||
}); | ||
expect(logger._options).toStrictEqual({ | ||
...defaultOptions, | ||
ignoreIterators: true, | ||
onlyFirstElem: false, | ||
}); | ||
//turn back all to default | ||
testArr.map((num) => { | ||
logger.log({ num }); | ||
}); | ||
expect(logger._options).toStrictEqual(defaultOptions); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_1 = require("../../index"); | ||
describe("immutability and configurability of option arguments", () => { | ||
const testArr = [1, 2, 3, 4, 5]; | ||
describe("given that a NodeLogger instance is created with options", () => { | ||
it("should NOT allow options to be set by the log func", () => { | ||
const logger = new index_1.NodeLogger("Test", { | ||
ignoreIterators: true, | ||
onlyFirstElem: true, | ||
}); | ||
expect(() => { | ||
testArr.forEach((num) => { | ||
logger.log({ num }, { ignoreIterators: false }); | ||
}); | ||
}).toThrow(/^Cannot redefine _options if the instance is created with options$/); | ||
}); | ||
it("logger instances should retain the original option values", () => { | ||
const logger = new index_1.NodeLogger("Test", { | ||
ignoreIterators: true, | ||
onlyFirstElem: true, | ||
}); | ||
expect(() => { | ||
testArr.forEach((num) => { | ||
logger.log({ num }); | ||
}); | ||
}).not.toThrow(); | ||
expect(logger._options).toStrictEqual({ | ||
ignoreIterators: true, | ||
onlyFirstElem: true, | ||
}); | ||
}); | ||
}); | ||
describe("given that a NodeLogger instance is NOT created with options", () => { | ||
it("should allow options to be set by the log func", () => { | ||
const logger = new index_1.NodeLogger("Test"); | ||
expect(() => { | ||
testArr.map((num) => { | ||
logger.log({ num }, { ignoreIterators: true, onlyFirstElem: true }); | ||
}); | ||
}).not.toThrow(); | ||
expect(logger._options).toStrictEqual({ | ||
ignoreIterators: true, | ||
onlyFirstElem: true, | ||
}); | ||
}); | ||
it("should allow reconfiguration of the options by the same instance", () => { | ||
const logger = new index_1.NodeLogger("Test"); | ||
expect(() => { | ||
testArr.map((num) => { | ||
logger.log({ num }, { ignoreIterators: true }); | ||
logger.log({ num }, { ignoreIterators: false, onlyFirstElem: true }); | ||
}); | ||
}).not.toThrow(); | ||
expect(logger._options).toStrictEqual({ | ||
ignoreIterators: false, | ||
onlyFirstElem: true, | ||
}); | ||
}); | ||
it("missing options provided to the instance must use default values", () => { | ||
const logger = new index_1.NodeLogger("Test"); | ||
const defaultOptions = index_1.NodeLogger.defaultOptions; | ||
expect(logger._options).toStrictEqual(defaultOptions); | ||
//missing one option | ||
testArr.map((num) => { | ||
logger.log({ num }, { ignoreIterators: true }); | ||
}); | ||
expect(logger._options).toStrictEqual({ | ||
...defaultOptions, | ||
ignoreIterators: true, | ||
}); | ||
//all options provided | ||
testArr.map((num) => { | ||
logger.log({ num }, { ignoreIterators: false, onlyFirstElem: true }); | ||
}); | ||
expect(logger._options).toStrictEqual({ | ||
...defaultOptions, | ||
ignoreIterators: false, | ||
onlyFirstElem: true, | ||
}); | ||
//turn back missing to default | ||
testArr.map((num) => { | ||
logger.log({ num }, { ignoreIterators: true }); | ||
}); | ||
expect(logger._options).toStrictEqual({ | ||
...defaultOptions, | ||
ignoreIterators: true, | ||
onlyFirstElem: false, | ||
}); | ||
//turn back all to default | ||
testArr.map((num) => { | ||
logger.log({ num }); | ||
}); | ||
expect(logger._options).toStrictEqual(defaultOptions); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.