@approval-tests/approvals 7.5.14 → 7.6.2

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 (62) hide show
  1. package/bin/index.js +2 -2
  2. package/lib/AUtils.js +2 -1
  3. package/lib/Approvals.d.ts +5 -1
  4. package/lib/Approvals.js +38 -37
  5. package/lib/Core/Namer.js +1 -1
  6. package/lib/Core/Options.d.ts +1 -1
  7. package/lib/Core/Options.js +2 -2
  8. package/lib/FileApprover.d.ts +1 -1
  9. package/lib/FileApprover.js +13 -13
  10. package/lib/FinalMessages.js +0 -1
  11. package/lib/Logs/ApprovedFileLog.js +1 -1
  12. package/lib/Logs/LogUtils.d.ts +1 -1
  13. package/lib/Logs/LogUtils.js +4 -4
  14. package/lib/ManualNamer.js +0 -3
  15. package/lib/Providers/BeforeEachVerifierBase.js +11 -17
  16. package/lib/Providers/Jest/CombinationApprovals.js +1 -1
  17. package/lib/Providers/Jest/JestApprovals.js +6 -16
  18. package/lib/Providers/Jest/JestNamer.js +5 -4
  19. package/lib/Providers/Jest/JestReporter.js +6 -3
  20. package/lib/Providers/Jest/JestSetup.js +8 -13
  21. package/lib/Providers/Mocha/MochaApprovals.d.ts +1 -1
  22. package/lib/Providers/Mocha/MochaApprovals.js +11 -18
  23. package/lib/Providers/Mocha/MochaNamer.d.ts +2 -2
  24. package/lib/Providers/Mocha/MochaNamer.js +8 -9
  25. package/lib/Providers/Vitest/VitestApprovals.js +6 -5
  26. package/lib/Providers/Vitest/VitestNamer.js +4 -4
  27. package/lib/Providers/Vitest/VitestReporter.js +2 -1
  28. package/lib/Reporting/GenericDiffReporterBase.d.ts +1 -1
  29. package/lib/Reporting/ReportByOpeningTheReceivedFile.d.ts +1 -1
  30. package/lib/Reporting/ReporterFactory.js +2 -1
  31. package/lib/Reporting/Reporters/beyondcompareReporter.js +1 -1
  32. package/lib/Reporting/Reporters/codiumReporter.js +1 -1
  33. package/lib/Reporting/Reporters/copycommandReporter.js +4 -5
  34. package/lib/Reporting/Reporters/diffmergeReporter.js +1 -1
  35. package/lib/Reporting/Reporters/donothingReporter.js +1 -3
  36. package/lib/Reporting/Reporters/kdiff3Reporter.js +1 -1
  37. package/lib/Reporting/Reporters/meldReporter.js +1 -1
  38. package/lib/Reporting/Reporters/multiReporter.js +2 -2
  39. package/lib/Reporting/Reporters/nodediffReporter.js +14 -25
  40. package/lib/Reporting/Reporters/p4mergeReporter.js +31 -26
  41. package/lib/Reporting/Reporters/tortoisemergeReporter.js +4 -4
  42. package/lib/Reporting/Reporters/vimdiffReporter.js +1 -4
  43. package/lib/Reporting/Reporters/visualstudioReporter.js +15 -12
  44. package/lib/Reporting/Reporters/vscodeReporter.js +1 -1
  45. package/lib/Reporting/Reporters/webstormReporter.d.ts +4 -0
  46. package/lib/Reporting/Reporters/webstormReporter.js +41 -0
  47. package/lib/Scrubbers/DateScrubber.js +1 -1
  48. package/lib/Scrubbers/Scrubbers.js +3 -18
  49. package/lib/StringWriter.js +1 -1
  50. package/lib/Utilities/Logger/LoggingInstance.js +13 -39
  51. package/lib/Utilities/Logger/SimpleLogger.d.ts +1 -1
  52. package/lib/Utilities/Logger/SimpleLogger.js +1 -1
  53. package/lib/Utilities/Logger/SimpleLoggerApprovals.js +1 -1
  54. package/lib/Utilities/Printers.js +2 -2
  55. package/lib/Writers/BinaryWriter.js +7 -12
  56. package/lib/config.js +2 -2
  57. package/lib/osTools.d.ts +1 -1
  58. package/lib/osTools.js +0 -2
  59. package/lib/postRunCleanup.d.ts +1 -1
  60. package/lib/postRunCleanup.js +17 -17
  61. package/package.json +19 -2
  62. package/readme.md +2 -1
@@ -49,26 +49,12 @@ class LoggingInstance {
49
49
  return code();
50
50
  }
51
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})`);
52
+ const entryParameters = typeof parameters === "function" ? parameters() : parameters;
53
+ this.logLine(`=> ${name}(${entryParameters})`);
60
54
  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}`);
55
+ const exitParameters = typeof parameters === "function" ? parameters() : "";
56
+ const returnText = logReturnValue ? `: ${returnValue}` : "";
57
+ this.logLine(`<= ${name}(${exitParameters})${returnText}`);
72
58
  return returnValue;
73
59
  }
74
60
  variable(name, value, showTypes) {
@@ -77,7 +63,7 @@ class LoggingInstance {
77
63
  }
78
64
  let toType = (_value, _spacing = "") => "";
79
65
  if (showTypes) {
80
- toType = (value, spacing = " ") => `${spacing}${printType(value)}`;
66
+ toType = (val, spacing = " ") => `${spacing}${printType(val)}`;
81
67
  }
82
68
  if (Array.isArray(value)) {
83
69
  this.logLine(`variable: ${name}${toType(value, "")}.length = ${value.length}`);
@@ -92,7 +78,7 @@ class LoggingInstance {
92
78
  }
93
79
  }
94
80
  logLine(text, use_timestamps = true) {
95
- if (this.counter != 0) {
81
+ if (this.counter !== 0) {
96
82
  this.logger("\n");
97
83
  }
98
84
  this.counter = 0;
@@ -114,14 +100,14 @@ class LoggingInstance {
114
100
  return;
115
101
  }
116
102
  this.counter += 1;
117
- if (this.counter == 1) {
103
+ if (this.counter === 1) {
118
104
  this.logger(`${this.getTabs()}.`);
119
105
  }
120
- else if (this.counter == 100) {
106
+ else if (this.counter === 100) {
121
107
  this.logger("10\n");
122
108
  this.counter = 0;
123
109
  }
124
- else if (this.counter % 10 == 0) {
110
+ else if (this.counter % 10 === 0) {
125
111
  const digit = this.counter / 10;
126
112
  this.logger(`${digit}`);
127
113
  }
@@ -158,24 +144,12 @@ class LoggingInstance {
158
144
  }
159
145
  warning(exception) {
160
146
  const warning_stars = "*".repeat(91);
161
- const text = null;
162
147
  this.logLine(warning_stars, false);
163
148
  if (this.logWithTimestamps) {
164
149
  this.logLine("", true);
165
150
  }
166
- if (text) {
167
- this.logLine(`Message:${text}`, false);
168
- }
169
151
  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);
152
+ this.logLine(`${exception}`, false);
179
153
  }
180
154
  this.logLine(warning_stars, false);
181
155
  }
@@ -201,11 +175,11 @@ class LoggingInstance {
201
175
  const time1 = this.timer();
202
176
  const time = time1.toISOString();
203
177
  let diff_millseconds = 0;
204
- if (this.previousTimestamp != null) {
178
+ if (this.previousTimestamp !== null) {
205
179
  diff_millseconds = time1.getTime() - this.previousTimestamp.getTime();
206
180
  }
207
181
  const diff_display = `~${String(diff_millseconds).padStart(6, "0")}ms`;
208
- let time_text = `${time}`.replace("T", " ").substring(0, 19);
182
+ const time_text = `${time}`.replace("T", " ").substring(0, 19);
209
183
  const timestamp = `[${time_text} ${diff_display}] `;
210
184
  this.previousTimestamp = time1;
211
185
  return timestamp;
@@ -1,6 +1,6 @@
1
- import { Wrapper } from "./Wrapper";
2
1
  import { LoggingInstance } from "./LoggingInstance";
3
2
  import { StringWrapper } from "./StringWrapper";
3
+ import { Wrapper } from "./Wrapper";
4
4
  export declare class SimpleLogger {
5
5
  static _wrapper: Wrapper<LoggingInstance>;
6
6
  static showQueries(show: boolean): void;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SimpleLogger = void 0;
4
- const Wrapper_1 = require("./Wrapper");
5
4
  const LoggingInstance_1 = require("./LoggingInstance");
5
+ const Wrapper_1 = require("./Wrapper");
6
6
  class SimpleLogger {
7
7
  static showQueries(show) {
8
8
  this._wrapper.get().showQueries(show);
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.verifySimpleLogger = verifySimpleLogger;
4
- const SimpleLogger_1 = require("./SimpleLogger");
5
4
  const JestApprovals_1 = require("../../Providers/Jest/JestApprovals");
5
+ const SimpleLogger_1 = require("./SimpleLogger");
6
6
  function verifySimpleLogger(testName, code, options) {
7
7
  test(testName, () => {
8
8
  const output = SimpleLogger_1.SimpleLogger.logToString();
@@ -13,7 +13,7 @@ function printArray(header, list, formatter) {
13
13
  if (header) {
14
14
  text = header + "\n\n\n";
15
15
  }
16
- for (let t of list) {
16
+ for (const t of list) {
17
17
  text += formatter(t) + "\n";
18
18
  }
19
19
  return text;
@@ -35,7 +35,7 @@ function generateParameterCombinations(variations, parameterCombinations = [], i
35
35
  parameterCombinations.push(currentParameterCombination);
36
36
  return parameterCombinations;
37
37
  }
38
- for (let nextParameter of variations[index]) {
38
+ for (const nextParameter of variations[index]) {
39
39
  generateParameterCombinations(variations, parameterCombinations, index + 1, [...currentParameterCombination, nextParameter]);
40
40
  }
41
41
  return parameterCombinations;
@@ -36,27 +36,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.BinaryWriter = void 0;
37
37
  const fs = __importStar(require("fs"));
38
38
  const path = __importStar(require("path"));
39
- const mkdirp_1 = require("mkdirp");
40
39
  const magic_bytes_js_1 = require("magic-bytes.js");
40
+ const mkdirp_1 = require("mkdirp");
41
+ const legacyApprovalFileExtensions = new Map([
42
+ ["jpeg", "jpg"],
43
+ ["tiff", "tif"],
44
+ ]);
41
45
  class BinaryWriter {
42
46
  constructor(outputData) {
43
47
  this.outputData = outputData;
44
48
  }
45
49
  getFileExtension() {
50
+ var _a;
46
51
  if (!this._ext) {
47
52
  // Use the first signature match (for example, zip before jar/docx).
48
53
  const extension = (0, magic_bytes_js_1.filetypeextension)(this.outputData)[0] || "blob";
49
- // Keep existing JPEG and TIFF approval filenames compatible.
50
- switch (extension) {
51
- case "jpeg":
52
- this._ext = "jpg";
53
- break;
54
- case "tiff":
55
- this._ext = "tif";
56
- break;
57
- default:
58
- this._ext = extension;
59
- }
54
+ this._ext = (_a = legacyApprovalFileExtensions.get(extension)) !== null && _a !== void 0 ? _a : extension;
60
55
  }
61
56
  return this._ext;
62
57
  }
package/lib/config.js CHANGED
@@ -39,11 +39,11 @@ exports.getConfig = getConfig;
39
39
  exports.configure = configure;
40
40
  exports.currentConfig = currentConfig;
41
41
  exports.reset = reset;
42
- const os = __importStar(require("os"));
43
42
  const fs = __importStar(require("fs"));
43
+ const os = __importStar(require("os"));
44
44
  const path = __importStar(require("path"));
45
- const _ = __importStar(require("lodash"));
46
45
  const yaml = __importStar(require("js-yaml"));
46
+ const _ = __importStar(require("lodash"));
47
47
  const ReportLaunchingCircuitBreaker_1 = require("./Reporting/ReportLaunchingCircuitBreaker");
48
48
  // begin-snippet: default_config
49
49
  exports.defaultConfig = {
package/lib/osTools.d.ts CHANGED
@@ -2,4 +2,4 @@ export declare const platform: {
2
2
  isWindows: boolean;
3
3
  isMac: boolean;
4
4
  };
5
- export declare let findProgramPathCommand: string;
5
+ export declare const findProgramPathCommand: string;
package/lib/osTools.js CHANGED
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
- // Remove the reference path as TypeScript should be configured to recognize node types globally via `tsconfig.json`
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.findProgramPathCommand = exports.platform = void 0;
5
- // Detect OS-specific features using TypeScript.
6
4
  const isWindows = process.platform.startsWith("win");
7
5
  exports.platform = {
8
6
  isWindows: isWindows,
@@ -1 +1 @@
1
- export declare function postRunCleanup(config: any, approvedFilesMap: any, glob_sync?: any): void;
1
+ export declare function postRunCleanup(config: any, approvedFilesMap: any, glob_sync?: (pattern: string) => string[]): void;
@@ -5,32 +5,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.postRunCleanup = postRunCleanup;
7
7
  const path_1 = __importDefault(require("path"));
8
+ const glob_1 = require("glob");
8
9
  function unique(items) {
9
10
  return [...new Set(items)];
10
11
  }
11
12
  function normalizeFilePath(filePath) {
12
13
  return (filePath || "").replace(/\\/g, "/");
13
14
  }
14
- const glob = require("glob");
15
- function postRunCleanup(config, approvedFilesMap, glob_sync = glob.sync) {
15
+ function findApprovedFilesInFolders(folders, glob_sync) {
16
+ const discoveredApprovalFiles = [];
17
+ folders.forEach(function (folder) {
18
+ return glob_sync(folder + "**/*.approved.*").forEach(function (file) {
19
+ if (discoveredApprovalFiles.indexOf(file) === -1) {
20
+ discoveredApprovalFiles.push(file);
21
+ }
22
+ });
23
+ });
24
+ return discoveredApprovalFiles;
25
+ }
26
+ function postRunCleanup(config, approvedFilesMap, glob_sync = glob_1.sync) {
16
27
  const options = config;
17
28
  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
29
  const normalizedApprovedFilePaths = approvedFilesMap.map(normalizeFilePath);
22
- const getAllDirectoriesOfApprovedFiles = unique(normalizedApprovedFilePaths.map(function (file) {
30
+ const approvedFileFolders = unique(normalizedApprovedFilePaths.map(function (file) {
23
31
  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);
32
+ }));
33
+ const discoveredApprovalFiles = findApprovedFilesInFolders(approvedFileFolders, glob_sync).map(normalizeFilePath);
34
34
  const staleApprovals = discoveredApprovalFiles
35
35
  .filter(function (file) {
36
36
  if (typeof options.shouldIgnoreStaleApprovedFile === "function") {
@@ -40,7 +40,7 @@ function postRunCleanup(config, approvedFilesMap, glob_sync = glob.sync) {
40
40
  })
41
41
  .filter(function (discoveredFilePath) {
42
42
  return normalizedApprovedFilePaths.indexOf(discoveredFilePath) < 0;
43
- }); // only pull the ones that aren't already in the 'normalizedApprovedFilePaths'
43
+ });
44
44
  if (staleApprovals.length) {
45
45
  process.exitCode = 1;
46
46
  throw new Error("ERROR: Found stale approvals files: \n - " +
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "description": "Approval Tests Library - Capturing Human Intelligence",
7
- "version": "7.5.14",
7
+ "version": "7.6.2",
8
8
  "homepage": "http://approvaltests.com",
9
9
  "author": {
10
10
  "name": "Jason Jarrett",
@@ -45,14 +45,25 @@
45
45
  "scripts": {
46
46
  "build": "tsc",
47
47
  "prepack": "npm run build",
48
- "test": "node scripts/test.cjs",
48
+ "test": "npm run lint && npm run test:suites --",
49
+ "test:suites": "node scripts/test.cjs",
49
50
  "vitest": "node scripts/test-isolated.cjs vitest",
50
51
  "test2": "npm run mocha && npm run lint",
51
52
  "lint": "eslint lib test",
53
+ "lint:fix": "npm run lint -- --fix",
54
+ "lint:staged": "lint-staged",
52
55
  "mocha": "node scripts/test-isolated.cjs mocha",
53
56
  "coverage": "node scripts/test-isolated.cjs mocha --coverage",
54
57
  "jest": "node scripts/test-isolated.cjs jest"
55
58
  },
59
+ "pre-commit": [
60
+ "lint:staged",
61
+ "build",
62
+ "test:suites"
63
+ ],
64
+ "lint-staged": {
65
+ "*.{js,mjs,ts,mts}": "eslint --fix"
66
+ },
56
67
  "dependencies": {
57
68
  "ansi-colors": "^4.1.3",
58
69
  "axios": "^1.7.9",
@@ -78,12 +89,18 @@
78
89
  "@typescript-eslint/parser": "^8.17.0",
79
90
  "chai": "^6.0.1",
80
91
  "eslint": "^10.2.1",
92
+ "eslint-plugin-import-x": "^4.18.1",
81
93
  "eslint-plugin-promise": "^7.2.1",
94
+ "globals": "^17.14.0",
95
+ "jscpd": "^5.4.3",
82
96
  "jsdoc-to-markdown": "^9.1.1",
97
+ "knip": "^6.45.1",
98
+ "lint-staged": "^17.6.0",
83
99
  "nyc": "^18.0.0",
84
100
  "pre-commit": "^2.0.0",
85
101
  "prettier": "^3.4.2",
86
102
  "sinon": "^22.0.0",
103
+ "ts-morph": "^28.0.0",
87
104
  "typescript": "^6.0.2"
88
105
  },
89
106
  "keywords": [
package/readme.md CHANGED
@@ -213,6 +213,7 @@ Any of the following reporter may suite your needs. Some support images, some on
213
213
  | `visualstudio` | [Visual Studio Diff tool](http://msdn.microsoft.com/en-us/library/bb385990.aspx) | &#10003; | |
214
214
  | `vscode` | [Visual Studio Code Diff tool](https://code.visualstudio.com/) | &#10003; | &#10003; |
215
215
  | `vscodium` | [VSCodium Diff tool](https://vscodium.com/) | &#10003; | &#10003; |
216
+ | `webstorm` | [WebStorm](https://www.jetbrains.com/webstorm/) | &#10003; | &#10003; | Discovers WebStorm on PATH or in macOS application folders; [configure a launcher](docs/reference/Reporters.md#webstorm) for a custom installation. |
216
217
 
217
218
  ### Custom Reporter
218
219
 
@@ -312,7 +313,7 @@ export const defaultConfig: Config = {
312
313
  maxLaunches: 10,
313
314
  };
314
315
  ```
315
- <sup><a href='/lib/config.ts#L25-L47' title='Snippet source file'>snippet source</a> | <a href='#snippet-default_config' title='Start of snippet'>anchor</a></sup>
316
+ <sup><a href='/lib/config.ts#L27-L49' title='Snippet source file'>snippet source</a> | <a href='#snippet-default_config' title='Start of snippet'>anchor</a></sup>
316
317
  <!-- endSnippet -->
317
318
 
318
319
  <a name="api" />