analogger 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/test.yml +1 -1
- package/.github/workflows/versioning.yml +1 -1
- package/.nycrc +20 -0
- package/CHANGELOG.md +8 -0
- package/README.md +14 -4
- package/ci.md +0 -0
- package/package.json +6 -3
- package/test/integration.cjs +18 -11
- package/test/unit.cjs +368 -18
package/.nycrc
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lines": 95,
|
|
3
|
+
"statements": 95,
|
|
4
|
+
"functions": 95,
|
|
5
|
+
"branches": 50,
|
|
6
|
+
"reporter": [
|
|
7
|
+
"json",
|
|
8
|
+
"text-summary"
|
|
9
|
+
],
|
|
10
|
+
"exclude": [
|
|
11
|
+
"coverage/**",
|
|
12
|
+
"docs/**",
|
|
13
|
+
"test{,s}/**",
|
|
14
|
+
"test{,-*}.{js,cjs,mjs,ts}",
|
|
15
|
+
"lib/browser/**",
|
|
16
|
+
"package-scripts.js",
|
|
17
|
+
"scripts/**"
|
|
18
|
+
],
|
|
19
|
+
"check-coverage": true
|
|
20
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
+
## [1.4.1](https://github.com/thimpat/analogger/compare/v1.4.0...v1.4.1) (2022-02-09)
|
|
2
|
+
|
|
3
|
+
# [1.4.0](https://github.com/thimpat/analogger/compare/v1.3.2...v1.4.0) (2022-02-09)
|
|
4
|
+
|
|
5
|
+
## [1.3.2](https://github.com/thimpat/analogger/compare/v1.3.1...v1.3.2) (2022-02-09)
|
|
6
|
+
|
|
7
|
+
## [1.3.1](https://github.com/thimpat/analogger/compare/v1.3.0...v1.3.1) (2022-02-09)
|
|
8
|
+
|
|
1
9
|
# [1.3.0](https://github.com/thimpat/analogger/compare/v1.2.0...v1.3.0) (2022-02-08)
|
package/README.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
[](https://badge.fury.io/js/analogger)
|
|
6
|
+
|
|
2
7
|
Analogger is a very simple logger for both Node and the Browser.
|
|
3
8
|
It is a library using both CJS and ESM.
|
|
4
9
|
It serves as a packaging example of **hybrid (CJS/ESM) module**.
|
|
@@ -172,10 +177,11 @@ anaLogger.assert((a, b)=> a === b, true, 2, 2)
|
|
|
172
177
|
|
|
173
178
|
<br/><br/>
|
|
174
179
|
|
|
175
|
-
###
|
|
180
|
+
### setErrorHandlerForUserTarget()
|
|
176
181
|
|
|
177
|
-
When an error is detected and should be seen by your app consumers explicitly (for instance, display a
|
|
178
|
-
|
|
182
|
+
When an error is detected and should be seen by your app consumers explicitly (for instance, you want to display a
|
|
183
|
+
dialogue box
|
|
184
|
+
to them), you can set a handler here. All other console.error will be working as usual (logging messages).
|
|
179
185
|
|
|
180
186
|
```javascript
|
|
181
187
|
anaLogger.setErrorHandlerForUserTarget(function (context/*, ...args*/)
|
|
@@ -186,5 +192,9 @@ to them), you can hook your logic.
|
|
|
186
192
|
// When an error is detected in the Browser, the Browser will see this message
|
|
187
193
|
anaLogger.alert(`Users explicitly see this message`)
|
|
188
194
|
}
|
|
189
|
-
})
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
anaLogger.setActiveTarget(LOG_TARGETS.USER);
|
|
198
|
+
anaLogger.error({target: LOG_TARGETS.USER}, "Salut user!"); // Display an alert box
|
|
199
|
+
anaLogger.error("Hi user!"); // Log the message to the inspector
|
|
190
200
|
```
|
package/ci.md
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "analogger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Js Logger",
|
|
5
5
|
"main": "dist/index-cjs.min.cjs",
|
|
6
6
|
"module": "dist/index-esm.min.mjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"bundle:prod:cjs": "rollup --config rollup-cjs.config.js",
|
|
18
18
|
"bundle:prod:esm": "rollup --config rollup-esm.config.js",
|
|
19
19
|
"bundle:prod": "npm run convert-cjs:esm && npm run convert-cjs:browser && npm run bundle:prod:cjs && npm run bundle:prod:esm",
|
|
20
|
-
"test": "mocha",
|
|
20
|
+
"test": "nyc mocha",
|
|
21
21
|
"demo": "npm run bundle:prod && node example/cjs/demo.cjs"
|
|
22
22
|
},
|
|
23
23
|
"author": "Patrice Thimothee",
|
|
@@ -41,14 +41,17 @@
|
|
|
41
41
|
"babel-eslint": "^10.1.0",
|
|
42
42
|
"capture-console": "^1.0.1",
|
|
43
43
|
"chai": "^4.3.6",
|
|
44
|
+
"chai-arrays": "^2.2.0",
|
|
44
45
|
"chai-spies": "^1.0.0",
|
|
45
46
|
"eslint": "^8.8.0",
|
|
46
47
|
"mocha": "^9.2.0",
|
|
48
|
+
"nyc": "^15.1.0",
|
|
47
49
|
"rollup": "^2.67.0",
|
|
48
50
|
"rollup-plugin-delete": "^2.0.0",
|
|
49
51
|
"rollup-plugin-uglify": "^6.0.4",
|
|
50
52
|
"semantic-release": "^19.0.2",
|
|
51
|
-
"
|
|
53
|
+
"sinon": "^13.0.1",
|
|
54
|
+
"to-esm": "^1.6.4"
|
|
52
55
|
},
|
|
53
56
|
"dependencies": {
|
|
54
57
|
"chalk": "^5.0.0",
|
package/test/integration.cjs
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
const chai = require("chai");
|
|
2
2
|
var capcon = require('capture-console');
|
|
3
3
|
const {anaLogger} = require("../src/cjs/ana-logger.cjs");
|
|
4
|
-
const {
|
|
4
|
+
const {LOG_CONTEXTS, LOG_TARGETS} = require("../example/cjs/contexts-def.cjs");
|
|
5
5
|
const expect = chai.expect;
|
|
6
6
|
|
|
7
7
|
describe('In the Terminal', function ()
|
|
8
8
|
{
|
|
9
|
-
const {anaLogger} = require("../src/cjs/ana-logger.cjs");
|
|
10
|
-
|
|
11
|
-
const LOG_CONTEXT = {STANDARD: {}, TEST: {color: "#B18904", symbol: "⏰"}, C1: null, C2: null, C3: null, DEFAULT: {}}
|
|
12
|
-
const LOG_TARGETS = {ALL: "ALL", DEV1: "TOM", DEV2: "TIM", DEV3: "ME", USER: "USER"}
|
|
13
|
-
|
|
14
9
|
before(()=>
|
|
15
10
|
{
|
|
16
|
-
anaLogger.setContexts(
|
|
11
|
+
anaLogger.setContexts(LOG_CONTEXTS);
|
|
17
12
|
anaLogger.setTargets(LOG_TARGETS);
|
|
18
13
|
})
|
|
19
14
|
|
|
@@ -38,7 +33,7 @@ describe('In the Terminal', function ()
|
|
|
38
33
|
expect(captured.stdout).to.contain(`Test Log example C1`)
|
|
39
34
|
});
|
|
40
35
|
|
|
41
|
-
it('should hide console output when the console behaviour is overridden', function ()
|
|
36
|
+
it('should hide console output when the console behaviour is overridden', function (done)
|
|
42
37
|
{
|
|
43
38
|
const captured = capcon.captureStdio(function ()
|
|
44
39
|
{
|
|
@@ -46,6 +41,7 @@ describe('In the Terminal', function ()
|
|
|
46
41
|
anaLogger.setOptions({silent: true})
|
|
47
42
|
anaLogger.overrideConsole()
|
|
48
43
|
console.log(`Log After override`);
|
|
44
|
+
done()
|
|
49
45
|
})
|
|
50
46
|
|
|
51
47
|
expect(captured.stdout).to.contain(`Log Before override`)
|
|
@@ -58,7 +54,7 @@ describe('In the Terminal', function ()
|
|
|
58
54
|
{
|
|
59
55
|
anaLogger.keepLogHistory();
|
|
60
56
|
anaLogger.setOptions({silent: true, hideError: false})
|
|
61
|
-
anaLogger.log(
|
|
57
|
+
anaLogger.log(LOG_CONTEXTS.C1, `Test Log example something again`);
|
|
62
58
|
})
|
|
63
59
|
|
|
64
60
|
const captured2 = capcon.captureStdio(function ()
|
|
@@ -94,8 +90,8 @@ describe('In the Terminal', function ()
|
|
|
94
90
|
const captured = capcon.captureStdio(function ()
|
|
95
91
|
{
|
|
96
92
|
anaLogger.setActiveTarget(LOG_TARGETS.DEV3)
|
|
97
|
-
anaLogger.log({context:
|
|
98
|
-
anaLogger.log({context:
|
|
93
|
+
anaLogger.log({context: LOG_CONTEXTS.TEST, target: LOG_TARGETS.DEV3, lid: 100001}, `Test Log example with active target`);
|
|
94
|
+
anaLogger.log({context: LOG_CONTEXTS.TEST, target: LOG_TARGETS.DEV1, lid: 100002}, `Test Log example with DEV1 target`);
|
|
99
95
|
anaLogger.log(`Test Log example with DEFAULT target`);
|
|
100
96
|
})
|
|
101
97
|
|
|
@@ -104,6 +100,17 @@ describe('In the Terminal', function ()
|
|
|
104
100
|
expect(captured.stdout).to.not.contain(`Test Log example with DEV1 target`)
|
|
105
101
|
});
|
|
106
102
|
|
|
103
|
+
it('should not anything when silent mode is enabled', function ()
|
|
104
|
+
{
|
|
105
|
+
const captured = capcon.captureStdio(function ()
|
|
106
|
+
{
|
|
107
|
+
anaLogger.setOptions({silent: true})
|
|
108
|
+
anaLogger.log(`Test Log example with DEFAULT target`);
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
expect(captured.stdout).to.not.contain(`Test Log example with DEFAULT target`)
|
|
112
|
+
});
|
|
113
|
+
|
|
107
114
|
|
|
108
115
|
});
|
|
109
116
|
});
|
package/test/unit.cjs
CHANGED
|
@@ -1,30 +1,91 @@
|
|
|
1
1
|
const chai = require("chai");
|
|
2
|
+
const assertArrays = require("chai-arrays")
|
|
2
3
|
const expect = chai.expect;
|
|
4
|
+
const sinon = require("sinon");
|
|
5
|
+
|
|
6
|
+
let alert, sandbox;
|
|
7
|
+
|
|
8
|
+
// Arrange
|
|
9
|
+
const myStub = {
|
|
10
|
+
myMethod: () => { }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
const spies = require('chai-spies');
|
|
4
15
|
|
|
5
16
|
chai.use(spies);
|
|
17
|
+
chai.use(assertArrays)
|
|
18
|
+
|
|
6
19
|
// sut
|
|
7
20
|
const {anaLogger} = require("../src/cjs/ana-logger.cjs");
|
|
8
|
-
const {
|
|
21
|
+
const {LOG_CONTEXTS, LOG_TARGETS} = require("../example/cjs/contexts-def.cjs");
|
|
9
22
|
|
|
10
23
|
describe('AnaLogger', function ()
|
|
11
24
|
{
|
|
12
|
-
const LOG_CONTEXT = {STANDARD: {}, TEST: {color: "#B18904", symbol: "⏰"}, C1: null, C2: null, C3: null, DEFAULT: {}}
|
|
13
|
-
const LOG_TARGETS = {ALL: "ALL", DEV1: "TOM", DEV2: "TIM", DEV3: "ME", USER: "USER"}
|
|
14
|
-
|
|
15
25
|
before(() =>
|
|
16
26
|
{
|
|
17
|
-
anaLogger.setContexts(
|
|
27
|
+
anaLogger.setContexts(LOG_CONTEXTS);
|
|
18
28
|
anaLogger.setTargets(LOG_TARGETS);
|
|
19
29
|
anaLogger.setActiveTarget(LOG_TARGETS.DEV3)
|
|
30
|
+
anaLogger.removeOverride({error: true})
|
|
20
31
|
})
|
|
21
32
|
|
|
22
33
|
beforeEach(() =>
|
|
23
34
|
{
|
|
35
|
+
alert = sinon.spy()
|
|
36
|
+
chai.spy.on(myStub, 'myMethod');
|
|
37
|
+
|
|
24
38
|
anaLogger.resetLogHistory()
|
|
25
39
|
anaLogger.keepLogHistory()
|
|
40
|
+
anaLogger.resetLogFormatter();
|
|
26
41
|
})
|
|
27
42
|
|
|
43
|
+
afterEach(()=>
|
|
44
|
+
{
|
|
45
|
+
chai.spy.restore(myStub.myMethod)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
describe('#isContextValid()', function ()
|
|
49
|
+
{
|
|
50
|
+
it('should be true when a valid context object is passed', function ()
|
|
51
|
+
{
|
|
52
|
+
// Arrange
|
|
53
|
+
const context = LOG_CONTEXTS.TEST
|
|
54
|
+
// Act
|
|
55
|
+
const result = anaLogger.isContextValid(context)
|
|
56
|
+
// Assert
|
|
57
|
+
expect(result).to.be.true
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should be false when an invalid context object is passed', function ()
|
|
61
|
+
{
|
|
62
|
+
// Arrange
|
|
63
|
+
const context = {}
|
|
64
|
+
// Act
|
|
65
|
+
const result = anaLogger.isContextValid(context)
|
|
66
|
+
// Assert
|
|
67
|
+
expect(result).to.be.false
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should be false when a null context is passed', function ()
|
|
71
|
+
{
|
|
72
|
+
// Act
|
|
73
|
+
const result = anaLogger.isContextValid(null)
|
|
74
|
+
// Assert
|
|
75
|
+
expect(result).to.be.false
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('#setOptions()', function ()
|
|
80
|
+
{
|
|
81
|
+
it('should have an option to silent the log', function ()
|
|
82
|
+
{
|
|
83
|
+
anaLogger.setOptions({silent: true})
|
|
84
|
+
const options = anaLogger.getOptions()
|
|
85
|
+
expect(options.silent).to.be.true
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
28
89
|
describe('#log()', function ()
|
|
29
90
|
{
|
|
30
91
|
it('should emulate console.log', function ()
|
|
@@ -39,6 +100,174 @@ describe('AnaLogger', function ()
|
|
|
39
100
|
// Assert
|
|
40
101
|
expect(output).to.contain(`Test Log example C1`)
|
|
41
102
|
});
|
|
103
|
+
|
|
104
|
+
it('should understand values passed with context', function ()
|
|
105
|
+
{
|
|
106
|
+
// Act
|
|
107
|
+
anaLogger.log(LOG_CONTEXTS.C1, `Test Log example C1`);
|
|
108
|
+
|
|
109
|
+
// Assert
|
|
110
|
+
expect(anaLogger.getLogHistory()).to.contain(`Test Log example C1`)
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should understand values passed with context as value of object', function ()
|
|
114
|
+
{
|
|
115
|
+
// Act
|
|
116
|
+
anaLogger.log({context: LOG_CONTEXTS.C1}, `Test Log example C1`);
|
|
117
|
+
|
|
118
|
+
// Assert
|
|
119
|
+
expect(anaLogger.getLogHistory()).to.contain(`Test Log example C1`)
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should understand values passed with context defined as null', function ()
|
|
123
|
+
{
|
|
124
|
+
// Act
|
|
125
|
+
anaLogger.log({context: null}, `Test Log example C1`);
|
|
126
|
+
|
|
127
|
+
// Assert
|
|
128
|
+
expect(anaLogger.getLogHistory()).to.contain(`Test Log example C1`)
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should populate history even though the hidelog option is on', function ()
|
|
132
|
+
{
|
|
133
|
+
anaLogger.setOptions({hideLog: true})
|
|
134
|
+
|
|
135
|
+
// Act
|
|
136
|
+
anaLogger.log({context: LOG_CONTEXTS.C1, lid: 123456789233}, `The hidden log`);
|
|
137
|
+
|
|
138
|
+
// Assert
|
|
139
|
+
expect(anaLogger.getLogHistory()).to.contain(`The hidden log`)
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should not capture or display log from another defined target', function ()
|
|
143
|
+
{
|
|
144
|
+
anaLogger.setActiveTarget(LOG_TARGETS.DEV3)
|
|
145
|
+
anaLogger.log({target: LOG_TARGETS.DEV1}, `I am for DEV1`);
|
|
146
|
+
|
|
147
|
+
// Assert
|
|
148
|
+
expect(anaLogger.getLogHistory()).to.not.contain(`I am for DEV1`)
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('should capture logs when no active target is set', function ()
|
|
152
|
+
{
|
|
153
|
+
anaLogger.setActiveTarget(null)
|
|
154
|
+
anaLogger.log({target: LOG_TARGETS.DEV3}, `I am for DEV3`);
|
|
155
|
+
|
|
156
|
+
// Assert
|
|
157
|
+
expect(anaLogger.getLogHistory()).to.contain(`I am for DEV3`)
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should capture logs from the same target', function ()
|
|
161
|
+
{
|
|
162
|
+
anaLogger.setActiveTarget(LOG_TARGETS.DEV3)
|
|
163
|
+
anaLogger.log({target: LOG_TARGETS.DEV3}, `I am for DEV3`);
|
|
164
|
+
|
|
165
|
+
// Assert
|
|
166
|
+
expect(anaLogger.getLogHistory()).to.contain(`I am for DEV3`)
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should capture logs from the same target', function ()
|
|
170
|
+
{
|
|
171
|
+
anaLogger.log(LOG_CONTEXTS.TEST2, `I am for DEV3`);
|
|
172
|
+
|
|
173
|
+
// Assert
|
|
174
|
+
expect(anaLogger.getLogHistory()).to.contain(`I am for DEV3`)
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should truncate some text when too long', function ()
|
|
178
|
+
{
|
|
179
|
+
// Act
|
|
180
|
+
anaLogger.log({
|
|
181
|
+
context: LOG_CONTEXTS.C1,
|
|
182
|
+
lid : 123456789233
|
|
183
|
+
}, `The super long Log ID (lid) will be truncated`);
|
|
184
|
+
|
|
185
|
+
// Assert
|
|
186
|
+
expect(anaLogger.getLogHistory()).to.contain(`C1: (12... )`)
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('#error()', function ()
|
|
193
|
+
{
|
|
194
|
+
it('should not show up when hideError mode is on', function ()
|
|
195
|
+
{
|
|
196
|
+
// Arrange
|
|
197
|
+
anaLogger.setOptions({hideError: true})
|
|
198
|
+
|
|
199
|
+
// Act
|
|
200
|
+
anaLogger.error(`Test Log example C1`);
|
|
201
|
+
|
|
202
|
+
// Assert
|
|
203
|
+
expect(anaLogger.getLogHistory()).to.not.contain(`Test Log example C1`)
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('should not show up when hideError mode is off', function ()
|
|
207
|
+
{
|
|
208
|
+
// Arrange
|
|
209
|
+
anaLogger.setOptions({hideError: false})
|
|
210
|
+
|
|
211
|
+
// Act
|
|
212
|
+
anaLogger.error(`Test Log example C1`);
|
|
213
|
+
|
|
214
|
+
// Assert
|
|
215
|
+
expect(anaLogger.getLogHistory()).to.contain(`Test Log example C1`)
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe('#info()', function ()
|
|
220
|
+
{
|
|
221
|
+
it('should display some log', function ()
|
|
222
|
+
{
|
|
223
|
+
anaLogger.info(`Hello from info`)
|
|
224
|
+
expect(anaLogger.getLogHistory()).to.contain(`Hello from info`)
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('#warn()', function ()
|
|
229
|
+
{
|
|
230
|
+
it('should display some warn', function ()
|
|
231
|
+
{
|
|
232
|
+
anaLogger.warn(`Hello from warn`)
|
|
233
|
+
expect(anaLogger.getLogHistory()).to.contain(`Hello from warn`)
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe('#alert()', function ()
|
|
238
|
+
{
|
|
239
|
+
it('should not fail on alert', function ()
|
|
240
|
+
{
|
|
241
|
+
anaLogger.alert(`Hello from alert`, {aaa: 1012})
|
|
242
|
+
expect(anaLogger.getLogHistory()).to.contain(`Hello from alert`)
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe("in a non-Node environment", function ()
|
|
246
|
+
{
|
|
247
|
+
beforeEach(function ()
|
|
248
|
+
{
|
|
249
|
+
sandbox = sinon.createSandbox();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
it('should be called', function ()
|
|
254
|
+
{
|
|
255
|
+
sandbox
|
|
256
|
+
.stub(anaLogger, "isNode")
|
|
257
|
+
.withArgs("Hello from alert")
|
|
258
|
+
.returns(
|
|
259
|
+
true
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
chai.expect(() => anaLogger.alert(`Hello from alert`)).to.throw(`alert is not defined`);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
afterEach(function ()
|
|
266
|
+
{
|
|
267
|
+
sandbox.restore();
|
|
268
|
+
});
|
|
269
|
+
})
|
|
270
|
+
|
|
42
271
|
});
|
|
43
272
|
|
|
44
273
|
describe('#assert()', function ()
|
|
@@ -61,19 +290,32 @@ describe('AnaLogger', function ()
|
|
|
61
290
|
expect(result).to.be.true
|
|
62
291
|
});
|
|
63
292
|
|
|
293
|
+
it('should fail when function expressions fail', function ()
|
|
294
|
+
{
|
|
295
|
+
const result = anaLogger.assert(() => false, true)
|
|
296
|
+
expect(result).to.be.false
|
|
297
|
+
});
|
|
298
|
+
|
|
64
299
|
it('should evaluate more complex function expressions', function ()
|
|
65
300
|
{
|
|
66
301
|
const result = anaLogger.assert((a, b) => a === b, true, 2, 2)
|
|
67
302
|
expect(result).to.be.true
|
|
68
303
|
});
|
|
304
|
+
|
|
305
|
+
it('should not break the code when an invalid function is passed', function ()
|
|
306
|
+
{
|
|
307
|
+
expect(anaLogger.assert(() => nonExistentFunctionThatIsCalledAnyway(), true, 2, 2)
|
|
308
|
+
).to.be.false
|
|
309
|
+
});
|
|
69
310
|
});
|
|
70
311
|
|
|
71
|
-
describe('#
|
|
312
|
+
describe('#overrideConsole()', function ()
|
|
72
313
|
{
|
|
73
|
-
it('should
|
|
314
|
+
it('should override the console behaviour', function ()
|
|
74
315
|
{
|
|
75
|
-
anaLogger.
|
|
76
|
-
|
|
316
|
+
anaLogger.overrideConsole({error: true})
|
|
317
|
+
console.log(`Test 1`)
|
|
318
|
+
expect(anaLogger.getLogHistory()).to.contain(`Test 1`)
|
|
77
319
|
});
|
|
78
320
|
});
|
|
79
321
|
|
|
@@ -84,21 +326,129 @@ describe('AnaLogger', function ()
|
|
|
84
326
|
*/
|
|
85
327
|
it('should replace the default formatter function with the given callback when invoking console.log', function ()
|
|
86
328
|
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
329
|
+
beforeEach(function ()
|
|
330
|
+
{
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
afterEach(function ()
|
|
334
|
+
{
|
|
335
|
+
chai.spy.restore(myStub.myMethod)
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
anaLogger.setLogFormat(
|
|
339
|
+
myStub.myMethod
|
|
340
|
+
);
|
|
91
341
|
|
|
92
|
-
|
|
93
|
-
|
|
342
|
+
console.log(LOG_CONTEXTS.C1, `Test Log example C4 with new format`);
|
|
343
|
+
expect(myStub.myMethod).to.have.been.called;
|
|
344
|
+
});
|
|
94
345
|
|
|
346
|
+
it("should reset the formatter to its first value", () =>
|
|
347
|
+
{
|
|
95
348
|
anaLogger.setLogFormat(
|
|
96
|
-
|
|
349
|
+
() => "If you see this the test has failed"
|
|
97
350
|
);
|
|
351
|
+
anaLogger.resetLogFormatter();
|
|
352
|
+
anaLogger.log(LOG_CONTEXTS.C1, `Test Log example C4 with new format`);
|
|
353
|
+
expect(anaLogger.getLogHistory()).to.contain(`C1: ( )`)
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
it("should reject invalid formatters", () =>
|
|
357
|
+
{
|
|
358
|
+
const res = anaLogger.setLogFormat(null);
|
|
359
|
+
expect(res).to.be.false
|
|
360
|
+
})
|
|
361
|
+
});
|
|
98
362
|
|
|
99
|
-
|
|
100
|
-
|
|
363
|
+
describe('#releaseLogHistory()', function ()
|
|
364
|
+
{
|
|
365
|
+
it('should not keep log history', function ()
|
|
366
|
+
{
|
|
367
|
+
anaLogger.releaseLogHistory()
|
|
368
|
+
anaLogger.log(`Hello you`)
|
|
369
|
+
expect(anaLogger.getLogHistory().length).to.equal(0)
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
describe('#getLogHistory()', function ()
|
|
374
|
+
{
|
|
375
|
+
it('should return history as a string', function ()
|
|
376
|
+
{
|
|
377
|
+
anaLogger.log(`Hello you`)
|
|
378
|
+
const arr = anaLogger.getLogHistory()
|
|
379
|
+
expect(arr).to.be.string
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('should return history as an array', function ()
|
|
383
|
+
{
|
|
384
|
+
anaLogger.log(`Hello you`)
|
|
385
|
+
const arr = anaLogger.getLogHistory(false)
|
|
386
|
+
expect(arr).to.be.array()
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it('should return history as an array', function ()
|
|
390
|
+
{
|
|
391
|
+
anaLogger.log(`Hello you`)
|
|
392
|
+
const arr = anaLogger.getLogHistory(false)
|
|
393
|
+
expect(arr).to.be.array()
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
describe('#setErrorHandler()', function ()
|
|
398
|
+
{
|
|
399
|
+
it('should replace the error manager', function ()
|
|
400
|
+
{
|
|
401
|
+
anaLogger.setActiveTarget(LOG_TARGETS.USER)
|
|
402
|
+
anaLogger.error({target: LOG_TARGETS.USER}, `Test Error Log`);
|
|
101
403
|
});
|
|
404
|
+
|
|
405
|
+
it('should replace the error manager', function ()
|
|
406
|
+
{
|
|
407
|
+
anaLogger.setErrorHandler(
|
|
408
|
+
myStub.myMethod
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
console.error(`Test Error Log`);
|
|
412
|
+
expect(myStub.myMethod).to.have.been.called;
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('should replace the error manager targeting the user', function ()
|
|
416
|
+
{
|
|
417
|
+
anaLogger.setActiveTarget(LOG_TARGETS.USER)
|
|
418
|
+
anaLogger.setErrorHandler(
|
|
419
|
+
myStub.myMethod
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
anaLogger.error(`Test Error Log`);
|
|
423
|
+
expect(myStub.myMethod).to.have.been.called;
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
describe('#setErrorHandlerForUserTarget()', function ()
|
|
429
|
+
{
|
|
430
|
+
it('should replace the error manager targetting the user', function ()
|
|
431
|
+
{
|
|
432
|
+
anaLogger.setActiveTarget(LOG_TARGETS.USER)
|
|
433
|
+
anaLogger.setErrorHandlerForUserTarget(
|
|
434
|
+
myStub.myMethod
|
|
435
|
+
);
|
|
436
|
+
|
|
437
|
+
anaLogger.error(`Test Error Log`);
|
|
438
|
+
expect(myStub.myMethod).to.have.been.called;
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it('should replace the error manager targeting the user', function ()
|
|
442
|
+
{
|
|
443
|
+
anaLogger.setActiveTarget(LOG_TARGETS.USER)
|
|
444
|
+
anaLogger.setErrorHandlerForUserTarget(
|
|
445
|
+
myStub.myMethod
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
anaLogger.error(`Test Error Log`);
|
|
449
|
+
expect(myStub.myMethod).to.have.been.called;
|
|
450
|
+
});
|
|
451
|
+
|
|
102
452
|
});
|
|
103
453
|
|
|
104
454
|
|