@approval-tests/approvals 7.5.11 → 7.5.13
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/bin/index.d.ts +1 -1
- package/bin/index.js +1 -1
- package/package.json +9 -4
- package/bin/index.ts +0 -108
- package/lib/AUtils.ts +0 -178
- package/lib/Approvals.ts +0 -321
- package/lib/Core/Namer.ts +0 -14
- package/lib/Core/Options.ts +0 -94
- package/lib/Core/Reporter.ts +0 -13
- package/lib/Core/Writer.ts +0 -5
- package/lib/FileApprover.ts +0 -116
- package/lib/FinalMessages.ts +0 -16
- package/lib/Logs/ApprovedFileLog.ts +0 -38
- package/lib/Logs/FailedFileLog.ts +0 -36
- package/lib/Logs/LogUtils.ts +0 -44
- package/lib/ManualNamer.ts +0 -12
- package/lib/Namer.ts +0 -28
- package/lib/Providers/BeforeEachVerifierBase.ts +0 -68
- package/lib/Providers/Jest/CombinationApprovals.ts +0 -161
- package/lib/Providers/Jest/JestApprovals.ts +0 -50
- package/lib/Providers/Jest/JestNamer.ts +0 -15
- package/lib/Providers/Jest/JestReporter.ts +0 -25
- package/lib/Providers/Jest/JestSetup.ts +0 -40
- package/lib/Providers/Mocha/MochaApprovals.ts +0 -74
- package/lib/Providers/Mocha/MochaNamer.ts +0 -84
- package/lib/Providers/OptionalFramework.ts +0 -11
- package/lib/Providers/Vitest/VitestApprovals.ts +0 -39
- package/lib/Providers/Vitest/VitestNamer.ts +0 -27
- package/lib/Providers/Vitest/VitestReporter.ts +0 -25
- package/lib/Reporting/DiffReporterAggregate.ts +0 -36
- package/lib/Reporting/GenericDiffReporterBase.ts +0 -154
- package/lib/Reporting/ReportByOpeningTheReceivedFile.ts +0 -22
- package/lib/Reporting/ReportLaunchingCircuitBreaker.ts +0 -40
- package/lib/Reporting/ReporterFactory.ts +0 -85
- package/lib/Reporting/Reporters/beyondcompareReporter.ts +0 -30
- package/lib/Reporting/Reporters/codiumReporter.ts +0 -26
- package/lib/Reporting/Reporters/copycommandReporter.ts +0 -46
- package/lib/Reporting/Reporters/diffmergeReporter.ts +0 -25
- package/lib/Reporting/Reporters/donothingReporter.ts +0 -13
- package/lib/Reporting/Reporters/gitdiffReporter.ts +0 -28
- package/lib/Reporting/Reporters/icdiffReporter.ts +0 -10
- package/lib/Reporting/Reporters/kdiff3Reporter.ts +0 -10
- package/lib/Reporting/Reporters/kompareReporter.ts +0 -10
- package/lib/Reporting/Reporters/meldReporter.ts +0 -10
- package/lib/Reporting/Reporters/multiReporter.ts +0 -55
- package/lib/Reporting/Reporters/nodediffReporter.ts +0 -61
- package/lib/Reporting/Reporters/opendiffReporter.ts +0 -10
- package/lib/Reporting/Reporters/p4mergeReporter.ts +0 -39
- package/lib/Reporting/Reporters/tortoisemergeReporter.ts +0 -25
- package/lib/Reporting/Reporters/vimdiffReporter.ts +0 -25
- package/lib/Reporting/Reporters/visualstudioReporter.ts +0 -48
- package/lib/Reporting/Reporters/vscodeReporter.ts +0 -26
- package/lib/Scrubbers/DateScrubber.ts +0 -83
- package/lib/Scrubbers/Scrubbers.ts +0 -106
- package/lib/StringWriter.ts +0 -73
- package/lib/Utilities/ConsoleUtils.ts +0 -15
- package/lib/Utilities/JestUtils.ts +0 -5
- package/lib/Utilities/Logger/LoggingInstance.ts +0 -247
- package/lib/Utilities/Logger/SimpleLogger.ts +0 -83
- package/lib/Utilities/Logger/SimpleLoggerApprovals.ts +0 -15
- package/lib/Utilities/Logger/StringWrapper.ts +0 -12
- package/lib/Utilities/Logger/Wrapper.ts +0 -27
- package/lib/Utilities/Printers.ts +0 -77
- package/lib/Utilities/StringUtils.ts +0 -8
- package/lib/Writers/BinaryWriter.ts +0 -42
- package/lib/config.ts +0 -95
- package/lib/osTools.ts +0 -11
- package/lib/postRunCleanup.ts +0 -63
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { DateScrubber } from "./DateScrubber";
|
|
2
|
-
|
|
3
|
-
export type Scrubber = (t: string) => string;
|
|
4
|
-
|
|
5
|
-
type ReplacementFunction = (index: number) => string;
|
|
6
|
-
|
|
7
|
-
function _replaceRegex(
|
|
8
|
-
text: string,
|
|
9
|
-
regex: RegExp,
|
|
10
|
-
replacement: ReplacementFunction,
|
|
11
|
-
): string {
|
|
12
|
-
const capturedGuids: string[] = [];
|
|
13
|
-
|
|
14
|
-
const result = text.replace(regex, (match) => {
|
|
15
|
-
if (capturedGuids.indexOf(match) < 0) {
|
|
16
|
-
capturedGuids.push(match);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const index = capturedGuids.indexOf(match) + 1;
|
|
20
|
-
return replacement(index);
|
|
21
|
-
});
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class Scrubbers {
|
|
26
|
-
static createReqexScrubber(
|
|
27
|
-
regex: RegExp,
|
|
28
|
-
replacement: string | ReplacementFunction,
|
|
29
|
-
): Scrubber {
|
|
30
|
-
if (typeof replacement === "function") {
|
|
31
|
-
return (t) => _replaceRegex(t, regex, replacement as ReplacementFunction);
|
|
32
|
-
} else {
|
|
33
|
-
const replacementString = replacement as string;
|
|
34
|
-
return (t) => _replaceRegex(t, regex, () => replacementString);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static createGuidScrubber(): Scrubber {
|
|
39
|
-
const guidReqex: RegExp =
|
|
40
|
-
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
|
|
41
|
-
return this.createReqexScrubber(guidReqex, (t) => `<guid_${t}>`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* This method exists as a convenient way to get an example scrubber for you to use.
|
|
46
|
-
* To use this template, simply inline the method in your IDE.
|
|
47
|
-
*/
|
|
48
|
-
static templates = class {
|
|
49
|
-
static regexScrubberWithLambda(): Scrubber {
|
|
50
|
-
return Scrubbers.createReqexScrubber(
|
|
51
|
-
/your pattern here: [a-zA-Z]+d{4}/gi,
|
|
52
|
-
(t) => `<your replacement_${t}>`,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static regexScrubber(): Scrubber {
|
|
57
|
-
return Scrubbers.createReqexScrubber(
|
|
58
|
-
/your pattern here: [a-zA-Z]+d{4}/gi,
|
|
59
|
-
`<your replacement>`,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
static dateScrubber(): Scrubber {
|
|
64
|
-
return DateScrubber.getScrubberFor("2014/05/13 16:30:59.786");
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
static noScrubber(data) {
|
|
68
|
-
return data;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
static guidScrubber(data: string) {
|
|
72
|
-
const guidRegex =
|
|
73
|
-
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
|
|
74
|
-
|
|
75
|
-
const capturedGuids: string[] = [];
|
|
76
|
-
|
|
77
|
-
const result = data.replace(guidRegex, function (match: string) {
|
|
78
|
-
// The arguments are:
|
|
79
|
-
// 1: The whole match (string)
|
|
80
|
-
// 2..n+1: The captures (string or undefined)
|
|
81
|
-
// n+2: Starting position of match (0 = start)
|
|
82
|
-
// n+3: The subject string.
|
|
83
|
-
// (n = number of capture groups)
|
|
84
|
-
|
|
85
|
-
if (capturedGuids.indexOf(match) < 0) {
|
|
86
|
-
capturedGuids.push(match);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const index = capturedGuids.indexOf(match) + 1;
|
|
90
|
-
|
|
91
|
-
return `guid_${index}`;
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return result;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
static multiScrubber(scrubbers: Scrubber[]) {
|
|
98
|
-
return function (data) {
|
|
99
|
-
scrubbers.forEach(function (scrubber) {
|
|
100
|
-
data = scrubber(data);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
return data;
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
package/lib/StringWriter.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import * as autils from "./AUtils";
|
|
4
|
-
import { Config } from "./config";
|
|
5
|
-
import { sync } from "mkdirp";
|
|
6
|
-
import { Writer } from "./Core/Writer";
|
|
7
|
-
|
|
8
|
-
const lineEndingRegex = new RegExp("\r?\n", "g");
|
|
9
|
-
|
|
10
|
-
function normalizeLineEndings(
|
|
11
|
-
lineEnding: string | any,
|
|
12
|
-
value: string | any,
|
|
13
|
-
): string {
|
|
14
|
-
if (autils.isBinaryFile(value)) {
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
return value.replace(lineEndingRegex, lineEnding);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class StringWriter implements Writer {
|
|
21
|
-
private config: Partial<Config>;
|
|
22
|
-
private ext: string;
|
|
23
|
-
public outputText: string;
|
|
24
|
-
|
|
25
|
-
constructor(config: Partial<Config>, outputText: string, ext?: string) {
|
|
26
|
-
if (typeof outputText !== "string") {
|
|
27
|
-
throw new Error(
|
|
28
|
-
`The outputText provided is not a 'string' value but is a typeof ${typeof outputText}`,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this.config = config;
|
|
33
|
-
this.ext = ext || "txt";
|
|
34
|
-
this.outputText = outputText;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getFileExtension(): string {
|
|
38
|
-
return this.ext;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
write(filePath: string): void {
|
|
42
|
-
const dir = path.dirname(path.normalize(filePath));
|
|
43
|
-
if (!fs.existsSync(dir)) {
|
|
44
|
-
sync(dir);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
this.config.normalizeLineEndingsTo !== false &&
|
|
49
|
-
this.config.normalizeLineEndingsTo !== undefined
|
|
50
|
-
) {
|
|
51
|
-
this.outputText = normalizeLineEndings(
|
|
52
|
-
this.config.normalizeLineEndingsTo as string,
|
|
53
|
-
this.outputText,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (this.config.appendEOL) {
|
|
58
|
-
const CRLF = "\r\n";
|
|
59
|
-
const LF = "\n";
|
|
60
|
-
|
|
61
|
-
const endsWithCRLF = this.outputText.endsWith(CRLF);
|
|
62
|
-
const endsWithLF = this.outputText.endsWith(LF);
|
|
63
|
-
|
|
64
|
-
if (!endsWithCRLF && !endsWithLF) {
|
|
65
|
-
this.outputText += this.config.EOL;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
fs.writeFileSync(filePath, this.outputText);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export default StringWriter;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { gray, green, red, yellow } from "ansi-colors";
|
|
2
|
-
|
|
3
|
-
export function yellowText(text: string): string {
|
|
4
|
-
return yellow(text);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function redText(text: string): string {
|
|
8
|
-
return red(text);
|
|
9
|
-
}
|
|
10
|
-
export function greenText(text: string): string {
|
|
11
|
-
return green(text);
|
|
12
|
-
}
|
|
13
|
-
export function grayText(text: string): string {
|
|
14
|
-
return gray(text);
|
|
15
|
-
}
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import { StringWrapper } from "./StringWrapper";
|
|
2
|
-
|
|
3
|
-
class Toggles {
|
|
4
|
-
public queries: boolean;
|
|
5
|
-
public messages: boolean;
|
|
6
|
-
public variables: boolean;
|
|
7
|
-
public hourglass: boolean;
|
|
8
|
-
public events: boolean;
|
|
9
|
-
public markers: boolean;
|
|
10
|
-
|
|
11
|
-
constructor(show: boolean) {
|
|
12
|
-
this.queries = show;
|
|
13
|
-
this.messages = show;
|
|
14
|
-
this.variables = show;
|
|
15
|
-
this.hourglass = show;
|
|
16
|
-
this.markers = show;
|
|
17
|
-
this.events = show;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function printType(value: any) {
|
|
22
|
-
return `<${value.constructor.name}>`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getCallingMethod(additional_stack: number) {
|
|
26
|
-
const re = /at ([^(]+) \(/g;
|
|
27
|
-
const stack = `${new Error().stack}`;
|
|
28
|
-
const lines = stack.split("\n");
|
|
29
|
-
const stackDepth = 2 + additional_stack;
|
|
30
|
-
const line = lines[stackDepth];
|
|
31
|
-
const aRegexResult = re.exec(line) ?? [];
|
|
32
|
-
const name = aRegexResult[1] || aRegexResult[2];
|
|
33
|
-
return name;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class LoggingInstance {
|
|
37
|
-
logger: (text: string) => void;
|
|
38
|
-
private counter: number = 0;
|
|
39
|
-
private tabs: number = 0;
|
|
40
|
-
private toggles = new Toggles(true);
|
|
41
|
-
public logStackTraces: boolean = true;
|
|
42
|
-
private logWithTimestamps: boolean = true;
|
|
43
|
-
public timer: () => Date;
|
|
44
|
-
private previousTimestamp: Date | null = null;
|
|
45
|
-
|
|
46
|
-
constructor() {
|
|
47
|
-
this.logger = (s) => process.stdout.write(s);
|
|
48
|
-
this.timer = () => new Date();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
logToString(): StringWrapper {
|
|
52
|
-
const stringWrapper = new StringWrapper();
|
|
53
|
-
this.logWithTimestamps = false;
|
|
54
|
-
this.logStackTraces = false;
|
|
55
|
-
this.logger = (t) => stringWrapper.append(t);
|
|
56
|
-
return stringWrapper;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
useMarkers<T>(
|
|
60
|
-
additional_stack: number,
|
|
61
|
-
code: () => T,
|
|
62
|
-
parameters: string | (() => string) = "",
|
|
63
|
-
logReturnValue: boolean = false,
|
|
64
|
-
): T {
|
|
65
|
-
if (!this.toggles.markers) {
|
|
66
|
-
return code();
|
|
67
|
-
}
|
|
68
|
-
const name = getCallingMethod(additional_stack + 1);
|
|
69
|
-
let parameterText = "";
|
|
70
|
-
if (typeof parameters === "function") {
|
|
71
|
-
parameterText = parameters();
|
|
72
|
-
} else {
|
|
73
|
-
parameterText = parameters;
|
|
74
|
-
}
|
|
75
|
-
this.logLine(`=> ${name}(${parameterText})`);
|
|
76
|
-
const returnValue = this.withTabbing(code);
|
|
77
|
-
if (typeof parameters === "function") {
|
|
78
|
-
parameterText = parameters();
|
|
79
|
-
} else {
|
|
80
|
-
parameterText = "";
|
|
81
|
-
}
|
|
82
|
-
let returnText = "";
|
|
83
|
-
if (logReturnValue) {
|
|
84
|
-
returnText = `: ${returnValue}`;
|
|
85
|
-
}
|
|
86
|
-
this.logLine(`<= ${name}(${parameterText})${returnText}`);
|
|
87
|
-
return returnValue;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
variable(name: string, value: any, showTypes: boolean) {
|
|
91
|
-
if (!this.toggles.variables) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
let toType = (_value: any, _spacing = "") => "";
|
|
96
|
-
if (showTypes) {
|
|
97
|
-
toType = (value, spacing = " ") => `${spacing}${printType(value)}`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (Array.isArray(value)) {
|
|
101
|
-
this.logLine(
|
|
102
|
-
`variable: ${name}${toType(value, "")}.length = ${value.length}`,
|
|
103
|
-
);
|
|
104
|
-
this.withTabbing(() => {
|
|
105
|
-
value.forEach((v, i) => {
|
|
106
|
-
this.logger(`${this.getTabs()}${name}[${i}] = ${v}${toType(v)}\n`);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
} else {
|
|
110
|
-
this.logLine(`variable: ${name} = ${value}${toType(value)}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private logLine(text: string, use_timestamps: boolean = true) {
|
|
115
|
-
if (this.counter != 0) {
|
|
116
|
-
this.logger("\n");
|
|
117
|
-
}
|
|
118
|
-
this.counter = 0;
|
|
119
|
-
const timestamp = use_timestamps ? this.getTimestamp() : "";
|
|
120
|
-
const output_message = `${timestamp}${this.getTabs()}${text}\n`;
|
|
121
|
-
this.logger(output_message);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private getTabs() {
|
|
125
|
-
return " ".repeat(this.tabs);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
private withTabbing<T>(code: () => T): T {
|
|
129
|
-
this.tabs += 1;
|
|
130
|
-
const returnValue = code();
|
|
131
|
-
this.tabs -= 1;
|
|
132
|
-
return returnValue;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
hourglass() {
|
|
136
|
-
if (!this.toggles.hourglass) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
this.counter += 1;
|
|
141
|
-
if (this.counter == 1) {
|
|
142
|
-
this.logger(`${this.getTabs()}.`);
|
|
143
|
-
} else if (this.counter == 100) {
|
|
144
|
-
this.logger("10\n");
|
|
145
|
-
this.counter = 0;
|
|
146
|
-
} else if (this.counter % 10 == 0) {
|
|
147
|
-
const digit = this.counter / 10;
|
|
148
|
-
this.logger(`${digit}`);
|
|
149
|
-
} else {
|
|
150
|
-
this.logger(".");
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
showAll(show: boolean) {
|
|
155
|
-
this.toggles = new Toggles(show);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
event(event_name: string) {
|
|
159
|
-
if (!this.toggles.events) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
this.logLine(`event: ${event_name}`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
showQueries(show: boolean) {
|
|
166
|
-
this.toggles.queries = show;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
showMarkers(show: boolean) {
|
|
170
|
-
this.toggles.markers = show;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
showEvents(show: boolean) {
|
|
174
|
-
this.toggles.events = show;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
showMessages(show: boolean) {
|
|
178
|
-
this.toggles.messages = show;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
showVariables(show: boolean) {
|
|
182
|
-
this.toggles.variables = show;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
showHourglass(show: boolean) {
|
|
186
|
-
this.toggles.hourglass = show;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
warning(exception: Error | string) {
|
|
190
|
-
const warning_stars = "*".repeat(91);
|
|
191
|
-
const text = null;
|
|
192
|
-
this.logLine(warning_stars, false);
|
|
193
|
-
if (this.logWithTimestamps) {
|
|
194
|
-
this.logLine("", true);
|
|
195
|
-
}
|
|
196
|
-
if (text) {
|
|
197
|
-
this.logLine(`Message:${text}`, false);
|
|
198
|
-
}
|
|
199
|
-
if (exception) {
|
|
200
|
-
let stack_trace = "";
|
|
201
|
-
if (this.logStackTraces) {
|
|
202
|
-
// todo: grab stack trace
|
|
203
|
-
stack_trace = exception.toString();
|
|
204
|
-
} else {
|
|
205
|
-
stack_trace = `${exception}`;
|
|
206
|
-
}
|
|
207
|
-
this.logLine(stack_trace, false);
|
|
208
|
-
}
|
|
209
|
-
this.logLine(warning_stars, false);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
query(queryText: string) {
|
|
213
|
-
if (!this.toggles.queries) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
this.logLine(`Sql: ${queryText}`);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
message(messageText: string) {
|
|
220
|
-
if (!this.toggles.messages) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
this.logLine(`message: ${messageText}`);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
showTimestamps(show: boolean) {
|
|
227
|
-
this.logWithTimestamps = show;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
private getTimestamp() {
|
|
231
|
-
if (!this.logWithTimestamps) {
|
|
232
|
-
return "";
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const time1 = this.timer();
|
|
236
|
-
const time = time1.toISOString();
|
|
237
|
-
let diff_millseconds = 0;
|
|
238
|
-
if (this.previousTimestamp != null) {
|
|
239
|
-
diff_millseconds = time1.getTime() - this.previousTimestamp.getTime();
|
|
240
|
-
}
|
|
241
|
-
const diff_display = `~${String(diff_millseconds).padStart(6, "0")}ms`;
|
|
242
|
-
let time_text = `${time}`.replace("T", " ").substring(0, 19);
|
|
243
|
-
const timestamp = `[${time_text} ${diff_display}] `;
|
|
244
|
-
this.previousTimestamp = time1;
|
|
245
|
-
return timestamp;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { SingleWrapper, Wrapper } from "./Wrapper";
|
|
2
|
-
|
|
3
|
-
import { LoggingInstance } from "./LoggingInstance";
|
|
4
|
-
import { StringWrapper } from "./StringWrapper";
|
|
5
|
-
|
|
6
|
-
export class SimpleLogger {
|
|
7
|
-
static _wrapper: Wrapper<LoggingInstance> = new SingleWrapper(
|
|
8
|
-
new LoggingInstance(),
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
static showQueries(show: boolean) {
|
|
12
|
-
this._wrapper.get().showQueries(show);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
static showMarkers(show: boolean) {
|
|
16
|
-
this._wrapper.get().showMarkers(show);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static showEvents(show: boolean) {
|
|
20
|
-
this._wrapper.get().showEvents(show);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static showMessages(show: boolean) {
|
|
24
|
-
this._wrapper.get().showMessages(show);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static showVariables(show: boolean) {
|
|
28
|
-
this._wrapper.get().showVariables(show);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static showHourglass(show: boolean) {
|
|
32
|
-
this._wrapper.get().showHourglass(show);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static registerLogger(log_method: (text: string) => void): void {
|
|
36
|
-
this._wrapper.get().logger = log_method;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static logToString(): StringWrapper {
|
|
40
|
-
this._wrapper = new SingleWrapper(new LoggingInstance());
|
|
41
|
-
return SimpleLogger._wrapper.get().logToString();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static useMarkers<T>(
|
|
45
|
-
code: () => T,
|
|
46
|
-
parameters: string | (() => string) = "",
|
|
47
|
-
logReturnValue: boolean = false,
|
|
48
|
-
): T {
|
|
49
|
-
return this._wrapper.get().useMarkers(1, code, parameters, logReturnValue);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static variable(name: string, value: any, show_types: boolean = false) {
|
|
53
|
-
SimpleLogger._wrapper.get().variable(name, value, show_types);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static hourglass() {
|
|
57
|
-
this._wrapper.get().hourglass();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static showAll(show: boolean) {
|
|
61
|
-
this._wrapper.get().showAll(show);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
static event(text: string) {
|
|
65
|
-
this._wrapper.get().event(text);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
static query(queryText: string) {
|
|
69
|
-
this._wrapper.get().query(queryText);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
static message(messageText: string) {
|
|
73
|
-
this._wrapper.get().message(messageText);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
static warning(exception: string | Error) {
|
|
77
|
-
this._wrapper.get().warning(exception);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
static showTimestamps(show: boolean) {
|
|
81
|
-
this._wrapper.get().showTimestamps(show);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Options } from "../../Core/Options";
|
|
2
|
-
import { SimpleLogger } from "./SimpleLogger";
|
|
3
|
-
import { verify } from "../../Providers/Jest/JestApprovals";
|
|
4
|
-
|
|
5
|
-
export function verifySimpleLogger(
|
|
6
|
-
testName: string,
|
|
7
|
-
code: () => void,
|
|
8
|
-
options?: Options,
|
|
9
|
-
) {
|
|
10
|
-
test(testName, () => {
|
|
11
|
-
const output = SimpleLogger.logToString();
|
|
12
|
-
code();
|
|
13
|
-
verify(output, options);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export abstract class Wrapper<Type> {
|
|
2
|
-
abstract get(): Type;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export class SingleWrapper<Type> extends Wrapper<Type> {
|
|
6
|
-
protected instance: Type;
|
|
7
|
-
constructor(instance: Type) {
|
|
8
|
-
super();
|
|
9
|
-
this.instance = instance;
|
|
10
|
-
}
|
|
11
|
-
get(): Type {
|
|
12
|
-
return this.instance;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class ThreadedWrapper<Type> extends Wrapper<Type> {
|
|
17
|
-
protected local: Type;
|
|
18
|
-
protected generator: () => Type;
|
|
19
|
-
constructor(generator: () => Type) {
|
|
20
|
-
super();
|
|
21
|
-
this.generator = generator;
|
|
22
|
-
this.local = generator();
|
|
23
|
-
}
|
|
24
|
-
get(): Type {
|
|
25
|
-
return this.local;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
VariationsForEachParameter,
|
|
3
|
-
Printer,
|
|
4
|
-
} from "../Providers/Jest/CombinationApprovals";
|
|
5
|
-
|
|
6
|
-
export function printArray<T>(
|
|
7
|
-
header: string,
|
|
8
|
-
list: T[],
|
|
9
|
-
formatter?: (element: T) => string,
|
|
10
|
-
): string {
|
|
11
|
-
function getDefaultFormatter() {
|
|
12
|
-
let count = 0;
|
|
13
|
-
return (t: T): string => `[${count++}] => ${t}`;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
formatter = formatter || getDefaultFormatter();
|
|
17
|
-
let text = "";
|
|
18
|
-
if (header) {
|
|
19
|
-
text = header + "\n\n\n";
|
|
20
|
-
}
|
|
21
|
-
for (let t of list) {
|
|
22
|
-
text += formatter(t) + "\n";
|
|
23
|
-
}
|
|
24
|
-
return text;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function printJson(data: any) {
|
|
28
|
-
return JSON.stringify(data, null, " ");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function printCombinations<T extends any[]>(
|
|
32
|
-
func: Printer<T>,
|
|
33
|
-
...variations: VariationsForEachParameter<T>
|
|
34
|
-
): string {
|
|
35
|
-
const parameterCombinations = generateParameterCombinations(variations);
|
|
36
|
-
|
|
37
|
-
let text = "";
|
|
38
|
-
parameterCombinations.forEach((parameters) => {
|
|
39
|
-
text += print(func, parameters);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return text;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function generateParameterCombinations<T extends any[]>(
|
|
46
|
-
variations: VariationsForEachParameter<T>,
|
|
47
|
-
parameterCombinations: T[] = [],
|
|
48
|
-
index: number = 0,
|
|
49
|
-
currentParameterCombination: T = [] as unknown as T,
|
|
50
|
-
): T[] {
|
|
51
|
-
const allParametersProcessed = index === variations.length;
|
|
52
|
-
if (allParametersProcessed) {
|
|
53
|
-
parameterCombinations.push(currentParameterCombination);
|
|
54
|
-
return parameterCombinations;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
for (let nextParameter of variations[index]) {
|
|
58
|
-
generateParameterCombinations(
|
|
59
|
-
variations,
|
|
60
|
-
parameterCombinations,
|
|
61
|
-
index + 1,
|
|
62
|
-
[...currentParameterCombination, nextParameter],
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return parameterCombinations;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function print<T extends any[]>(func: Printer<T>, parameters: T) {
|
|
70
|
-
let output;
|
|
71
|
-
try {
|
|
72
|
-
output = func(...parameters);
|
|
73
|
-
} catch (e) {
|
|
74
|
-
output = `${e}`;
|
|
75
|
-
}
|
|
76
|
-
return `[${parameters}] => ${output}\n`;
|
|
77
|
-
}
|