analogger 1.2.0 → 1.3.0
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/.eslintrc.cjs +25 -0
- package/.github/workflows/test.yml +24 -0
- package/.github/workflows/versioning.yml +0 -2
- package/.releaserc +27 -0
- package/CHANGELOG.md +1 -0
- package/README.md +19 -0
- package/package.json +11 -10
- package/test/integration.cjs +109 -0
- package/test/unit.cjs +105 -0
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
browser: true,
|
|
4
|
+
node: true
|
|
5
|
+
},
|
|
6
|
+
parser: "@babel/eslint-parser",
|
|
7
|
+
parserOptions: {
|
|
8
|
+
"ecmaVersion": 2020
|
|
9
|
+
},
|
|
10
|
+
rules: {
|
|
11
|
+
"comma-dangle": 0,
|
|
12
|
+
"comma-style": ["error", "last"],
|
|
13
|
+
"no-bitwise": "off",
|
|
14
|
+
"no-console": "off",
|
|
15
|
+
"no-nested-ternary": "off",
|
|
16
|
+
"no-plusplus": "off",
|
|
17
|
+
"prefer-const": "off",
|
|
18
|
+
"spaced-comment": "off",
|
|
19
|
+
"no-debugger": "error",
|
|
20
|
+
"quotes": ["error", "double"],
|
|
21
|
+
"semi": 2,
|
|
22
|
+
"no-unused-vars": "error",
|
|
23
|
+
"max-len": ["error", {code: 200}]
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Versioning AnaLogger
|
|
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
|
package/.releaserc
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"branches": ["test", "main", "next"],
|
|
3
|
+
"dryRun": false,
|
|
4
|
+
"ci": true,
|
|
5
|
+
"debug": true,
|
|
6
|
+
"plugins": [
|
|
7
|
+
["@semantic-release/commit-analyzer",
|
|
8
|
+
{
|
|
9
|
+
"preset": "angular",
|
|
10
|
+
"releaseRules": [
|
|
11
|
+
{"type": "docs", "scope":"README", "release": "patch"},
|
|
12
|
+
{"type": "refactor", "release": "patch"},
|
|
13
|
+
{"type": "style", "release": "patch"}
|
|
14
|
+
],
|
|
15
|
+
"parserOpts": {
|
|
16
|
+
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES"]
|
|
17
|
+
}
|
|
18
|
+
}],
|
|
19
|
+
"@semantic-release/release-notes-generator",
|
|
20
|
+
"@semantic-release/changelog",
|
|
21
|
+
"@semantic-release/npm",
|
|
22
|
+
["@semantic-release/git", {
|
|
23
|
+
"assets": ["package.json", "CHANGELOG.md"],
|
|
24
|
+
"message": "AnaLogger Release: ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
25
|
+
}]
|
|
26
|
+
]
|
|
27
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# [1.3.0](https://github.com/thimpat/analogger/compare/v1.2.0...v1.3.0) (2022-02-08)
|
package/README.md
CHANGED
|
@@ -169,3 +169,22 @@ anaLogger.assert(1 === 2)
|
|
|
169
169
|
anaLogger.assert(()=>true, true)
|
|
170
170
|
anaLogger.assert((a, b)=> a === b, true, 2, 2)
|
|
171
171
|
```
|
|
172
|
+
|
|
173
|
+
<br/><br/>
|
|
174
|
+
|
|
175
|
+
###
|
|
176
|
+
|
|
177
|
+
When an error is detected and should be seen by your app consumers explicitly (for instance, display a dialogue box
|
|
178
|
+
to them), you can hook your logic.
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
anaLogger.setErrorHandlerForUserTarget(function (context/*, ...args*/)
|
|
182
|
+
{
|
|
183
|
+
// Detect whether we are in a browser
|
|
184
|
+
if (context.environnment === anaLogger.ENVIRONMENT_TYPE.BROWSER)
|
|
185
|
+
{
|
|
186
|
+
// When an error is detected in the Browser, the Browser will see this message
|
|
187
|
+
anaLogger.alert(`Users explicitly see this message`)
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "analogger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Js Logger",
|
|
5
5
|
"main": "dist/index-cjs.min.cjs",
|
|
6
6
|
"module": "dist/index-esm.min.mjs",
|
|
@@ -17,6 +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
21
|
"demo": "npm run bundle:prod && node example/cjs/demo.cjs"
|
|
21
22
|
},
|
|
22
23
|
"author": "Patrice Thimothee",
|
|
@@ -26,23 +27,23 @@
|
|
|
26
27
|
"type": "git",
|
|
27
28
|
"url": "https://github.com/thimpat/analogger.git"
|
|
28
29
|
},
|
|
29
|
-
"release": {
|
|
30
|
-
"branches": [
|
|
31
|
-
"main",
|
|
32
|
-
{
|
|
33
|
-
"name": "ci"
|
|
34
|
-
},
|
|
35
|
-
"master"
|
|
36
|
-
]
|
|
37
|
-
},
|
|
38
30
|
"devDependencies": {
|
|
39
31
|
"@babel/core": "^7.17.0",
|
|
40
32
|
"@babel/eslint-parser": "^7.17.0",
|
|
41
33
|
"@babel/preset-env": "^7.16.11",
|
|
42
34
|
"@rollup/plugin-commonjs": "^21.0.1",
|
|
43
35
|
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
36
|
+
"@semantic-release/changelog": "^6.0.1",
|
|
37
|
+
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
38
|
+
"@semantic-release/git": "^10.0.1",
|
|
39
|
+
"@semantic-release/npm": "^9.0.0",
|
|
40
|
+
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
44
41
|
"babel-eslint": "^10.1.0",
|
|
42
|
+
"capture-console": "^1.0.1",
|
|
43
|
+
"chai": "^4.3.6",
|
|
44
|
+
"chai-spies": "^1.0.0",
|
|
45
45
|
"eslint": "^8.8.0",
|
|
46
|
+
"mocha": "^9.2.0",
|
|
46
47
|
"rollup": "^2.67.0",
|
|
47
48
|
"rollup-plugin-delete": "^2.0.0",
|
|
48
49
|
"rollup-plugin-uglify": "^6.0.4",
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const chai = require("chai");
|
|
2
|
+
var capcon = require('capture-console');
|
|
3
|
+
const {anaLogger} = require("../src/cjs/ana-logger.cjs");
|
|
4
|
+
const {LOG_CONTEXT, LOG_TARGETS} = require("../example/cjs/contexts-def.cjs");
|
|
5
|
+
const expect = chai.expect;
|
|
6
|
+
|
|
7
|
+
describe('In the Terminal', function ()
|
|
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
|
+
before(()=>
|
|
15
|
+
{
|
|
16
|
+
anaLogger.setContexts(LOG_CONTEXT);
|
|
17
|
+
anaLogger.setTargets(LOG_TARGETS);
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
beforeEach(()=>
|
|
21
|
+
{
|
|
22
|
+
anaLogger.resetLogHistory()
|
|
23
|
+
anaLogger.keepLogHistory()
|
|
24
|
+
anaLogger.setOptions({silent: false, hideError: false})
|
|
25
|
+
anaLogger.removeOverride()
|
|
26
|
+
anaLogger.removeOverrideError()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
describe('AnaLogger', function ()
|
|
30
|
+
{
|
|
31
|
+
it('should emulate console.log', function ()
|
|
32
|
+
{
|
|
33
|
+
const captured = capcon.captureStdio(function ()
|
|
34
|
+
{
|
|
35
|
+
anaLogger.log(`Test Log example C1`);
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
expect(captured.stdout).to.contain(`Test Log example C1`)
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should hide console output when the console behaviour is overridden', function ()
|
|
42
|
+
{
|
|
43
|
+
const captured = capcon.captureStdio(function ()
|
|
44
|
+
{
|
|
45
|
+
console.log(`Log Before override`);
|
|
46
|
+
anaLogger.setOptions({silent: true})
|
|
47
|
+
anaLogger.overrideConsole()
|
|
48
|
+
console.log(`Log After override`);
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
expect(captured.stdout).to.contain(`Log Before override`)
|
|
52
|
+
expect(captured.stdout).to.not.contain(`Log After override`)
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should hide console output but keep console input in the log history', function ()
|
|
56
|
+
{
|
|
57
|
+
const captured1 = capcon.captureStdio(function ()
|
|
58
|
+
{
|
|
59
|
+
anaLogger.keepLogHistory();
|
|
60
|
+
anaLogger.setOptions({silent: true, hideError: false})
|
|
61
|
+
anaLogger.log(LOG_CONTEXT.C1, `Test Log example something again`);
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const captured2 = capcon.captureStdio(function ()
|
|
65
|
+
{
|
|
66
|
+
console.log(anaLogger.getLogHistory())
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
expect(captured1.stdout).to.not.contain(`Test Log example something again`)
|
|
70
|
+
expect(captured2.stdout).to.contain(`Test Log example something again`)
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should hide console error when the console behaviour is overridden', function ()
|
|
74
|
+
{
|
|
75
|
+
const captured = capcon.captureStdio(function ()
|
|
76
|
+
{
|
|
77
|
+
console.log(`Log Before override`);
|
|
78
|
+
anaLogger.setOptions({hideError: true})
|
|
79
|
+
anaLogger.overrideConsole()
|
|
80
|
+
|
|
81
|
+
console.error(`Error Before override`);
|
|
82
|
+
anaLogger.overrideError()
|
|
83
|
+
console.error(`Error After override`);
|
|
84
|
+
|
|
85
|
+
console.log(`Log After override`);
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
expect(captured.stdout).to.contain(`Log Before override`)
|
|
89
|
+
expect(captured.stdout).to.not.contain(`Error After override`)
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should not show unrelated target logs', function ()
|
|
93
|
+
{
|
|
94
|
+
const captured = capcon.captureStdio(function ()
|
|
95
|
+
{
|
|
96
|
+
anaLogger.setActiveTarget(LOG_TARGETS.DEV3)
|
|
97
|
+
anaLogger.log({context: LOG_CONTEXT.TEST, target: LOG_TARGETS.DEV3, lid: 100001}, `Test Log example with active target`);
|
|
98
|
+
anaLogger.log({context: LOG_CONTEXT.TEST, target: LOG_TARGETS.DEV1, lid: 100002}, `Test Log example with DEV1 target`);
|
|
99
|
+
anaLogger.log(`Test Log example with DEFAULT target`);
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
expect(captured.stdout).to.contain(`Test Log example with active target`)
|
|
103
|
+
expect(captured.stdout).to.contain(`Test Log example with DEFAULT target`)
|
|
104
|
+
expect(captured.stdout).to.not.contain(`Test Log example with DEV1 target`)
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
});
|
|
109
|
+
});
|
package/test/unit.cjs
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const chai = require("chai");
|
|
2
|
+
const expect = chai.expect;
|
|
3
|
+
const spies = require('chai-spies');
|
|
4
|
+
|
|
5
|
+
chai.use(spies);
|
|
6
|
+
// sut
|
|
7
|
+
const {anaLogger} = require("../src/cjs/ana-logger.cjs");
|
|
8
|
+
const {LOG_CONTEXT} = require("../example/cjs/contexts-def.cjs");
|
|
9
|
+
|
|
10
|
+
describe('AnaLogger', function ()
|
|
11
|
+
{
|
|
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
|
+
before(() =>
|
|
16
|
+
{
|
|
17
|
+
anaLogger.setContexts(LOG_CONTEXT);
|
|
18
|
+
anaLogger.setTargets(LOG_TARGETS);
|
|
19
|
+
anaLogger.setActiveTarget(LOG_TARGETS.DEV3)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
beforeEach(() =>
|
|
23
|
+
{
|
|
24
|
+
anaLogger.resetLogHistory()
|
|
25
|
+
anaLogger.keepLogHistory()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe('#log()', function ()
|
|
29
|
+
{
|
|
30
|
+
it('should emulate console.log', function ()
|
|
31
|
+
{
|
|
32
|
+
// Arrange
|
|
33
|
+
anaLogger.setOptions({silent: false, hideError: false})
|
|
34
|
+
|
|
35
|
+
// Act
|
|
36
|
+
anaLogger.log(`Test Log example C1`);
|
|
37
|
+
const output = anaLogger.getLogHistory()
|
|
38
|
+
|
|
39
|
+
// Assert
|
|
40
|
+
expect(output).to.contain(`Test Log example C1`)
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('#assert()', function ()
|
|
45
|
+
{
|
|
46
|
+
it('should evaluate condition expressions', function ()
|
|
47
|
+
{
|
|
48
|
+
const result = anaLogger.assert(1 === 1)
|
|
49
|
+
expect(result).to.be.true
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should detect failing condition expressions', function ()
|
|
53
|
+
{
|
|
54
|
+
const result = anaLogger.assert(1 === 2)
|
|
55
|
+
expect(result).to.be.false
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should evaluate function expressions', function ()
|
|
59
|
+
{
|
|
60
|
+
const result = anaLogger.assert(() => true, true)
|
|
61
|
+
expect(result).to.be.true
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should evaluate more complex function expressions', function ()
|
|
65
|
+
{
|
|
66
|
+
const result = anaLogger.assert((a, b) => a === b, true, 2, 2)
|
|
67
|
+
expect(result).to.be.true
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('#alert()', function ()
|
|
72
|
+
{
|
|
73
|
+
it('should not fail on alert', function ()
|
|
74
|
+
{
|
|
75
|
+
anaLogger.alert(`Hello from alert`, {aaa: 1012})
|
|
76
|
+
expect(anaLogger.getLogHistory()).to.contain(`Hello from alert`)
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('#setLogFormat()', function ()
|
|
81
|
+
{
|
|
82
|
+
/**
|
|
83
|
+
* We use a spy here, but things would have been straightforward with a simple "done" + async on the "it"
|
|
84
|
+
*/
|
|
85
|
+
it('should replace the default formatter function with the given callback when invoking console.log', function ()
|
|
86
|
+
{
|
|
87
|
+
// Arrange
|
|
88
|
+
const methodToCall = {
|
|
89
|
+
myMethod: () => { }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Spy on methodToCall.myMethod to check it has been called
|
|
93
|
+
chai.spy.on(methodToCall, 'myMethod');
|
|
94
|
+
|
|
95
|
+
anaLogger.setLogFormat(
|
|
96
|
+
methodToCall.myMethod
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
console.log(LOG_CONTEXT.C1, `Test Log example C4 with new format`);
|
|
100
|
+
expect(methodToCall.myMethod).to.have.been.called;
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
});
|