|
@@ -298,7 +298,7 @@ describe('Logger Helpers', () => {
|
|
|
}
|
|
|
const end = Date.now();
|
|
|
const timestamps = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry[0]);
|
|
|
expect(timestamps.length).toBe(10);
|
|
|
for (const timestamp of timestamps) {
|
|
@@ -323,7 +323,7 @@ describe('Logger Helpers', () => {
|
|
|
];
|
|
|
logger.debug(...record.slice(1));
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records.length).toBe(1);
|
|
|
expect(records[0]).toEqual(record);
|
|
@@ -344,7 +344,7 @@ describe('Logger Helpers', () => {
|
|
|
];
|
|
|
logger.debug(' te%cst ', 'color: #fff', ...args);
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records.length).toBe(1);
|
|
|
expect(records[0]).toEqual((['debug', 'te%cst', 'color: #fff'] as any[]).concat(args));
|
|
@@ -371,7 +371,7 @@ describe('Logger Helpers', () => {
|
|
|
];
|
|
|
logger.debug(...record.slice(1));
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records.length).toBe(1);
|
|
|
expect(records[0]).toEqual(record);
|
|
@@ -391,25 +391,38 @@ describe('Logger Helpers', () => {
|
|
|
];
|
|
|
logger.debug(...record.slice(1));
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records.length).toBe(1);
|
|
|
expect(records[0]).toEqual(record);
|
|
|
});
|
|
|
|
|
|
- it('serialises confidential types sanitised', () => {
|
|
|
+ it('serialises confidential types sanitised, if requested', () => {
|
|
|
const logger = new MemoryLogger();
|
|
|
|
|
|
// Ensure 'Confidential' messages are being sanitised.
|
|
|
const confidential = new TestConfidential();
|
|
|
logger.debug(confidential, confidential, confidential);
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records.length).toBe(1);
|
|
|
expect(records[0]).toEqual(['debug', 'censored', 'censored', 'censored']);
|
|
|
});
|
|
|
|
|
|
+ it('serialises confidential types as is, if requested', () => {
|
|
|
+ const logger = new MemoryLogger();
|
|
|
+
|
|
|
+ // Ensure 'Confidential' messages are being sanitised.
|
|
|
+ const confidential = new TestConfidential();
|
|
|
+ logger.debug(confidential, confidential, confidential);
|
|
|
+ const records = JSON
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(false)))
|
|
|
+ .map((entry) => entry.slice(1));
|
|
|
+ expect(records.length).toBe(1);
|
|
|
+ expect(records[0]).toEqual(['debug', 'uncensored', 'uncensored', 'uncensored']);
|
|
|
+ });
|
|
|
+
|
|
|
it('serialises exceptions', () => {
|
|
|
const logger = new MemoryLogger();
|
|
|
|
|
@@ -417,7 +430,7 @@ describe('Logger Helpers', () => {
|
|
|
const error = new Error('WTF!');
|
|
|
logger.error(error);
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records.length).toBe(1);
|
|
|
expect(records[0]).toEqual(['error', error.toString()]);
|
|
@@ -433,7 +446,7 @@ describe('Logger Helpers', () => {
|
|
|
const blob = new Blob([JSON.stringify({ a: 10 })], { type: 'application/json'} );
|
|
|
logger.debug(buffer, array, blob);
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records.length).toBe(1);
|
|
|
expect(records[0]).toEqual([
|
|
@@ -450,7 +463,7 @@ describe('Logger Helpers', () => {
|
|
|
// Ensure instances are being represented with their name.
|
|
|
logger.debug(logger);
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records.length).toBe(1);
|
|
|
expect(records[0]).toEqual(['debug', '[MemoryLogger]']);
|
|
@@ -469,7 +482,7 @@ describe('Logger Helpers', () => {
|
|
|
};
|
|
|
logger.debug(object);
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records.length).toBe(1);
|
|
|
expect(records[0]).toEqual(['debug', object]);
|
|
@@ -486,7 +499,7 @@ describe('Logger Helpers', () => {
|
|
|
];
|
|
|
logger.debug(array);
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records.length).toBe(1);
|
|
|
expect(records[0]).toEqual(['debug', array]);
|
|
@@ -500,7 +513,7 @@ describe('Logger Helpers', () => {
|
|
|
logger.debug(i);
|
|
|
}
|
|
|
const records = JSON
|
|
|
- .parse(JSON.stringify(logger.getRecords(), MemoryLogger.replacer))
|
|
|
+ .parse(JSON.stringify(logger.getRecords(), logger.getReplacer(true)))
|
|
|
.map((entry) => entry.slice(1));
|
|
|
expect(records).toEqual([
|
|
|
['debug', 8],
|