@approval-tests/approvals 7.6.0 → 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 (61) 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.js +1 -1
  46. package/lib/Scrubbers/DateScrubber.js +1 -1
  47. package/lib/Scrubbers/Scrubbers.js +3 -18
  48. package/lib/StringWriter.js +1 -1
  49. package/lib/Utilities/Logger/LoggingInstance.js +13 -39
  50. package/lib/Utilities/Logger/SimpleLogger.d.ts +1 -1
  51. package/lib/Utilities/Logger/SimpleLogger.js +1 -1
  52. package/lib/Utilities/Logger/SimpleLoggerApprovals.js +1 -1
  53. package/lib/Utilities/Printers.js +2 -2
  54. package/lib/Writers/BinaryWriter.js +7 -12
  55. package/lib/config.js +2 -2
  56. package/lib/osTools.d.ts +1 -1
  57. package/lib/osTools.js +0 -2
  58. package/lib/postRunCleanup.d.ts +1 -1
  59. package/lib/postRunCleanup.js +17 -17
  60. package/package.json +19 -2
  61. package/readme.md +1 -1
@@ -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.6.0",
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
@@ -313,7 +313,7 @@ export const defaultConfig: Config = {
313
313
  maxLaunches: 10,
314
314
  };
315
315
  ```
316
- <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>
317
317
  <!-- endSnippet -->
318
318
 
319
319
  <a name="api" />