@approval-tests/approvals 7.6.0 → 7.6.3

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 (67) hide show
  1. package/bin/index.js +3 -37
  2. package/lib/AUtils.js +21 -48
  3. package/lib/Approvals.d.ts +9 -5
  4. package/lib/Approvals.js +44 -76
  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.d.ts +2 -0
  11. package/lib/FinalMessages.js +5 -1
  12. package/lib/Logs/ApprovedFileLog.js +9 -39
  13. package/lib/Logs/FailedFileLog.js +8 -38
  14. package/lib/Logs/LogUtils.d.ts +1 -1
  15. package/lib/Logs/LogUtils.js +4 -4
  16. package/lib/ManualNamer.js +0 -3
  17. package/lib/Providers/BeforeEachVerifierBase.js +21 -57
  18. package/lib/Providers/Jest/CombinationApprovals.js +1 -1
  19. package/lib/Providers/Jest/JestApprovals.js +8 -51
  20. package/lib/Providers/Jest/JestNamer.js +5 -4
  21. package/lib/Providers/Jest/JestReporter.js +6 -3
  22. package/lib/Providers/Jest/JestSetup.js +8 -13
  23. package/lib/Providers/Mocha/MochaApprovals.d.ts +1 -1
  24. package/lib/Providers/Mocha/MochaApprovals.js +13 -53
  25. package/lib/Providers/Mocha/MochaNamer.d.ts +2 -2
  26. package/lib/Providers/Mocha/MochaNamer.js +8 -9
  27. package/lib/Providers/Vitest/VitestApprovals.js +8 -40
  28. package/lib/Providers/Vitest/VitestNamer.js +4 -4
  29. package/lib/Providers/Vitest/VitestReporter.js +2 -1
  30. package/lib/Reporting/GenericDiffReporterBase.d.ts +1 -1
  31. package/lib/Reporting/GenericDiffReporterBase.js +9 -42
  32. package/lib/Reporting/ReportByOpeningTheReceivedFile.d.ts +1 -1
  33. package/lib/Reporting/ReportLaunchingCircuitBreaker.d.ts +2 -0
  34. package/lib/Reporting/ReportLaunchingCircuitBreaker.js +6 -0
  35. package/lib/Reporting/ReporterFactory.js +2 -1
  36. package/lib/Reporting/Reporters/beyondcompareReporter.js +1 -1
  37. package/lib/Reporting/Reporters/codiumReporter.js +1 -1
  38. package/lib/Reporting/Reporters/copycommandReporter.js +4 -5
  39. package/lib/Reporting/Reporters/diffmergeReporter.js +6 -36
  40. package/lib/Reporting/Reporters/donothingReporter.js +1 -3
  41. package/lib/Reporting/Reporters/gitdiffReporter.js +0 -1
  42. package/lib/Reporting/Reporters/kdiff3Reporter.js +1 -1
  43. package/lib/Reporting/Reporters/meldReporter.js +1 -1
  44. package/lib/Reporting/Reporters/multiReporter.js +2 -2
  45. package/lib/Reporting/Reporters/nodediffReporter.js +15 -26
  46. package/lib/Reporting/Reporters/p4mergeReporter.js +27 -26
  47. package/lib/Reporting/Reporters/tortoisemergeReporter.js +4 -4
  48. package/lib/Reporting/Reporters/vimdiffReporter.js +1 -4
  49. package/lib/Reporting/Reporters/visualstudioReporter.js +15 -12
  50. package/lib/Reporting/Reporters/vscodeReporter.js +1 -1
  51. package/lib/Reporting/Reporters/webstormReporter.js +1 -1
  52. package/lib/Scrubbers/DateScrubber.js +1 -1
  53. package/lib/Scrubbers/Scrubbers.js +3 -18
  54. package/lib/StringWriter.js +10 -40
  55. package/lib/Utilities/Logger/LoggingInstance.js +13 -39
  56. package/lib/Utilities/Logger/SimpleLogger.d.ts +1 -1
  57. package/lib/Utilities/Logger/SimpleLogger.js +1 -1
  58. package/lib/Utilities/Logger/SimpleLoggerApprovals.js +1 -1
  59. package/lib/Utilities/Printers.js +2 -2
  60. package/lib/Writers/BinaryWriter.js +15 -50
  61. package/lib/config.js +15 -45
  62. package/lib/osTools.d.ts +1 -1
  63. package/lib/osTools.js +0 -2
  64. package/lib/postRunCleanup.d.ts +1 -1
  65. package/lib/postRunCleanup.js +17 -17
  66. package/package.json +19 -6
  67. package/readme.md +1 -1
@@ -1,41 +1,11 @@
1
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
- })();
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
35
5
  Object.defineProperty(exports, "__esModule", { value: true });
36
6
  exports.FailedFileLog = void 0;
37
- const fs = __importStar(require("fs"));
38
- const path = __importStar(require("path"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
39
9
  const JestUtils_1 = require("../Utilities/JestUtils");
40
10
  const LogUtils_1 = require("./LogUtils");
41
11
  let runOnce = false;
@@ -48,15 +18,15 @@ class FailedFileLog {
48
18
  this.forceClearFileLog();
49
19
  }
50
20
  static forceClearFileLog() {
51
- fs.writeFileSync(this.getLogFilePath(), "");
21
+ fs_1.default.writeFileSync(this.getLogFilePath(), "");
52
22
  }
53
23
  static getLogFilePath() {
54
- return path.join(LogUtils_1.LogUtils.ensureTempDirectoryExists(), ".failed_comparison.log");
24
+ return path_1.default.join(LogUtils_1.LogUtils.ensureTempDirectoryExists(), ".failed_comparison.log");
55
25
  }
56
26
  static log(approved, received) {
57
27
  const logFilePath = this.getLogFilePath();
58
28
  const logEntry = `${received} -> ${approved}\n`;
59
- fs.appendFileSync(logFilePath, logEntry);
29
+ fs_1.default.appendFileSync(logFilePath, logEntry);
60
30
  }
61
31
  static touch() {
62
32
  this.clearLogFile();
@@ -2,6 +2,6 @@ export declare class LogUtils {
2
2
  private static runOnce;
3
3
  static readonly APPROVAL_TEMP_DIRECTORY: string;
4
4
  static ensureTempDirectoryExists(): string;
5
- private static downloadApproveAllScriptIfMissing;
5
+ private static downloadScriptsIfMissing;
6
6
  private static downloadFile;
7
7
  }
@@ -25,10 +25,10 @@ class LogUtils {
25
25
  if (!fs_1.default.existsSync(this.APPROVAL_TEMP_DIRECTORY)) {
26
26
  fs_1.default.mkdirSync(this.APPROVAL_TEMP_DIRECTORY);
27
27
  }
28
- this.downloadApproveAllScriptIfMissing().then();
28
+ this.downloadScriptsIfMissing().then();
29
29
  return this.APPROVAL_TEMP_DIRECTORY;
30
30
  }
31
- static downloadApproveAllScriptIfMissing() {
31
+ static downloadScriptsIfMissing() {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
33
  void this.downloadFile(`approve_all.py`);
34
34
  void this.downloadFile(`remove_abandoned_files.py`);
@@ -47,8 +47,8 @@ class LogUtils {
47
47
  fs_1.default.chmodSync(scriptPath, 0o755);
48
48
  }
49
49
  }
50
- catch (error) {
51
- // Do nothing
50
+ catch (_a) {
51
+ // Best-effort download: being offline or GitHub failing must not break tests.
52
52
  }
53
53
  });
54
54
  }
@@ -5,9 +5,6 @@ const Namer_1 = require("./Namer");
5
5
  class ManualNamer extends Namer_1.Namer {
6
6
  constructor(dirName, testFileName) {
7
7
  super(dirName, testFileName);
8
- // Redefining these properties is actually redundant here because the superclass constructor
9
- // already sets them based on the arguments provided. You might want to remove these lines
10
- // unless there is some side effect or behavior in the superclass constructor that requires them.
11
8
  this.basePath = dirName;
12
9
  this.name = testFileName;
13
10
  }
@@ -1,81 +1,45 @@
1
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
- })();
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
35
5
  Object.defineProperty(exports, "__esModule", { value: true });
36
6
  exports.beforeEachVerifierBase = beforeEachVerifierBase;
37
- const _ = __importStar(require("lodash"));
38
- const fs = __importStar(require("fs"));
39
- const cfg = __importStar(require("../config"));
40
- const StringWriter_1 = require("../StringWriter");
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const AUtils_1 = require("../AUtils");
10
+ const config_1 = require("../config");
41
11
  const FileApprover_1 = require("../FileApprover");
42
12
  const ReporterFactory_1 = require("../Reporting/ReporterFactory");
43
- const aUtils = __importStar(require("../AUtils"));
13
+ const StringWriter_1 = require("../StringWriter");
44
14
  function beforeEachLoaderFunction(Namer, dirName, that) {
45
- // Add methods to the test context
46
15
  that.approvals = { getCurrentReporters };
47
16
  that.verify = verify;
48
17
  that.verifyAsJSON = verifyAsJSON;
49
18
  function getCurrentReporters(options) {
50
- options = options || cfg.currentConfig();
51
- const reporterCandidates = ReporterFactory_1.ReporterFactory.loadAllReporters(options.reporters);
52
- return reporterCandidates;
19
+ options = options || (0, config_1.currentConfig)();
20
+ return ReporterFactory_1.ReporterFactory.loadAllReporters(options.reporters);
53
21
  }
54
22
  function verify(data, overrideOptions) {
55
- // @ts-ignore
56
- const context = this;
57
- const namer = new Namer(context, dirName);
58
- const newOptions = _.defaults(overrideOptions || {}, cfg.currentConfig());
59
- const reporterFactory = function () {
60
- return { getCurrentReporters }.getCurrentReporters(newOptions);
61
- };
23
+ const namer = new Namer(this, dirName);
24
+ const newOptions = lodash_1.default.defaults(overrideOptions || {}, (0, config_1.currentConfig)());
25
+ const reporterFactory = () => getCurrentReporters(newOptions);
62
26
  const writer = new StringWriter_1.StringWriter(newOptions, data);
63
27
  FileApprover_1.FileApprover.verify(namer, writer, reporterFactory);
64
28
  }
65
29
  function verifyAsJSON(data, overrideOptions) {
66
- // @ts-ignore
67
- this.verify(aUtils.stringifyKeysInOrder(data), overrideOptions);
30
+ this.verify((0, AUtils_1.stringifyKeysInOrder)(data), overrideOptions);
68
31
  }
69
32
  }
70
- function beforeEachVerifierBase(Namer, usageSample, dirName) {
71
- if (!fs.existsSync(dirName)) {
72
- fs.mkdirSync(dirName);
33
+ function ensureDirectoryExists(dirName, usageSample) {
34
+ if (!fs_1.default.existsSync(dirName)) {
35
+ fs_1.default.mkdirSync(dirName);
73
36
  }
74
- // Make sure it's a valid directory
75
- const stats = fs.lstatSync(dirName);
76
- if (!stats.isDirectory()) {
37
+ if (!fs_1.default.lstatSync(dirName).isDirectory()) {
77
38
  throw new Error(`Invalid directory [${dirName}]. Try using the following syntax. > ${usageSample}`);
78
39
  }
40
+ }
41
+ function beforeEachVerifierBase(Namer, usageSample, dirName) {
42
+ ensureDirectoryExists(dirName, usageSample);
79
43
  beforeEach(function () {
80
44
  return beforeEachLoaderFunction(Namer, dirName, this);
81
45
  });
@@ -10,8 +10,8 @@ exports.verifyAllCombinations6 = verifyAllCombinations6;
10
10
  exports.verifyAllCombinations7 = verifyAllCombinations7;
11
11
  exports.verifyAllCombinations8 = verifyAllCombinations8;
12
12
  exports.verifyAllCombinations9 = verifyAllCombinations9;
13
- const JestApprovals_1 = require("./JestApprovals");
14
13
  const Printers_1 = require("../../Utilities/Printers");
14
+ const JestApprovals_1 = require("./JestApprovals");
15
15
  function verifyAllCombinations(func, ...variations) {
16
16
  (0, JestApprovals_1.verify)((0, Printers_1.printCombinations)(func, ...variations));
17
17
  }
@@ -1,68 +1,25 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.verify = verify;
37
4
  exports.verifyAsJson = verifyAsJson;
38
5
  exports.verifyAll = verifyAll;
39
- const Printers_1 = require("../../Utilities/Printers");
40
- /* ^^^ If the above line is failing, please add
41
- # 1. Jest Config
42
- ```
43
- "transformIgnorePatterns": ["node_modules/@3ds"]
44
- ```
45
-
46
- # 2. tsconfig.json
47
- ```
48
- "esModuleInterop": true
49
- ```
50
- */
6
+ const Approvals_1 = require("../../Approvals");
51
7
  const Options_1 = require("../../Core/Options");
52
- const JestNamer_1 = require("./JestNamer");
53
8
  const StringWriter_1 = require("../../StringWriter");
54
- const approvals = __importStar(require("../../Approvals"));
9
+ const Printers_1 = require("../../Utilities/Printers");
55
10
  const OptionalFramework_1 = require("../OptionalFramework");
11
+ const JestNamer_1 = require("./JestNamer");
56
12
  function verify(sut, options) {
57
- if (!(0, OptionalFramework_1.isFrameworkAvailable)("jest"))
13
+ if (!(0, OptionalFramework_1.isFrameworkAvailable)("jest")) {
58
14
  return;
15
+ }
59
16
  options = options || new Options_1.Options();
60
17
  options = options.withNamer((0, JestNamer_1.getJestNamer)());
61
- const config = options.getConfig(approvals.getConfig());
18
+ const config = options.getConfig((0, Approvals_1.getConfig)());
62
19
  const scrubbed = options.scrub(`${sut}`);
63
20
  const writer = new StringWriter_1.StringWriter(config, scrubbed, options.forFile().getFileExtension());
64
- let namer = options.getNamer();
65
- approvals.verifyWithControl(namer, writer, null, config);
21
+ const namer = options.getNamer();
22
+ (0, Approvals_1.verifyWithControl)(namer, writer, null, config);
66
23
  }
67
24
  function verifyAsJson(data, options) {
68
25
  const text = (0, Printers_1.printJson)(data);
@@ -5,14 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getJestNamer = getJestNamer;
7
7
  const path_1 = __importDefault(require("path"));
8
- const Namer_1 = require("../../Namer");
9
- const Namer_2 = require("../../Core/Namer");
8
+ const Namer_1 = require("../../Core/Namer");
9
+ const Namer_2 = require("../../Namer");
10
10
  function getJestNamer() {
11
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
11
12
  const { expect } = require("@jest/globals");
12
13
  const state = expect.getState();
13
14
  const file = path_1.default.parse(state.testPath);
14
15
  const testPath = file.dir;
15
16
  const testFileName = file.name;
16
- const testName = (0, Namer_2.convertToFilename)(`${testFileName}.${state.currentTestName}`);
17
- return new Namer_1.Namer(testPath, testName);
17
+ const testName = (0, Namer_1.convertToFilename)(`${testFileName}.${state.currentTestName}`);
18
+ return new Namer_2.Namer(testPath, testName);
18
19
  }
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.JestReporter = void 0;
7
- const OptionalFramework_1 = require("../OptionalFramework");
8
7
  const fs_1 = __importDefault(require("fs"));
8
+ const OptionalFramework_1 = require("../OptionalFramework");
9
9
  class JestReporter {
10
10
  constructor() {
11
11
  this.name = "JestReporter";
@@ -14,9 +14,12 @@ class JestReporter {
14
14
  return (0, OptionalFramework_1.isFrameworkAvailable)("jest");
15
15
  }
16
16
  report(approvedFilePath, receivedFilePath, _) {
17
- if (!(0, OptionalFramework_1.isFrameworkAvailable)("jest"))
17
+ if (!(0, OptionalFramework_1.isFrameworkAvailable)("jest")) {
18
18
  return;
19
- const { expect } = require("@jest/globals");
19
+ }
20
+ const { expect } =
21
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
22
+ require("@jest/globals");
20
23
  const approvedText = fs_1.default.readFileSync(approvedFilePath).toString();
21
24
  const receivedText = fs_1.default.readFileSync(receivedFilePath).toString();
22
25
  expect(receivedText).toBe(approvedText);
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.jestInitializingRun = void 0;
7
7
  exports.initializeGlobalsForJest = initializeGlobalsForJest;
8
8
  exports.helpUserSetupJest = helpUserSetupJest;
9
+ const fs_1 = __importDefault(require("fs"));
9
10
  const ApprovedFileLog_1 = require("../../Logs/ApprovedFileLog");
10
11
  const FailedFileLog_1 = require("../../Logs/FailedFileLog");
11
- const fs_1 = __importDefault(require("fs"));
12
12
  const LogUtils_1 = require("../../Logs/LogUtils");
13
13
  exports.jestInitializingRun = false;
14
14
  function initializeGlobalsForJest() {
@@ -16,20 +16,15 @@ function initializeGlobalsForJest() {
16
16
  FailedFileLog_1.FailedFileLog.forceClearFileLog();
17
17
  exports.jestInitializingRun = true;
18
18
  }
19
+ function wasCreatedInLast24Hours(file) {
20
+ const creationDate = fs_1.default.statSync(file).birthtime;
21
+ const twentyFourHoursAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
22
+ return creationDate > twentyFourHoursAgo;
23
+ }
19
24
  function helpUserSetupJest(fileToCheck) {
20
25
  LogUtils_1.LogUtils.ensureTempDirectoryExists();
21
- // Check if the file exists
22
- if (fs_1.default.existsSync(fileToCheck)) {
23
- // Get the date that fileToCheck was created
24
- const fileStats = fs_1.default.statSync(fileToCheck);
25
- const fileCreationDate = fileStats.birthtime;
26
- // Check if the date was in the last 24 hours
27
- const currentDate = new Date();
28
- const twentyFourHoursAgo = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000);
29
- const isFileRecent = fileCreationDate > twentyFourHoursAgo;
30
- if (isFileRecent) {
31
- return;
32
- }
26
+ if (fs_1.default.existsSync(fileToCheck) && wasCreatedInLast24Hours(fileToCheck)) {
27
+ return;
33
28
  }
34
29
  const helpMessage = `
35
30
  **********************************************
@@ -1,5 +1,5 @@
1
- import { Options } from "../../Core/Options";
2
1
  import { Namer } from "../../Core/Namer";
2
+ import { Options } from "../../Core/Options";
3
3
  export declare function it2(label: string, test: () => void): void;
4
4
  export declare function setNamer(that: any): void;
5
5
  export declare function getNamer(): Namer;
@@ -1,37 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
@@ -42,27 +9,18 @@ exports.getNamer = getNamer;
42
9
  exports.verify = verify;
43
10
  exports.verifyAsJson = verifyAsJson;
44
11
  exports.verifyAll = verifyAll;
45
- const Printers_1 = require("../../Utilities/Printers");
46
- /* ^^^ If the above line is failing, please add
47
- # 1. Jest Config
48
- ```
49
- "transformIgnorePatterns": ["node_modules/@3ds"]
50
- ```
51
-
52
- # 2. tsconfig.json
53
- ```
54
- "esModuleInterop": true
55
- ```
56
- */
12
+ const Approvals_1 = require("../../Approvals");
57
13
  const Options_1 = require("../../Core/Options");
58
- const MochaNamer_1 = require("./MochaNamer");
59
- const OptionalFramework_1 = require("../OptionalFramework");
60
14
  const StringWriter_1 = __importDefault(require("../../StringWriter"));
61
- const approvals = __importStar(require("../../Approvals"));
15
+ const Printers_1 = require("../../Utilities/Printers");
16
+ const OptionalFramework_1 = require("../OptionalFramework");
17
+ const MochaNamer_1 = require("./MochaNamer");
62
18
  let mochaTest = null;
63
19
  function it2(label, test) {
64
- if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
20
+ if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha")) {
65
21
  return;
22
+ }
23
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
66
24
  const mocha = require("mocha");
67
25
  mocha.it(label, function () {
68
26
  mochaTest = this;
@@ -72,22 +30,24 @@ function it2(label, test) {
72
30
  }
73
31
  let namer;
74
32
  function setNamer(that) {
75
- if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
33
+ if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha")) {
76
34
  return;
35
+ }
77
36
  namer = (0, MochaNamer_1.getMochaNamer)(that.currentTest);
78
37
  }
79
38
  function getNamer() {
80
39
  return namer;
81
40
  }
82
41
  function verify(sut, options) {
83
- if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
42
+ if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha")) {
84
43
  return;
44
+ }
85
45
  options = options || new Options_1.Options();
86
46
  options = options.withNamer(getNamer());
87
- const config = options.getConfig(approvals.getConfig());
47
+ const config = options.getConfig((0, Approvals_1.getConfig)());
88
48
  const scrubbed = options.scrub(`${sut}`);
89
49
  const writer = new StringWriter_1.default(config, scrubbed, options.forFile().getFileExtension());
90
- approvals.verifyWithControl(namer, writer, null, config);
50
+ (0, Approvals_1.verifyWithControl)(namer, writer, null, config);
91
51
  }
92
52
  function verifyAsJson(data, options) {
93
53
  const text = (0, Printers_1.printJson)(data);
@@ -1,8 +1,8 @@
1
+ import type { Context, Runnable } from "mocha";
1
2
  import { Namer } from "../../Namer";
2
- import type { Runnable } from "mocha";
3
3
  export declare class MochaNamer extends Namer {
4
4
  private ctx;
5
- constructor(mochaTest: Mocha.Context, overrideBasePath?: string);
5
+ constructor(mochaTest: Context, overrideBasePath?: string);
6
6
  getFullTestName(testContext: Runnable): string;
7
7
  pathCreator(type: string, ext: string): string;
8
8
  }
@@ -6,10 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MochaNamer = void 0;
7
7
  exports.getMochaNamer = getMochaNamer;
8
8
  const path_1 = __importDefault(require("path"));
9
- const Namer_1 = require("../../Namer");
10
- const Namer_2 = require("../../Core/Namer");
11
- class MochaNamer extends Namer_1.Namer {
12
- // @ts-ignore errors if Mocha is not used
9
+ const Namer_1 = require("../../Core/Namer");
10
+ const Namer_2 = require("../../Namer");
11
+ class MochaNamer extends Namer_2.Namer {
13
12
  constructor(mochaTest, overrideBasePath) {
14
13
  if (!mochaTest || !mochaTest.test) {
15
14
  throw new Error("Mocha test context was not supplied");
@@ -19,15 +18,15 @@ class MochaNamer extends Namer_1.Namer {
19
18
  this.basePath = overrideBasePath || path_1.default.dirname(this.ctx.file);
20
19
  }
21
20
  getFullTestName(testContext) {
22
- let test = testContext;
23
- let parentStack = [];
21
+ const test = testContext;
22
+ const parentStack = [];
24
23
  let currParent = test;
25
24
  while (currParent && currParent.parent) {
26
25
  parentStack.push(currParent);
27
26
  currParent = currParent.parent;
28
27
  }
29
28
  let newTitle = "";
30
- let parentStackReversed = parentStack.reverse();
29
+ const parentStackReversed = parentStack.reverse();
31
30
  parentStackReversed.forEach((item, index) => {
32
31
  if (index !== 0) {
33
32
  newTitle += ".";
@@ -67,6 +66,6 @@ function getMochaNamer(test) {
67
66
  const testPath = file.dir;
68
67
  const testFileName = file.name;
69
68
  const pieces = getTitleChain(test);
70
- const testName = (0, Namer_2.convertToFilename)(`${testFileName}.${pieces.join(".")}`);
71
- return new Namer_1.Namer(testPath, testName);
69
+ const testName = (0, Namer_1.convertToFilename)(`${testFileName}.${pieces.join(".")}`);
70
+ return new Namer_2.Namer(testPath, testName);
72
71
  }
@@ -1,57 +1,25 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.verify = verify;
37
4
  exports.verifyAsJson = verifyAsJson;
38
5
  exports.verifyAll = verifyAll;
39
- const Printers_1 = require("../../Utilities/Printers");
6
+ const Approvals_1 = require("../../Approvals");
40
7
  const Options_1 = require("../../Core/Options");
41
- const VitestNamer_1 = require("./VitestNamer");
42
8
  const StringWriter_1 = require("../../StringWriter");
43
- const approvals = __importStar(require("../../Approvals"));
9
+ const Printers_1 = require("../../Utilities/Printers");
44
10
  const OptionalFramework_1 = require("../OptionalFramework");
11
+ const VitestNamer_1 = require("./VitestNamer");
45
12
  function verify(sut, options) {
46
- if (!(0, OptionalFramework_1.isFrameworkAvailable)("vitest"))
13
+ if (!(0, OptionalFramework_1.isFrameworkAvailable)("vitest")) {
47
14
  return;
15
+ }
48
16
  options = options || new Options_1.Options();
49
17
  options = options.withNamer((0, VitestNamer_1.getVitestNamer)());
50
- const config = options.getConfig(approvals.getConfig());
18
+ const config = options.getConfig((0, Approvals_1.getConfig)());
51
19
  const scrubbed = options.scrub(`${sut}`);
52
20
  const writer = new StringWriter_1.StringWriter(config, scrubbed, options.forFile().getFileExtension());
53
- let namer = options.getNamer();
54
- approvals.verifyWithControl(namer, writer, null, config);
21
+ const namer = options.getNamer();
22
+ (0, Approvals_1.verifyWithControl)(namer, writer, null, config);
55
23
  }
56
24
  function verifyAsJson(data, options) {
57
25
  const text = (0, Printers_1.printJson)(data);
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getVitestNamer = getVitestNamer;
7
7
  const path_1 = __importDefault(require("path"));
8
- const Namer_1 = require("../../Namer");
9
- const Namer_2 = require("../../Core/Namer");
8
+ const Namer_1 = require("../../Core/Namer");
9
+ const Namer_2 = require("../../Namer");
10
10
  const StringUtils_1 = require("../../Utilities/StringUtils");
11
11
  function getVitestNamer() {
12
12
  var _a;
@@ -15,6 +15,6 @@ function getVitestNamer() {
15
15
  const testPath = file.dir;
16
16
  const testFileName = file.name;
17
17
  const currentTestNameWithoutSeparators = StringUtils_1.StringUtils.replaceAll((_a = state.currentTestName) !== null && _a !== void 0 ? _a : "", " > ", " ");
18
- const testName = (0, Namer_2.convertToFilename)(`${testFileName}.${currentTestNameWithoutSeparators}`);
19
- return new Namer_1.Namer(testPath, testName);
18
+ const testName = (0, Namer_1.convertToFilename)(`${testFileName}.${currentTestNameWithoutSeparators}`);
19
+ return new Namer_2.Namer(testPath, testName);
20
20
  }
@@ -14,8 +14,9 @@ class VitestReporter {
14
14
  return (0, OptionalFramework_1.isFrameworkAvailable)("vitest");
15
15
  }
16
16
  report(approvedFilePath, receivedFilePath, _) {
17
- if (!(0, OptionalFramework_1.isFrameworkAvailable)("vitest"))
17
+ if (!(0, OptionalFramework_1.isFrameworkAvailable)("vitest")) {
18
18
  return;
19
+ }
19
20
  const approvedText = fs_1.default.readFileSync(approvedFilePath).toString();
20
21
  const receivedText = fs_1.default.readFileSync(receivedFilePath).toString();
21
22
  expect(receivedText).toBe(approvedText);