analogger 1.3.2 → 1.5.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/.nycrc +3 -3
- package/CHANGELOG.md +9 -1
- package/README.md +35 -9
- package/package.json +22 -4
- package/.github/actions/checkout/action.yml +0 -10
- package/.github/workflows/test.yml +0 -24
- package/.github/workflows/versioning.yml +0 -25
- package/test/integration.cjs +0 -116
- package/test/unit.cjs +0 -455
package/.nycrc
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
## [1.
|
|
1
|
+
## [1.5.1](https://github.com/thimpat/analogger/compare/v1.5.0...v1.5.1) (2022-02-11)
|
|
2
2
|
|
|
3
|
+
# [1.5.0](https://github.com/thimpat/analogger/compare/v1.4.1...v1.5.0) (2022-02-11)
|
|
4
|
+
|
|
5
|
+
## [1.4.1](https://github.com/thimpat/analogger/compare/v1.4.0...v1.4.1) (2022-02-09)
|
|
6
|
+
|
|
7
|
+
# [1.4.0](https://github.com/thimpat/analogger/compare/v1.3.2...v1.4.0) (2022-02-09)
|
|
8
|
+
|
|
9
|
+
## [1.3.2](https://github.com/thimpat/analogger/compare/v1.3.1...v1.3.2) (2022-02-09)
|
|
10
|
+
|
|
3
11
|
## [1.3.1](https://github.com/thimpat/analogger/compare/v1.3.0...v1.3.1) (2022-02-09)
|
|
4
12
|
|
|
5
13
|
# [1.3.0](https://github.com/thimpat/analogger/compare/v1.2.0...v1.3.0) (2022-02-08)
|
package/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
|
|
2
|
-

|
|
3
|
-

|
|
4
|
-

|
|
5
|
-
[](https://
|
|
2
|
+
[](https://github.com/thimpat/analogger/actions/workflows/test.yml)
|
|
3
|
+
[](https://github.com/thimpat/analogger/blob/main/README.md)
|
|
4
|
+
[](https://github.com/thimpat/analogger/actions/workflows/versioning.yml)
|
|
5
|
+
[](https://www.npmjs.com/package/analogger)
|
|
6
|
+
<img alt="semantic-release" src="https://img.shields.io/badge/semantic--release-19.0.2-e10079?logo=semantic-release">
|
|
7
|
+
|
|
8
|
+
---
|
|
6
9
|
|
|
7
10
|
Analogger is a very simple logger for both Node and the Browser.
|
|
8
11
|
It is a library using both CJS and ESM.
|
|
@@ -38,10 +41,14 @@ import {anaLogger} from "analogger"
|
|
|
38
41
|
|
|
39
42
|
### Preview
|
|
40
43
|
|
|
44
|
+
#### Terminal
|
|
41
45
|

|
|
42
46
|
|
|
47
|
+
#### Inspector
|
|
43
48
|

|
|
44
49
|
|
|
50
|
+
#### DOM
|
|
51
|
+

|
|
45
52
|
<br/>
|
|
46
53
|
|
|
47
54
|
## API
|
|
@@ -70,7 +77,26 @@ Display the browser native message box if run from it; otherwise, it displays th
|
|
|
70
77
|
|
|
71
78
|
<br/>
|
|
72
79
|
|
|
73
|
-
###
|
|
80
|
+
### setOptions()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
| **Options** | **default** | **Description** |
|
|
84
|
+
|--------------------|-------------|------------------------------------------------------------------------------------|
|
|
85
|
+
| silent | false | _No log will be displayed (only errors)_ |
|
|
86
|
+
| hideError | false | _Hide errors from console_ |
|
|
87
|
+
| hideHookMessage | false | _Hide the automatic message shown when some native console methods are overridden_ |
|
|
88
|
+
| showPassingTests | true | _Show Live test results_ |
|
|
89
|
+
| logToDom | undefined | _display log in a DOM container_ |
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
// No hook alert message + Log messages in the div #analogger
|
|
94
|
+
anaLogger.setOptions({hideHookMessage: true, logToDom: "#analogger"})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
<br/>
|
|
98
|
+
|
|
99
|
+
### overrideConsole()
|
|
74
100
|
|
|
75
101
|
```javascript
|
|
76
102
|
anaLogger.setOptions({silent: true, hideError: false})
|
|
@@ -151,10 +177,10 @@ const LOG_TARGETS = {ALL: "ALL", DEV1: "TOM", DEV2: "TIM", USER: "USER"};
|
|
|
151
177
|
anaLogger.setContexts(LOG_CONTEXTS);
|
|
152
178
|
anaLogger.setActiveTarget(LOG_TARGETS.DEV1); // <- You are DEV1
|
|
153
179
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
180
|
+
anaLogger.log({target: LOG_TARGETS.DEV1}, `Testing log 1`); // You will see this
|
|
181
|
+
anaLogger.log({target: LOG_TARGETS.DEV2}, `Testing log 2`); // You will not see this
|
|
182
|
+
anaLogger.log({context: LOG_CONTEXTS.STANDARD}, `Testing log 3`); // You will see this
|
|
183
|
+
anaLogger.log(`Testing log 4`); // You will see this. No context = LOG_CONTEXTS.ALL
|
|
158
184
|
|
|
159
185
|
|
|
160
186
|
anaLogger.log(LOG_CONTEXTS.C1, `Test Log example C1`); // You will see this
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "analogger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Js Logger",
|
|
5
5
|
"main": "dist/index-cjs.min.cjs",
|
|
6
6
|
"module": "dist/index-esm.min.mjs",
|
|
@@ -17,12 +17,22 @@
|
|
|
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": "nyc mocha",
|
|
20
|
+
"test": "npm run bundle:prod && nyc mocha --exit --sort",
|
|
21
|
+
"server:start": "http-server.cmd -c-1 -s -p 9880 ./ > log.log",
|
|
22
|
+
"manual:check": "http-server.cmd -c-1 -p 9877 -o example/index.html ./ ",
|
|
23
|
+
"manual:test": "concurrently --success first --kill-others \"npm run test\" \"npm run server:start\"",
|
|
21
24
|
"demo": "npm run bundle:prod && node example/cjs/demo.cjs"
|
|
22
25
|
},
|
|
23
26
|
"author": "Patrice Thimothee",
|
|
24
27
|
"license": "MIT",
|
|
25
28
|
"homepage": "https://github.com/thimpat/analogger/blob/main/README.md",
|
|
29
|
+
"keywords": [
|
|
30
|
+
"console",
|
|
31
|
+
"log",
|
|
32
|
+
"error",
|
|
33
|
+
"log analyser",
|
|
34
|
+
"productivity"
|
|
35
|
+
],
|
|
26
36
|
"repository": {
|
|
27
37
|
"type": "git",
|
|
28
38
|
"url": "https://github.com/thimpat/analogger.git"
|
|
@@ -43,15 +53,22 @@
|
|
|
43
53
|
"chai": "^4.3.6",
|
|
44
54
|
"chai-arrays": "^2.2.0",
|
|
45
55
|
"chai-spies": "^1.0.0",
|
|
56
|
+
"chromedriver": "^2.33.0",
|
|
57
|
+
"chromium": "^3.0.3",
|
|
58
|
+
"concurrently": "^7.0.0",
|
|
46
59
|
"eslint": "^8.8.0",
|
|
60
|
+
"http-server": "^14.1.0",
|
|
61
|
+
"jsdom": "19.0.0",
|
|
62
|
+
"jsdom-global": "3.0.2",
|
|
47
63
|
"mocha": "^9.2.0",
|
|
48
64
|
"nyc": "^15.1.0",
|
|
49
65
|
"rollup": "^2.67.0",
|
|
66
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
50
67
|
"rollup-plugin-delete": "^2.0.0",
|
|
51
68
|
"rollup-plugin-uglify": "^6.0.4",
|
|
52
69
|
"semantic-release": "^19.0.2",
|
|
53
70
|
"sinon": "^13.0.1",
|
|
54
|
-
"to-esm": "^1.6.
|
|
71
|
+
"to-esm": "^1.6.5"
|
|
55
72
|
},
|
|
56
73
|
"dependencies": {
|
|
57
74
|
"chalk": "^5.0.0",
|
|
@@ -59,6 +76,7 @@
|
|
|
59
76
|
"color-convert": "^2.0.1",
|
|
60
77
|
"color-convert-cjs": "npm:color-convert@^2.0.1",
|
|
61
78
|
"rgb-hex": "^4.0.0",
|
|
62
|
-
"rgb-hex-cjs": "npm:rgb-hex@^3.0.0"
|
|
79
|
+
"rgb-hex-cjs": "npm:rgb-hex@^3.0.0",
|
|
80
|
+
"selenium-webdriver": "^3.6.0"
|
|
63
81
|
}
|
|
64
82
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
name: Test
|
|
2
|
-
env:
|
|
3
|
-
ANALOGGER_APP_NAME: "release/analogger"
|
|
4
|
-
on:
|
|
5
|
-
push:
|
|
6
|
-
branches:
|
|
7
|
-
- "**"
|
|
8
|
-
paths-ignore:
|
|
9
|
-
- "**.md"
|
|
10
|
-
- ".vscode/**"
|
|
11
|
-
jobs:
|
|
12
|
-
set-version:
|
|
13
|
-
runs-on: [self-hosted]
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v2
|
|
16
|
-
- name: Check out Git repository
|
|
17
|
-
uses: thimpat/analogger/.github/actions/checkout@ci
|
|
18
|
-
- name: Install dependencies
|
|
19
|
-
shell: powershell
|
|
20
|
-
run: npm install
|
|
21
|
-
- name: Test
|
|
22
|
-
shell: powershell
|
|
23
|
-
run: |
|
|
24
|
-
npm test
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
name: Build
|
|
2
|
-
env:
|
|
3
|
-
ANALOGGER_APP_NAME: "release/analogger"
|
|
4
|
-
on:
|
|
5
|
-
push:
|
|
6
|
-
branches:
|
|
7
|
-
- main
|
|
8
|
-
- ci
|
|
9
|
-
paths-ignore:
|
|
10
|
-
- "**.md"
|
|
11
|
-
- ".vscode/**"
|
|
12
|
-
jobs:
|
|
13
|
-
set-version:
|
|
14
|
-
runs-on: [self-hosted]
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/checkout@v2
|
|
17
|
-
- name: Check out Git repository
|
|
18
|
-
uses: thimpat/analogger/.github/actions/checkout@ci
|
|
19
|
-
- name: Install dependencies
|
|
20
|
-
shell: powershell
|
|
21
|
-
run: npm install
|
|
22
|
-
- name: Upgrade version
|
|
23
|
-
shell: powershell
|
|
24
|
-
run: |
|
|
25
|
-
npx semantic-release
|
package/test/integration.cjs
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
const chai = require("chai");
|
|
2
|
-
var capcon = require('capture-console');
|
|
3
|
-
const {anaLogger} = require("../src/cjs/ana-logger.cjs");
|
|
4
|
-
const {LOG_CONTEXTS, LOG_TARGETS} = require("../example/cjs/contexts-def.cjs");
|
|
5
|
-
const expect = chai.expect;
|
|
6
|
-
|
|
7
|
-
describe('In the Terminal', function ()
|
|
8
|
-
{
|
|
9
|
-
before(()=>
|
|
10
|
-
{
|
|
11
|
-
anaLogger.setContexts(LOG_CONTEXTS);
|
|
12
|
-
anaLogger.setTargets(LOG_TARGETS);
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
beforeEach(()=>
|
|
16
|
-
{
|
|
17
|
-
anaLogger.resetLogHistory()
|
|
18
|
-
anaLogger.keepLogHistory()
|
|
19
|
-
anaLogger.setOptions({silent: false, hideError: false})
|
|
20
|
-
anaLogger.removeOverride()
|
|
21
|
-
anaLogger.removeOverrideError()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
describe('AnaLogger', function ()
|
|
25
|
-
{
|
|
26
|
-
it('should emulate console.log', function ()
|
|
27
|
-
{
|
|
28
|
-
const captured = capcon.captureStdio(function ()
|
|
29
|
-
{
|
|
30
|
-
anaLogger.log(`Test Log example C1`);
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
expect(captured.stdout).to.contain(`Test Log example C1`)
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should hide console output when the console behaviour is overridden', function (done)
|
|
37
|
-
{
|
|
38
|
-
const captured = capcon.captureStdio(function ()
|
|
39
|
-
{
|
|
40
|
-
console.log(`Log Before override`);
|
|
41
|
-
anaLogger.setOptions({silent: true})
|
|
42
|
-
anaLogger.overrideConsole()
|
|
43
|
-
console.log(`Log After override`);
|
|
44
|
-
done()
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
expect(captured.stdout).to.contain(`Log Before override`)
|
|
48
|
-
expect(captured.stdout).to.not.contain(`Log After override`)
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should hide console output but keep console input in the log history', function ()
|
|
52
|
-
{
|
|
53
|
-
const captured1 = capcon.captureStdio(function ()
|
|
54
|
-
{
|
|
55
|
-
anaLogger.keepLogHistory();
|
|
56
|
-
anaLogger.setOptions({silent: true, hideError: false})
|
|
57
|
-
anaLogger.log(LOG_CONTEXTS.C1, `Test Log example something again`);
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
const captured2 = capcon.captureStdio(function ()
|
|
61
|
-
{
|
|
62
|
-
console.log(anaLogger.getLogHistory())
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
expect(captured1.stdout).to.not.contain(`Test Log example something again`)
|
|
66
|
-
expect(captured2.stdout).to.contain(`Test Log example something again`)
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should hide console error when the console behaviour is overridden', function ()
|
|
70
|
-
{
|
|
71
|
-
const captured = capcon.captureStdio(function ()
|
|
72
|
-
{
|
|
73
|
-
console.log(`Log Before override`);
|
|
74
|
-
anaLogger.setOptions({hideError: true})
|
|
75
|
-
anaLogger.overrideConsole()
|
|
76
|
-
|
|
77
|
-
console.error(`Error Before override`);
|
|
78
|
-
anaLogger.overrideError()
|
|
79
|
-
console.error(`Error After override`);
|
|
80
|
-
|
|
81
|
-
console.log(`Log After override`);
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
expect(captured.stdout).to.contain(`Log Before override`)
|
|
85
|
-
expect(captured.stdout).to.not.contain(`Error After override`)
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should not show unrelated target logs', function ()
|
|
89
|
-
{
|
|
90
|
-
const captured = capcon.captureStdio(function ()
|
|
91
|
-
{
|
|
92
|
-
anaLogger.setActiveTarget(LOG_TARGETS.DEV3)
|
|
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`);
|
|
95
|
-
anaLogger.log(`Test Log example with DEFAULT target`);
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
expect(captured.stdout).to.contain(`Test Log example with active target`)
|
|
99
|
-
expect(captured.stdout).to.contain(`Test Log example with DEFAULT target`)
|
|
100
|
-
expect(captured.stdout).to.not.contain(`Test Log example with DEV1 target`)
|
|
101
|
-
});
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
});
|
package/test/unit.cjs
DELETED
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
const chai = require("chai");
|
|
2
|
-
const assertArrays = require("chai-arrays")
|
|
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
|
-
|
|
14
|
-
const spies = require('chai-spies');
|
|
15
|
-
|
|
16
|
-
chai.use(spies);
|
|
17
|
-
chai.use(assertArrays)
|
|
18
|
-
|
|
19
|
-
// sut
|
|
20
|
-
const {anaLogger} = require("../src/cjs/ana-logger.cjs");
|
|
21
|
-
const {LOG_CONTEXTS, LOG_TARGETS} = require("../example/cjs/contexts-def.cjs");
|
|
22
|
-
|
|
23
|
-
describe('AnaLogger', function ()
|
|
24
|
-
{
|
|
25
|
-
before(() =>
|
|
26
|
-
{
|
|
27
|
-
anaLogger.setContexts(LOG_CONTEXTS);
|
|
28
|
-
anaLogger.setTargets(LOG_TARGETS);
|
|
29
|
-
anaLogger.setActiveTarget(LOG_TARGETS.DEV3)
|
|
30
|
-
anaLogger.removeOverride({error: true})
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
beforeEach(() =>
|
|
34
|
-
{
|
|
35
|
-
alert = sinon.spy()
|
|
36
|
-
chai.spy.on(myStub, 'myMethod');
|
|
37
|
-
|
|
38
|
-
anaLogger.resetLogHistory()
|
|
39
|
-
anaLogger.keepLogHistory()
|
|
40
|
-
anaLogger.resetLogFormatter();
|
|
41
|
-
})
|
|
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
|
-
|
|
89
|
-
describe('#log()', function ()
|
|
90
|
-
{
|
|
91
|
-
it('should emulate console.log', function ()
|
|
92
|
-
{
|
|
93
|
-
// Arrange
|
|
94
|
-
anaLogger.setOptions({silent: false, hideError: false})
|
|
95
|
-
|
|
96
|
-
// Act
|
|
97
|
-
anaLogger.log(`Test Log example C1`);
|
|
98
|
-
const output = anaLogger.getLogHistory()
|
|
99
|
-
|
|
100
|
-
// Assert
|
|
101
|
-
expect(output).to.contain(`Test Log example C1`)
|
|
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
|
-
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
describe('#assert()', function ()
|
|
274
|
-
{
|
|
275
|
-
it('should evaluate condition expressions', function ()
|
|
276
|
-
{
|
|
277
|
-
const result = anaLogger.assert(1 === 1)
|
|
278
|
-
expect(result).to.be.true
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it('should detect failing condition expressions', function ()
|
|
282
|
-
{
|
|
283
|
-
const result = anaLogger.assert(1 === 2)
|
|
284
|
-
expect(result).to.be.false
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('should evaluate function expressions', function ()
|
|
288
|
-
{
|
|
289
|
-
const result = anaLogger.assert(() => true, true)
|
|
290
|
-
expect(result).to.be.true
|
|
291
|
-
});
|
|
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
|
-
|
|
299
|
-
it('should evaluate more complex function expressions', function ()
|
|
300
|
-
{
|
|
301
|
-
const result = anaLogger.assert((a, b) => a === b, true, 2, 2)
|
|
302
|
-
expect(result).to.be.true
|
|
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
|
-
});
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
describe('#overrideConsole()', function ()
|
|
313
|
-
{
|
|
314
|
-
it('should override the console behaviour', function ()
|
|
315
|
-
{
|
|
316
|
-
anaLogger.overrideConsole({error: true})
|
|
317
|
-
console.log(`Test 1`)
|
|
318
|
-
expect(anaLogger.getLogHistory()).to.contain(`Test 1`)
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
describe('#setLogFormat()', function ()
|
|
323
|
-
{
|
|
324
|
-
/**
|
|
325
|
-
* We use a spy here, but things would have been straightforward with a simple "done" + async on the "it"
|
|
326
|
-
*/
|
|
327
|
-
it('should replace the default formatter function with the given callback when invoking console.log', function ()
|
|
328
|
-
{
|
|
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
|
-
);
|
|
341
|
-
|
|
342
|
-
console.log(LOG_CONTEXTS.C1, `Test Log example C4 with new format`);
|
|
343
|
-
expect(myStub.myMethod).to.have.been.called;
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it("should reset the formatter to its first value", () =>
|
|
347
|
-
{
|
|
348
|
-
anaLogger.setLogFormat(
|
|
349
|
-
() => "If you see this the test has failed"
|
|
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
|
-
});
|
|
362
|
-
|
|
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`);
|
|
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
|
-
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
});
|