@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,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringUtils = void 0;
4
+ class StringUtils {
5
+ static replaceAll(text, find, replace) {
6
+ while (text.includes(find)) {
7
+ text = text.replace(find, replace);
8
+ }
9
+ return text;
10
+ }
11
+ }
12
+ exports.StringUtils = StringUtils;
@@ -0,0 +1,8 @@
1
+ export class StringUtils {
2
+ static replaceAll(text: string, find: string, replace: string) {
3
+ while (text.includes(find)) {
4
+ text = text.replace(find, replace);
5
+ }
6
+ return text;
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ import { Writer } from "../Core/Writer";
2
+ export declare class BinaryWriter implements Writer {
3
+ private outputData;
4
+ private _ext?;
5
+ constructor(outputData: Buffer);
6
+ getFileExtension(): string;
7
+ write(filePath: string): void;
8
+ }
@@ -0,0 +1,63 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.BinaryWriter = void 0;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const mkdirp_1 = __importDefault(require("mkdirp"));
43
+ const file_type_1 = __importDefault(require("file-type")); // Assuming fileType provides synchronous methods
44
+ class BinaryWriter {
45
+ constructor(outputData) {
46
+ this.outputData = outputData;
47
+ }
48
+ getFileExtension() {
49
+ if (!this._ext) {
50
+ const fileTypeDiscovered = (0, file_type_1.default)(this.outputData);
51
+ this._ext = (fileTypeDiscovered === null || fileTypeDiscovered === void 0 ? void 0 : fileTypeDiscovered.ext) || "blob"; // Assuming synchronous call
52
+ }
53
+ return this._ext;
54
+ }
55
+ write(filePath) {
56
+ const dir = path.dirname(path.normalize(filePath));
57
+ if (!fs.existsSync(dir)) {
58
+ mkdirp_1.default.sync(dir);
59
+ }
60
+ fs.writeFileSync(filePath, this.outputData);
61
+ }
62
+ }
63
+ exports.BinaryWriter = BinaryWriter;
@@ -0,0 +1,31 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import mkdirp from "mkdirp";
4
+ import fileType from "file-type"; // Assuming fileType provides synchronous methods
5
+ import { Writer } from "../Core/Writer";
6
+
7
+ export class BinaryWriter implements Writer {
8
+ private outputData: Buffer;
9
+ private _ext?: string;
10
+
11
+ constructor(outputData: Buffer) {
12
+ this.outputData = outputData;
13
+ }
14
+
15
+ getFileExtension(): string {
16
+ if (!this._ext) {
17
+ const fileTypeDiscovered = fileType(this.outputData);
18
+ this._ext = fileTypeDiscovered?.ext || "blob"; // Assuming synchronous call
19
+ }
20
+ return this._ext;
21
+ }
22
+
23
+ write(filePath: string): void {
24
+ const dir = path.dirname(path.normalize(filePath));
25
+ if (!fs.existsSync(dir)) {
26
+ mkdirp.sync(dir);
27
+ }
28
+
29
+ fs.writeFileSync(filePath, this.outputData);
30
+ }
31
+ }
@@ -0,0 +1,22 @@
1
+ import { Reporter } from "./Core/Reporter";
2
+ export interface Config {
3
+ reporters: (string | Reporter)[];
4
+ normalizeLineEndingsTo: boolean | string;
5
+ failOnLineEndingDifferences: boolean;
6
+ appendEOL: boolean;
7
+ EOL: string;
8
+ errorOnStaleApprovedFiles: boolean;
9
+ shouldIgnoreStaleApprovedFile: (fileName?: string) => boolean;
10
+ stripBOM: boolean;
11
+ forceApproveAll: boolean;
12
+ blockUntilReporterExits: boolean;
13
+ maxLaunches: number;
14
+ cmdOptionOverrides?: any;
15
+ cmdArgs?: string[];
16
+ }
17
+ export declare const defaultConfig: Config;
18
+ export declare function getHomeApprovalConfig(): Config | null;
19
+ export declare function getConfig(configOverrides?: Partial<Config>): Config;
20
+ export declare function configure(overrideOptions?: Partial<Config>): Config;
21
+ export declare function currentConfig(): Config;
22
+ export declare function reset(): void;
package/lib/config.js ADDED
@@ -0,0 +1,106 @@
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.defaultConfig = void 0;
37
+ exports.getHomeApprovalConfig = getHomeApprovalConfig;
38
+ exports.getConfig = getConfig;
39
+ exports.configure = configure;
40
+ exports.currentConfig = currentConfig;
41
+ exports.reset = reset;
42
+ const os = __importStar(require("os"));
43
+ const fs = __importStar(require("fs"));
44
+ const path = __importStar(require("path"));
45
+ const _ = __importStar(require("lodash"));
46
+ const yaml = __importStar(require("js-yaml"));
47
+ const ReportLaunchingCircuitBreaker_1 = require("./Reporting/ReportLaunchingCircuitBreaker");
48
+ // begin-snippet: default_config
49
+ exports.defaultConfig = {
50
+ reporters: [
51
+ "BeyondCompare",
52
+ "diffmerge",
53
+ "p4merge",
54
+ "tortoisemerge",
55
+ "nodediff",
56
+ "opendiff",
57
+ "gitdiff",
58
+ ],
59
+ normalizeLineEndingsTo: false,
60
+ failOnLineEndingDifferences: false,
61
+ appendEOL: true,
62
+ EOL: os.EOL,
63
+ errorOnStaleApprovedFiles: true,
64
+ shouldIgnoreStaleApprovedFile: () => false,
65
+ stripBOM: false,
66
+ forceApproveAll: false,
67
+ blockUntilReporterExits: false,
68
+ maxLaunches: 10,
69
+ };
70
+ // end-snippet
71
+ function getHomeApprovalConfig() {
72
+ const homeConfigPath = path.join(os.homedir(), ".approvalsConfig");
73
+ if (fs.existsSync(homeConfigPath)) {
74
+ const configFileData = fs.readFileSync(homeConfigPath).toString();
75
+ try {
76
+ return yaml.load(configFileData);
77
+ }
78
+ catch (ex) {
79
+ throw new Error("Error parsing " + homeConfigPath + ". " + ex);
80
+ }
81
+ }
82
+ return null;
83
+ }
84
+ let currentConfigObj;
85
+ function getConfig(configOverrides) {
86
+ const homeConfig = getHomeApprovalConfig() || {};
87
+ const resultConfig = _.defaults(configOverrides || {}, currentConfigObj || {}, homeConfig, exports.defaultConfig);
88
+ return resultConfig;
89
+ }
90
+ function configure(overrideOptions) {
91
+ currentConfigObj = getConfig(overrideOptions);
92
+ processConfig(currentConfigObj);
93
+ return currentConfigObj;
94
+ }
95
+ function currentConfig() {
96
+ return currentConfigObj;
97
+ }
98
+ function reset() {
99
+ currentConfigObj = _.defaults({}, getHomeApprovalConfig(), exports.defaultConfig);
100
+ }
101
+ currentConfigObj = getConfig();
102
+ function processConfig(config) {
103
+ if (config.maxLaunches) {
104
+ ReportLaunchingCircuitBreaker_1.ReportLaunchingCircuitBreaker.setMaxLaunch(config.maxLaunches);
105
+ }
106
+ }
package/lib/config.ts ADDED
@@ -0,0 +1,95 @@
1
+ import * as os from "os";
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ import * as _ from "lodash";
5
+ import * as yaml from "js-yaml";
6
+ import { ReportLaunchingCircuitBreaker } from "./Reporting/ReportLaunchingCircuitBreaker";
7
+ import { Reporter } from "./Core/Reporter";
8
+
9
+ export interface Config {
10
+ reporters: (string | Reporter)[];
11
+ normalizeLineEndingsTo: boolean | string;
12
+ failOnLineEndingDifferences: boolean;
13
+ appendEOL: boolean;
14
+ EOL: string;
15
+ errorOnStaleApprovedFiles: boolean;
16
+ shouldIgnoreStaleApprovedFile: (fileName?: string) => boolean;
17
+ stripBOM: boolean;
18
+ forceApproveAll: boolean;
19
+ blockUntilReporterExits: boolean;
20
+ maxLaunches: number;
21
+ cmdOptionOverrides?: any;
22
+ cmdArgs?: string[];
23
+ }
24
+
25
+ // begin-snippet: default_config
26
+ export const defaultConfig: Config = {
27
+ reporters: [
28
+ "BeyondCompare",
29
+ "diffmerge",
30
+ "p4merge",
31
+ "tortoisemerge",
32
+ "nodediff",
33
+ "opendiff",
34
+ "gitdiff",
35
+ ],
36
+ normalizeLineEndingsTo: false,
37
+ failOnLineEndingDifferences: false,
38
+ appendEOL: true,
39
+ EOL: os.EOL,
40
+ errorOnStaleApprovedFiles: true,
41
+ shouldIgnoreStaleApprovedFile: () => false,
42
+ stripBOM: false,
43
+ forceApproveAll: false,
44
+ blockUntilReporterExits: false,
45
+ maxLaunches: 10,
46
+ };
47
+ // end-snippet
48
+
49
+ export function getHomeApprovalConfig(): Config | null {
50
+ const homeConfigPath = path.join(os.homedir(), ".approvalsConfig");
51
+ if (fs.existsSync(homeConfigPath)) {
52
+ const configFileData = fs.readFileSync(homeConfigPath).toString();
53
+ try {
54
+ return yaml.load(configFileData) as Config;
55
+ } catch (ex) {
56
+ throw new Error("Error parsing " + homeConfigPath + ". " + ex);
57
+ }
58
+ }
59
+ return null;
60
+ }
61
+
62
+ let currentConfigObj: Config;
63
+
64
+ export function getConfig(configOverrides?: Partial<Config>): Config {
65
+ const homeConfig = getHomeApprovalConfig() || {};
66
+ const resultConfig = _.defaults(
67
+ configOverrides || {},
68
+ currentConfigObj || {},
69
+ homeConfig,
70
+ defaultConfig,
71
+ );
72
+ return resultConfig as Config;
73
+ }
74
+
75
+ export function configure(overrideOptions?: Partial<Config>): Config {
76
+ currentConfigObj = getConfig(overrideOptions);
77
+ processConfig(currentConfigObj);
78
+ return currentConfigObj;
79
+ }
80
+
81
+ export function currentConfig(): Config {
82
+ return currentConfigObj;
83
+ }
84
+
85
+ export function reset(): void {
86
+ currentConfigObj = _.defaults({}, getHomeApprovalConfig(), defaultConfig);
87
+ }
88
+
89
+ currentConfigObj = getConfig();
90
+
91
+ function processConfig(config: Config): void {
92
+ if (config.maxLaunches) {
93
+ ReportLaunchingCircuitBreaker.setMaxLaunch(config.maxLaunches);
94
+ }
95
+ }
@@ -0,0 +1,5 @@
1
+ export declare const platform: {
2
+ isWindows: boolean;
3
+ isMac: boolean;
4
+ };
5
+ export declare let findProgramPathCommand: string;
package/lib/osTools.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ // Remove the reference path as TypeScript should be configured to recognize node types globally via `tsconfig.json`
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.findProgramPathCommand = exports.platform = void 0;
5
+ // Detect OS-specific features using TypeScript.
6
+ const isWindows = process.platform.startsWith("win");
7
+ exports.platform = {
8
+ isWindows: isWindows,
9
+ isMac: process.platform === "darwin",
10
+ };
11
+ exports.findProgramPathCommand = isWindows ? "where" : "which";
package/lib/osTools.ts ADDED
@@ -0,0 +1,11 @@
1
+ // Remove the reference path as TypeScript should be configured to recognize node types globally via `tsconfig.json`
2
+
3
+ // Detect OS-specific features using TypeScript.
4
+ const isWindows = process.platform.startsWith("win");
5
+
6
+ export const platform = {
7
+ isWindows: isWindows,
8
+ isMac: process.platform === "darwin",
9
+ };
10
+
11
+ export let findProgramPathCommand = isWindows ? "where" : "which";
@@ -0,0 +1 @@
1
+ export declare function postRunCleanup(config: any, approvedFilesMap: any, glob_sync?: any): void;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.postRunCleanup = postRunCleanup;
7
+ const path_1 = __importDefault(require("path"));
8
+ function unique(items) {
9
+ return [...new Set(items)];
10
+ }
11
+ function normalizeFilePath(filePath) {
12
+ return (filePath || "").replace(/\\/g, "/");
13
+ }
14
+ const glob = require("glob");
15
+ function postRunCleanup(config, approvedFilesMap, glob_sync = glob.sync) {
16
+ const options = config;
17
+ if (options.errorOnStaleApprovedFiles) {
18
+ // Don't require glob at the top of the file.
19
+ // this avoids a load of glob if it's not necessary
20
+ // normalize file paths for searching (windows vs *nix)...
21
+ const normalizedApprovedFilePaths = approvedFilesMap.map(normalizeFilePath);
22
+ const getAllDirectoriesOfApprovedFiles = unique(normalizedApprovedFilePaths.map(function (file) {
23
+ return path_1.default.dirname(file);
24
+ })); // get just the directory of each
25
+ let discoveredApprovalFiles = [];
26
+ getAllDirectoriesOfApprovedFiles.forEach(function (folder) {
27
+ return glob_sync(folder + "**/*.approved.*").forEach(function (file) {
28
+ if (discoveredApprovalFiles.indexOf(file) === -1) {
29
+ discoveredApprovalFiles.push(file);
30
+ }
31
+ });
32
+ }); // use 'glob' to find all .approved.* files for each folder.
33
+ discoveredApprovalFiles = discoveredApprovalFiles.map(normalizeFilePath);
34
+ const staleApprovals = discoveredApprovalFiles
35
+ .filter(function (file) {
36
+ if (typeof options.shouldIgnoreStaleApprovedFile === "function") {
37
+ return !options.shouldIgnoreStaleApprovedFile(file);
38
+ }
39
+ return true;
40
+ })
41
+ .filter(function (discoveredFilePath) {
42
+ return normalizedApprovedFilePaths.indexOf(discoveredFilePath) < 0;
43
+ }); // only pull the ones that aren't already in the 'normalizedApprovedFilePaths'
44
+ if (staleApprovals.length) {
45
+ process.exitCode = 1;
46
+ throw new Error("ERROR: Found stale approvals files: \n - " +
47
+ staleApprovals.join("\n - ") +
48
+ "\n");
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,63 @@
1
+ import path from "path";
2
+
3
+ function unique<T>(items: T[]): T[] {
4
+ return [...new Set(items)];
5
+ }
6
+
7
+ function normalizeFilePath(filePath) {
8
+ return (filePath || "").replace(/\\/g, "/");
9
+ }
10
+
11
+ const glob = require("glob");
12
+
13
+ export function postRunCleanup(
14
+ config,
15
+ approvedFilesMap,
16
+ glob_sync = glob.sync,
17
+ ) {
18
+ const options = config;
19
+ if (options.errorOnStaleApprovedFiles) {
20
+ // Don't require glob at the top of the file.
21
+ // this avoids a load of glob if it's not necessary
22
+
23
+ // normalize file paths for searching (windows vs *nix)...
24
+ const normalizedApprovedFilePaths = approvedFilesMap.map(normalizeFilePath);
25
+
26
+ const getAllDirectoriesOfApprovedFiles = unique(
27
+ normalizedApprovedFilePaths.map(function (file) {
28
+ return path.dirname(file);
29
+ }),
30
+ ); // get just the directory of each
31
+
32
+ let discoveredApprovalFiles: any = [];
33
+ getAllDirectoriesOfApprovedFiles.forEach(function (folder) {
34
+ return glob_sync(folder + "**/*.approved.*").forEach(function (file) {
35
+ if (discoveredApprovalFiles.indexOf(file) === -1) {
36
+ discoveredApprovalFiles.push(file);
37
+ }
38
+ });
39
+ }); // use 'glob' to find all .approved.* files for each folder.
40
+
41
+ discoveredApprovalFiles = discoveredApprovalFiles.map(normalizeFilePath);
42
+
43
+ const staleApprovals = discoveredApprovalFiles
44
+ .filter(function (file) {
45
+ if (typeof options.shouldIgnoreStaleApprovedFile === "function") {
46
+ return !options.shouldIgnoreStaleApprovedFile(file);
47
+ }
48
+ return true;
49
+ })
50
+ .filter(function (discoveredFilePath) {
51
+ return normalizedApprovedFilePaths.indexOf(discoveredFilePath) < 0;
52
+ }); // only pull the ones that aren't already in the 'normalizedApprovedFilePaths'
53
+
54
+ if (staleApprovals.length) {
55
+ process.exitCode = 1;
56
+ throw new Error(
57
+ "ERROR: Found stale approvals files: \n - " +
58
+ staleApprovals.join("\n - ") +
59
+ "\n",
60
+ );
61
+ }
62
+ }
63
+ }
package/package.json ADDED
@@ -0,0 +1,109 @@
1
+ {
2
+ "name": "@approval-tests/approvals",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "description": "Approval Tests Library - Capturing Human Intelligence",
7
+ "version": "7.5.7",
8
+ "homepage": "http://approvaltests.com",
9
+ "author": {
10
+ "name": "Jason Jarrett",
11
+ "url": "http://staxmanade.com"
12
+ },
13
+ "contributors": [
14
+ {
15
+ "name": "Llewellyn Falco"
16
+ },
17
+ {
18
+ "name": "Jason Jarrett (http://staxmanade.com)"
19
+ }
20
+ ],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/approvals/Approvals.NodeJS.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/approvals/Approvals.NodeJS/issues"
27
+ },
28
+ "license": "Apache-2.0",
29
+ "main": "lib/Approvals",
30
+ "files": [
31
+ "lib",
32
+ "bin"
33
+ ],
34
+ "bin": {
35
+ "approvals": "bin/index.js"
36
+ },
37
+ "engines": {
38
+ "node": ">= 0.8.0"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc",
42
+ "test": "gulp && jest && vitest run",
43
+ "vitest": "vitest run",
44
+ "test2": "npm run mocha && npm run lint",
45
+ "lint": "eslint './lib/**/*.js' './test/**/*.js'",
46
+ "release": "np",
47
+ "mocha": "mocha 'test/**/*[Tt]ests.js'",
48
+ "coverage": "nyc npm run mocha"
49
+ },
50
+ "dependencies": {
51
+ "ansi-colors": "^4.1.3",
52
+ "axios": "^1.7.9",
53
+ "callsite": "^1.0.0",
54
+ "diff": "^9.0.0",
55
+ "event-stream": "^4.0.1",
56
+ "file-type": "^12.4.2",
57
+ "glob": "^13.0.0",
58
+ "jest": "^30.0.0",
59
+ "js-yaml": "^5.1.0",
60
+ "lodash": "^4.17.21",
61
+ "marked": "^15.0.6",
62
+ "marked-terminal": "^7.0.0",
63
+ "minimist": "^1.2.8",
64
+ "mkdirp": "^3.0.1",
65
+ "shelljs": "^0.10.0",
66
+ "temp": "^0.9.4",
67
+ "ts-jest": "^29.0.3"
68
+ },
69
+ "devDependencies": {
70
+ "@types/chai": "^5.0.1",
71
+ "@types/mocha": "^10.0.10",
72
+ "@types/node": "^26.0.0",
73
+ "@typescript-eslint/eslint-plugin": "^8.17.0",
74
+ "@typescript-eslint/parser": "^8.17.0",
75
+ "chai": "^6.0.1",
76
+ "eslint": "^10.2.1",
77
+ "eslint-plugin-promise": "^7.2.1",
78
+ "gulp": "^5.0.0",
79
+ "gulp-eslint": "^6.0.0",
80
+ "gulp-istanbul": "^1.1.3",
81
+ "gulp-load-plugins": "^2.0.7",
82
+ "gulp-mocha": "^10.0.1",
83
+ "gulp-watch": "^5.0.1",
84
+ "jest-junit": "^17.0.0",
85
+ "jsdoc-to-markdown": "^9.1.1",
86
+ "mocha": "^11.0.1",
87
+ "mocha-junit-reporter": "^2.2.1",
88
+ "mocha-multi-reporters": "^1.5.1",
89
+ "np": "^12.0.0",
90
+ "nyc": "^18.0.0",
91
+ "pre-commit": "^2.0.0",
92
+ "prettier": "^3.4.2",
93
+ "sinon": "^22.0.0",
94
+ "ts-node": "^10.9.1",
95
+ "typescript": "^6.0.2",
96
+ "vitest": "^4.1.8"
97
+ },
98
+ "keywords": [
99
+ "Approve",
100
+ "Approvals",
101
+ "ApprovalTests",
102
+ "Approval Tests",
103
+ "Mocha",
104
+ "Test",
105
+ "Testing",
106
+ "Verification",
107
+ "Verify"
108
+ ]
109
+ }