-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.js
96 lines (75 loc) · 2.46 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const expect = require("chai").expect;
const log4js = require("log4js");
const log4js_extend = require("./log4js-extend");
const recording = require('./node_modules/log4js/lib/appenders/recording');
const path = require("path");
const vm = require("vm");
describe("Logging", () => {
before(() => {
log4js.configure({
appenders: { vcr: { type: "recording" } },
categories: { default: { appenders: ['vcr'], level: 'info' } }
});
log4js_extend(log4js, {
path: null,
format: "at @name (@file:@line:@column)"
});
});
afterEach(() => {
recording.erase();
});
it("No Scope", function () {
const logger = log4js.getLogger();
logger.info("test");
const events = recording.replay();
const result = events[0].data.join(" ");
expect(result).to.equal("test at <anonymous> (" + __filename + ":28:12)");
});
it("In Scope", function () {
const logger = log4js.getLogger();
!function scope() {
logger.info("test");
}();
const events = recording.replay();
const result = events[0].data.join(" ");
expect(result).to.equal("test at scope (" + __filename + ":39:14)");
});
it("In Object", function () {
const logger = log4js.getLogger();
!{
method: function scope() {
logger.info("test");
}
}.method();
const events = recording.replay();
const result = events[0].data.join(" ");
expect(result).to.equal("test at method (" + __filename + ":52:16)");
});
it("Relative Path", function () {
log4js_extend(log4js, {
path: __dirname
});
const logger = log4js.getLogger();
logger.info("test");
const events = recording.replay();
const result = events[0].data.join(" ");
expect(result).to.equal("test at <anonymous> (" + path.relative(__dirname, __filename) + ":67:12)");
});
it("No Options", function () {
log4js_extend(log4js);
const logger = log4js.getLogger();
logger.info("test");
const events = recording.replay();
const result = events[0].data.join(" ");
expect(result).to.equal("test at <anonymous> (" + __filename + ":78:12)");
});
it("trace.file empty", function () {
log4js_extend(log4js);
var logger = log4js.getLogger();
var ctx = vm.createContext({logger: logger});
vm.runInContext("logger.info(\"test\")", ctx, "");
const events = recording.replay();
const result = events[0].data.join(" ");
expect(result).to.equal("test at <anonymous> (:1:8)");
});
});