@approval-tests/approvals 7.5.7

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