@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.
- package/bin/index.js +2 -2
- package/lib/AUtils.js +2 -1
- package/lib/Approvals.d.ts +5 -1
- package/lib/Approvals.js +38 -37
- package/lib/Core/Namer.js +1 -1
- package/lib/Core/Options.d.ts +1 -1
- package/lib/Core/Options.js +2 -2
- package/lib/FileApprover.d.ts +1 -1
- package/lib/FileApprover.js +13 -13
- package/lib/FinalMessages.js +0 -1
- package/lib/Logs/ApprovedFileLog.js +1 -1
- package/lib/Logs/LogUtils.d.ts +1 -1
- package/lib/Logs/LogUtils.js +4 -4
- package/lib/ManualNamer.js +0 -3
- package/lib/Providers/BeforeEachVerifierBase.js +11 -17
- package/lib/Providers/Jest/CombinationApprovals.js +1 -1
- package/lib/Providers/Jest/JestApprovals.js +6 -16
- package/lib/Providers/Jest/JestNamer.js +5 -4
- package/lib/Providers/Jest/JestReporter.js +6 -3
- package/lib/Providers/Jest/JestSetup.js +8 -13
- package/lib/Providers/Mocha/MochaApprovals.d.ts +1 -1
- package/lib/Providers/Mocha/MochaApprovals.js +11 -18
- package/lib/Providers/Mocha/MochaNamer.d.ts +2 -2
- package/lib/Providers/Mocha/MochaNamer.js +8 -9
- package/lib/Providers/Vitest/VitestApprovals.js +6 -5
- package/lib/Providers/Vitest/VitestNamer.js +4 -4
- package/lib/Providers/Vitest/VitestReporter.js +2 -1
- package/lib/Reporting/GenericDiffReporterBase.d.ts +1 -1
- package/lib/Reporting/ReportByOpeningTheReceivedFile.d.ts +1 -1
- package/lib/Reporting/ReporterFactory.js +2 -1
- package/lib/Reporting/Reporters/beyondcompareReporter.js +1 -1
- package/lib/Reporting/Reporters/codiumReporter.js +1 -1
- package/lib/Reporting/Reporters/copycommandReporter.js +4 -5
- package/lib/Reporting/Reporters/diffmergeReporter.js +1 -1
- package/lib/Reporting/Reporters/donothingReporter.js +1 -3
- package/lib/Reporting/Reporters/kdiff3Reporter.js +1 -1
- package/lib/Reporting/Reporters/meldReporter.js +1 -1
- package/lib/Reporting/Reporters/multiReporter.js +2 -2
- package/lib/Reporting/Reporters/nodediffReporter.js +14 -25
- package/lib/Reporting/Reporters/p4mergeReporter.js +31 -26
- package/lib/Reporting/Reporters/tortoisemergeReporter.js +4 -4
- package/lib/Reporting/Reporters/vimdiffReporter.js +1 -4
- package/lib/Reporting/Reporters/visualstudioReporter.js +15 -12
- package/lib/Reporting/Reporters/vscodeReporter.js +1 -1
- package/lib/Reporting/Reporters/webstormReporter.d.ts +4 -0
- package/lib/Reporting/Reporters/webstormReporter.js +41 -0
- package/lib/Scrubbers/DateScrubber.js +1 -1
- package/lib/Scrubbers/Scrubbers.js +3 -18
- package/lib/StringWriter.js +1 -1
- package/lib/Utilities/Logger/LoggingInstance.js +13 -39
- package/lib/Utilities/Logger/SimpleLogger.d.ts +1 -1
- package/lib/Utilities/Logger/SimpleLogger.js +1 -1
- package/lib/Utilities/Logger/SimpleLoggerApprovals.js +1 -1
- package/lib/Utilities/Printers.js +2 -2
- package/lib/Writers/BinaryWriter.js +7 -12
- package/lib/config.js +2 -2
- package/lib/osTools.d.ts +1 -1
- package/lib/osTools.js +0 -2
- package/lib/postRunCleanup.d.ts +1 -1
- package/lib/postRunCleanup.js +17 -17
- package/package.json +19 -2
- package/readme.md +2 -1
package/bin/index.js
CHANGED
|
@@ -46,14 +46,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
46
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
47
|
};
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
-
const event_stream_1 = __importDefault(require("event-stream"));
|
|
50
|
-
const autils = __importStar(require("../lib/AUtils"));
|
|
51
49
|
const fs_1 = __importDefault(require("fs"));
|
|
52
50
|
const path_1 = __importDefault(require("path"));
|
|
51
|
+
const event_stream_1 = __importDefault(require("event-stream"));
|
|
53
52
|
const marked_1 = require("marked");
|
|
54
53
|
const marked_terminal_renderer_1 = require("marked-terminal-renderer");
|
|
55
54
|
const minimist_1 = __importDefault(require("minimist"));
|
|
56
55
|
const Approvals_1 = require("../lib/Approvals");
|
|
56
|
+
const autils = __importStar(require("../lib/AUtils"));
|
|
57
57
|
const ConsoleUtils_1 = require("../lib/Utilities/ConsoleUtils");
|
|
58
58
|
const verbose = process.argv.includes("--verbose");
|
|
59
59
|
const printHelp = process.argv.includes("--help");
|
package/lib/AUtils.js
CHANGED
|
@@ -73,8 +73,9 @@ const isBinaryFile = (buffer) => {
|
|
|
73
73
|
};
|
|
74
74
|
exports.isBinaryFile = isBinaryFile;
|
|
75
75
|
const trimExtension = (filePath) => {
|
|
76
|
-
if (!filePath)
|
|
76
|
+
if (!filePath) {
|
|
77
77
|
return filePath;
|
|
78
|
+
}
|
|
78
79
|
const i = filePath.lastIndexOf(".");
|
|
79
80
|
const ext = i < 0 ? "" : filePath.substr(i);
|
|
80
81
|
return ext ? filePath.substring(0, filePath.length - ext.length) : filePath;
|
package/lib/Approvals.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approvals module.
|
|
3
|
+
* @module approvals
|
|
4
|
+
*/
|
|
1
5
|
import * as cfg from "./config";
|
|
2
6
|
import { Namer } from "./Core/Namer";
|
|
7
|
+
import { Writer } from "./Core/Writer";
|
|
3
8
|
import { ReporterLoader } from "./Reporting/ReporterFactory";
|
|
4
9
|
import { Scrubber, Scrubbers } from "./Scrubbers/Scrubbers";
|
|
5
|
-
import { Writer } from "./Core/Writer";
|
|
6
10
|
/**
|
|
7
11
|
* Contains some helpful and util scrubbers that can be used for scrubbing data before saving to a received file.
|
|
8
12
|
*/
|
package/lib/Approvals.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Approvals module.
|
|
4
|
+
* @module approvals
|
|
5
|
+
*/
|
|
3
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
7
|
if (k2 === undefined) k2 = k;
|
|
5
8
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -45,29 +48,24 @@ exports.verify = verify;
|
|
|
45
48
|
exports.verifyAsJSON = verifyAsJSON;
|
|
46
49
|
exports.verifyAsJSONAndScrub = verifyAsJSONAndScrub;
|
|
47
50
|
exports.verifyWithControl = verifyWithControl;
|
|
48
|
-
/**
|
|
49
|
-
* Approvals module.
|
|
50
|
-
* @module approvals
|
|
51
|
-
*/
|
|
52
|
-
const callsite_1 = __importDefault(require("callsite"));
|
|
53
51
|
const path_1 = __importDefault(require("path"));
|
|
54
52
|
const url_1 = require("url");
|
|
53
|
+
const callsite_1 = __importDefault(require("callsite"));
|
|
54
|
+
const AUtils_1 = require("./AUtils");
|
|
55
55
|
const cfg = __importStar(require("./config"));
|
|
56
|
-
const BinaryWriter_1 = require("./Writers/BinaryWriter");
|
|
57
56
|
const FileApprover_1 = require("./FileApprover");
|
|
58
57
|
const FinalMessages_1 = require("./FinalMessages");
|
|
59
58
|
const ManualNamer_1 = require("./ManualNamer");
|
|
59
|
+
const postRunCleanup_1 = require("./postRunCleanup");
|
|
60
|
+
const BeforeEachVerifierBase_1 = require("./Providers/BeforeEachVerifierBase");
|
|
61
|
+
const MochaNamer_1 = require("./Providers/Mocha/MochaNamer");
|
|
62
|
+
const OptionalFramework_1 = require("./Providers/OptionalFramework");
|
|
60
63
|
const ReporterFactory_1 = require("./Reporting/ReporterFactory");
|
|
64
|
+
const multiReporter_1 = __importDefault(require("./Reporting/Reporters/multiReporter"));
|
|
61
65
|
const Scrubbers_1 = require("./Scrubbers/Scrubbers");
|
|
62
66
|
Object.defineProperty(exports, "scrubbers", { enumerable: true, get: function () { return Scrubbers_1.Scrubbers; } });
|
|
63
67
|
const StringWriter_1 = require("./StringWriter");
|
|
64
|
-
const
|
|
65
|
-
const AUtils_1 = require("./AUtils");
|
|
66
|
-
// if someone tries to call 'require("@approval-tests/approvals")...' without calling ".mocha(...) or
|
|
67
|
-
// they won't get a helpful error. So we put this in there - just in case"
|
|
68
|
-
const MochaNamer_1 = require("./Providers/Mocha/MochaNamer");
|
|
69
|
-
const BeforeEachVerifierBase_1 = require("./Providers/BeforeEachVerifierBase");
|
|
70
|
-
const OptionalFramework_1 = require("./Providers/OptionalFramework");
|
|
68
|
+
const BinaryWriter_1 = require("./Writers/BinaryWriter");
|
|
71
69
|
if (typeof beforeEach === "function") {
|
|
72
70
|
beforeEach(function () {
|
|
73
71
|
if (!this) {
|
|
@@ -78,16 +76,15 @@ if (typeof beforeEach === "function") {
|
|
|
78
76
|
};
|
|
79
77
|
});
|
|
80
78
|
}
|
|
81
|
-
|
|
82
|
-
const listOfApprovedFiles = [];
|
|
79
|
+
const approvedFilesSeenDuringTests = [];
|
|
83
80
|
process.on("approvalFileApproved", function (fileName) {
|
|
84
|
-
if (
|
|
85
|
-
|
|
81
|
+
if (approvedFilesSeenDuringTests.indexOf(fileName) === -1) {
|
|
82
|
+
approvedFilesSeenDuringTests.push(fileName);
|
|
86
83
|
}
|
|
87
84
|
});
|
|
88
85
|
process.on("exit", function () {
|
|
89
86
|
const options = cfg.currentConfig();
|
|
90
|
-
(0, postRunCleanup_1.postRunCleanup)(options,
|
|
87
|
+
(0, postRunCleanup_1.postRunCleanup)(options, approvedFilesSeenDuringTests);
|
|
91
88
|
const finalMessages = FinalMessages_1.FinalMessages.getMessages();
|
|
92
89
|
if (finalMessages.length) {
|
|
93
90
|
console.log("******************************");
|
|
@@ -126,19 +123,23 @@ function getConfig(overrideOptions) {
|
|
|
126
123
|
* @param {*} optionalBaseDir - An optional folder to save approval files to.
|
|
127
124
|
*/
|
|
128
125
|
function mocha(optionalBaseDir) {
|
|
129
|
-
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
|
|
126
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha")) {
|
|
130
127
|
return module.exports;
|
|
131
|
-
|
|
128
|
+
}
|
|
132
129
|
if (!optionalBaseDir) {
|
|
133
|
-
|
|
134
|
-
if (fileName.startsWith("file://")) {
|
|
135
|
-
fileName = (0, url_1.fileURLToPath)(fileName);
|
|
136
|
-
}
|
|
137
|
-
optionalBaseDir = path_1.default.dirname(fileName);
|
|
130
|
+
optionalBaseDir = directoryOfCallerOfMocha();
|
|
138
131
|
}
|
|
139
132
|
(0, BeforeEachVerifierBase_1.beforeEachVerifierBase)(MochaNamer_1.MochaNamer, "require('@approval-tests/approvals').mocha();", optionalBaseDir);
|
|
140
133
|
return module.exports;
|
|
141
134
|
}
|
|
135
|
+
function directoryOfCallerOfMocha() {
|
|
136
|
+
// callsite()[0] is this function, [1] is mocha(), [2] is the test file that called mocha()
|
|
137
|
+
let fileName = (0, callsite_1.default)()[2].getFileName();
|
|
138
|
+
if (fileName.startsWith("file://")) {
|
|
139
|
+
fileName = (0, url_1.fileURLToPath)(fileName);
|
|
140
|
+
}
|
|
141
|
+
return path_1.default.dirname(fileName);
|
|
142
|
+
}
|
|
142
143
|
/**
|
|
143
144
|
* `reporters` gives access to the `MultiReporter`
|
|
144
145
|
*
|
|
@@ -157,7 +158,7 @@ exports.reporters = {
|
|
|
157
158
|
* ]
|
|
158
159
|
* });
|
|
159
160
|
*/
|
|
160
|
-
MultiReporter:
|
|
161
|
+
MultiReporter: multiReporter_1.default,
|
|
161
162
|
};
|
|
162
163
|
/**
|
|
163
164
|
* Use this to apply the scrubber function to any data before running verify.
|
|
@@ -181,17 +182,8 @@ exports.reporters = {
|
|
|
181
182
|
*/
|
|
182
183
|
function verifyAndScrub(dirName, testName, data, scrubber, optionsOverride) {
|
|
183
184
|
scrubber = scrubber || Scrubbers_1.Scrubbers.noScrubber;
|
|
184
|
-
// backwards compatible option
|
|
185
185
|
if (Array.isArray(optionsOverride)) {
|
|
186
|
-
optionsOverride =
|
|
187
|
-
reporters: optionsOverride,
|
|
188
|
-
};
|
|
189
|
-
const stringReporters = JSON.stringify(optionsOverride.reporters);
|
|
190
|
-
console.error('For the last arg of the approvals.verify(...) function, if you passed in an array of reporters, something like ["opendiff","nodediff"], this has been deprecated and replaced by passing in a config object. Please re-evaluate if you can remove this parameter alltogether and use individual user configs in ~/.approvalConfig, if not then replace this: ' +
|
|
191
|
-
stringReporters +
|
|
192
|
-
" with this { reporters: " +
|
|
193
|
-
stringReporters +
|
|
194
|
-
"}.");
|
|
186
|
+
optionsOverride = convertDeprecatedReportersArray(optionsOverride);
|
|
195
187
|
}
|
|
196
188
|
const newOptions = cfg.getConfig(optionsOverride);
|
|
197
189
|
const namer = new ManualNamer_1.ManualNamer(dirName, testName);
|
|
@@ -205,6 +197,15 @@ function verifyAndScrub(dirName, testName, data, scrubber, optionsOverride) {
|
|
|
205
197
|
}
|
|
206
198
|
verifyWithControl(namer, writer, null, newOptions);
|
|
207
199
|
}
|
|
200
|
+
function convertDeprecatedReportersArray(reporterNames) {
|
|
201
|
+
const stringReporters = JSON.stringify(reporterNames);
|
|
202
|
+
console.error('For the last arg of the approvals.verify(...) function, if you passed in an array of reporters, something like ["opendiff","nodediff"], this has been deprecated and replaced by passing in a config object. Please re-evaluate if you can remove this parameter alltogether and use individual user configs in ~/.approvalConfig, if not then replace this: ' +
|
|
203
|
+
stringReporters +
|
|
204
|
+
" with this { reporters: " +
|
|
205
|
+
stringReporters +
|
|
206
|
+
"}.");
|
|
207
|
+
return { reporters: reporterNames };
|
|
208
|
+
}
|
|
208
209
|
/**
|
|
209
210
|
*
|
|
210
211
|
* @example
|
package/lib/Core/Namer.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.convertToFilename = convertToFilename;
|
|
|
4
4
|
const StringUtils_1 = require("../Utilities/StringUtils");
|
|
5
5
|
function convertToFilename(name) {
|
|
6
6
|
const forbidden = "\\/:?\"<>|' ";
|
|
7
|
-
for (
|
|
7
|
+
for (const forbiddenKey of forbidden) {
|
|
8
8
|
name = StringUtils_1.StringUtils.replaceAll(name, forbiddenKey, "_");
|
|
9
9
|
}
|
|
10
10
|
return name;
|
package/lib/Core/Options.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Config } from "../config";
|
|
1
2
|
import type { Scrubber } from "../Scrubbers/Scrubbers";
|
|
2
3
|
import { Namer as CoreNamer } from "./Namer";
|
|
3
|
-
import { Config } from "../config";
|
|
4
4
|
import { Reporter } from "./Reporter";
|
|
5
5
|
export type ConfigModifier = (t: any) => any;
|
|
6
6
|
declare class FileOptions {
|
package/lib/Core/Options.js
CHANGED
|
@@ -23,7 +23,7 @@ class Options {
|
|
|
23
23
|
}
|
|
24
24
|
modify(key, value) {
|
|
25
25
|
const next = new Options();
|
|
26
|
-
for (const key1
|
|
26
|
+
for (const key1 of Object.keys(this.fields)) {
|
|
27
27
|
next.fields[key1] = this.fields[key1];
|
|
28
28
|
}
|
|
29
29
|
next.fields[key] = value;
|
|
@@ -33,7 +33,7 @@ class Options {
|
|
|
33
33
|
return new FileOptions(this);
|
|
34
34
|
}
|
|
35
35
|
get(key, default1) {
|
|
36
|
-
if (this.fields[key]
|
|
36
|
+
if (this.fields[key] === undefined || this.fields[key] === null) {
|
|
37
37
|
return default1();
|
|
38
38
|
}
|
|
39
39
|
return this.fields[key];
|
package/lib/FileApprover.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Config } from "./config";
|
|
2
2
|
import { Namer } from "./Core/Namer";
|
|
3
|
-
import { Writer } from "./Core/Writer";
|
|
4
3
|
import { Reporter } from "./Core/Reporter";
|
|
4
|
+
import { Writer } from "./Core/Writer";
|
|
5
5
|
import { ReporterLoader } from "./Reporting/ReporterFactory";
|
|
6
6
|
export declare class FileApprover {
|
|
7
7
|
static verify(namer: Namer, writer: Writer, reporterFactory: ReporterLoader, options?: Partial<Config>): void;
|
package/lib/FileApprover.js
CHANGED
|
@@ -6,24 +6,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.FileApprover = void 0;
|
|
7
7
|
exports.verify = verify;
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const ConsoleUtils_1 = require("./Utilities/ConsoleUtils");
|
|
10
9
|
const ApprovedFileLog_1 = require("./Logs/ApprovedFileLog");
|
|
11
10
|
const FailedFileLog_1 = require("./Logs/FailedFileLog");
|
|
11
|
+
const ConsoleUtils_1 = require("./Utilities/ConsoleUtils");
|
|
12
12
|
function normalizeLineEndings(value) {
|
|
13
13
|
return value.replace(/(?:\r\n|\r|\n)/g, "\n");
|
|
14
14
|
}
|
|
15
|
+
function assertRequiredArguments(namer, writer, reporterFactory) {
|
|
16
|
+
const missing = [
|
|
17
|
+
!namer ? "namer" : null,
|
|
18
|
+
!writer ? "writer" : null,
|
|
19
|
+
!reporterFactory ? "reporterFactory" : null,
|
|
20
|
+
].filter(Boolean);
|
|
21
|
+
if (missing.length > 0) {
|
|
22
|
+
throw new Error(`Missing required arguments: ${missing.join(", ")}.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
15
25
|
class FileApprover {
|
|
16
26
|
static verify(namer, writer, reporterFactory, options) {
|
|
17
|
-
|
|
18
|
-
const missing = [
|
|
19
|
-
!namer ? "namer" : null,
|
|
20
|
-
!writer ? "writer" : null,
|
|
21
|
-
!reporterFactory ? "reporterFactory" : null,
|
|
22
|
-
]
|
|
23
|
-
.filter(Boolean)
|
|
24
|
-
.join(", ");
|
|
25
|
-
throw new Error(`Missing required arguments: ${missing}.`);
|
|
26
|
-
}
|
|
27
|
+
assertRequiredArguments(namer, writer, reporterFactory);
|
|
27
28
|
if (!options) {
|
|
28
29
|
options = {};
|
|
29
30
|
}
|
|
@@ -38,7 +39,7 @@ class FileApprover {
|
|
|
38
39
|
}
|
|
39
40
|
const selectFirstCompatibleReporter = () => {
|
|
40
41
|
const allReporters = reporterFactory();
|
|
41
|
-
const reporter = allReporters.find((
|
|
42
|
+
const reporter = allReporters.find((r) => r.canReportOn(receivedFileName));
|
|
42
43
|
if (!reporter) {
|
|
43
44
|
throw new Error(`No compatible reporter found in configured list [${allReporters.map((r) => r.name).join(", ")}] for: ${receivedFileName}`);
|
|
44
45
|
}
|
|
@@ -74,7 +75,6 @@ class FileApprover {
|
|
|
74
75
|
if (approvedFileBufferNormalized !== receivedFileBufferNormalized) {
|
|
75
76
|
throwReporterError("Files do not match.");
|
|
76
77
|
}
|
|
77
|
-
// Delete the received file
|
|
78
78
|
fs_1.default.unlinkSync(receivedFileName);
|
|
79
79
|
process.emit("approvalFileApproved", approvedFileName);
|
|
80
80
|
}
|
package/lib/FinalMessages.js
CHANGED
|
@@ -36,8 +36,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.ApprovedFileLog = void 0;
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
|
-
const JestUtils_1 = require("../Utilities/JestUtils");
|
|
40
39
|
const JestSetup_1 = require("../Providers/Jest/JestSetup");
|
|
40
|
+
const JestUtils_1 = require("../Utilities/JestUtils");
|
|
41
41
|
const LogUtils_1 = require("./LogUtils");
|
|
42
42
|
let runOnce = false;
|
|
43
43
|
class ApprovedFileLog {
|
package/lib/Logs/LogUtils.d.ts
CHANGED
|
@@ -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
|
|
5
|
+
private static downloadScriptsIfMissing;
|
|
6
6
|
private static downloadFile;
|
|
7
7
|
}
|
package/lib/Logs/LogUtils.js
CHANGED
|
@@ -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.
|
|
28
|
+
this.downloadScriptsIfMissing().then();
|
|
29
29
|
return this.APPROVAL_TEMP_DIRECTORY;
|
|
30
30
|
}
|
|
31
|
-
static
|
|
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 (
|
|
51
|
-
//
|
|
50
|
+
catch (_a) {
|
|
51
|
+
// Best-effort download: being offline or GitHub failing must not break tests.
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
}
|
package/lib/ManualNamer.js
CHANGED
|
@@ -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
|
}
|
|
@@ -34,48 +34,42 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.beforeEachVerifierBase = beforeEachVerifierBase;
|
|
37
|
-
const _ = __importStar(require("lodash"));
|
|
38
37
|
const fs = __importStar(require("fs"));
|
|
38
|
+
const _ = __importStar(require("lodash"));
|
|
39
|
+
const aUtils = __importStar(require("../AUtils"));
|
|
39
40
|
const cfg = __importStar(require("../config"));
|
|
40
|
-
const StringWriter_1 = require("../StringWriter");
|
|
41
41
|
const FileApprover_1 = require("../FileApprover");
|
|
42
42
|
const ReporterFactory_1 = require("../Reporting/ReporterFactory");
|
|
43
|
-
const
|
|
43
|
+
const StringWriter_1 = require("../StringWriter");
|
|
44
44
|
function beforeEachLoaderFunction(Namer, dirName, that) {
|
|
45
|
-
// Add methods to the test context
|
|
46
45
|
that.approvals = { getCurrentReporters };
|
|
47
46
|
that.verify = verify;
|
|
48
47
|
that.verifyAsJSON = verifyAsJSON;
|
|
49
48
|
function getCurrentReporters(options) {
|
|
50
49
|
options = options || cfg.currentConfig();
|
|
51
|
-
|
|
52
|
-
return reporterCandidates;
|
|
50
|
+
return ReporterFactory_1.ReporterFactory.loadAllReporters(options.reporters);
|
|
53
51
|
}
|
|
54
52
|
function verify(data, overrideOptions) {
|
|
55
|
-
|
|
56
|
-
const context = this;
|
|
57
|
-
const namer = new Namer(context, dirName);
|
|
53
|
+
const namer = new Namer(this, dirName);
|
|
58
54
|
const newOptions = _.defaults(overrideOptions || {}, cfg.currentConfig());
|
|
59
|
-
const reporterFactory =
|
|
60
|
-
return { getCurrentReporters }.getCurrentReporters(newOptions);
|
|
61
|
-
};
|
|
55
|
+
const reporterFactory = () => getCurrentReporters(newOptions);
|
|
62
56
|
const writer = new StringWriter_1.StringWriter(newOptions, data);
|
|
63
57
|
FileApprover_1.FileApprover.verify(namer, writer, reporterFactory);
|
|
64
58
|
}
|
|
65
59
|
function verifyAsJSON(data, overrideOptions) {
|
|
66
|
-
// @ts-ignore
|
|
67
60
|
this.verify(aUtils.stringifyKeysInOrder(data), overrideOptions);
|
|
68
61
|
}
|
|
69
62
|
}
|
|
70
|
-
function
|
|
63
|
+
function ensureDirectoryExists(dirName, usageSample) {
|
|
71
64
|
if (!fs.existsSync(dirName)) {
|
|
72
65
|
fs.mkdirSync(dirName);
|
|
73
66
|
}
|
|
74
|
-
|
|
75
|
-
const stats = fs.lstatSync(dirName);
|
|
76
|
-
if (!stats.isDirectory()) {
|
|
67
|
+
if (!fs.lstatSync(dirName).isDirectory()) {
|
|
77
68
|
throw new Error(`Invalid directory [${dirName}]. Try using the following syntax. > ${usageSample}`);
|
|
78
69
|
}
|
|
70
|
+
}
|
|
71
|
+
function beforeEachVerifierBase(Namer, usageSample, dirName) {
|
|
72
|
+
ensureDirectoryExists(dirName, usageSample);
|
|
79
73
|
beforeEach(function () {
|
|
80
74
|
return beforeEachLoaderFunction(Namer, dirName, this);
|
|
81
75
|
});
|
|
@@ -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
|
}
|
|
@@ -36,32 +36,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.verify = verify;
|
|
37
37
|
exports.verifyAsJson = verifyAsJson;
|
|
38
38
|
exports.verifyAll = verifyAll;
|
|
39
|
-
const
|
|
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
|
-
*/
|
|
39
|
+
const approvals = __importStar(require("../../Approvals"));
|
|
51
40
|
const Options_1 = require("../../Core/Options");
|
|
52
|
-
const JestNamer_1 = require("./JestNamer");
|
|
53
41
|
const StringWriter_1 = require("../../StringWriter");
|
|
54
|
-
const
|
|
42
|
+
const Printers_1 = require("../../Utilities/Printers");
|
|
55
43
|
const OptionalFramework_1 = require("../OptionalFramework");
|
|
44
|
+
const JestNamer_1 = require("./JestNamer");
|
|
56
45
|
function verify(sut, options) {
|
|
57
|
-
if (!(0, OptionalFramework_1.isFrameworkAvailable)("jest"))
|
|
46
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("jest")) {
|
|
58
47
|
return;
|
|
48
|
+
}
|
|
59
49
|
options = options || new Options_1.Options();
|
|
60
50
|
options = options.withNamer((0, JestNamer_1.getJestNamer)());
|
|
61
51
|
const config = options.getConfig(approvals.getConfig());
|
|
62
52
|
const scrubbed = options.scrub(`${sut}`);
|
|
63
53
|
const writer = new StringWriter_1.StringWriter(config, scrubbed, options.forFile().getFileExtension());
|
|
64
|
-
|
|
54
|
+
const namer = options.getNamer();
|
|
65
55
|
approvals.verifyWithControl(namer, writer, null, config);
|
|
66
56
|
}
|
|
67
57
|
function verifyAsJson(data, options) {
|
|
@@ -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("../../
|
|
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,
|
|
17
|
-
return new
|
|
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
|
-
|
|
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
|
-
|
|
22
|
-
|
|
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;
|
|
@@ -42,27 +42,18 @@ exports.getNamer = getNamer;
|
|
|
42
42
|
exports.verify = verify;
|
|
43
43
|
exports.verifyAsJson = verifyAsJson;
|
|
44
44
|
exports.verifyAll = verifyAll;
|
|
45
|
-
const
|
|
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
|
-
*/
|
|
45
|
+
const approvals = __importStar(require("../../Approvals"));
|
|
57
46
|
const Options_1 = require("../../Core/Options");
|
|
58
|
-
const MochaNamer_1 = require("./MochaNamer");
|
|
59
|
-
const OptionalFramework_1 = require("../OptionalFramework");
|
|
60
47
|
const StringWriter_1 = __importDefault(require("../../StringWriter"));
|
|
61
|
-
const
|
|
48
|
+
const Printers_1 = require("../../Utilities/Printers");
|
|
49
|
+
const OptionalFramework_1 = require("../OptionalFramework");
|
|
50
|
+
const MochaNamer_1 = require("./MochaNamer");
|
|
62
51
|
let mochaTest = null;
|
|
63
52
|
function it2(label, test) {
|
|
64
|
-
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
|
|
53
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha")) {
|
|
65
54
|
return;
|
|
55
|
+
}
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
66
57
|
const mocha = require("mocha");
|
|
67
58
|
mocha.it(label, function () {
|
|
68
59
|
mochaTest = this;
|
|
@@ -72,16 +63,18 @@ function it2(label, test) {
|
|
|
72
63
|
}
|
|
73
64
|
let namer;
|
|
74
65
|
function setNamer(that) {
|
|
75
|
-
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
|
|
66
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha")) {
|
|
76
67
|
return;
|
|
68
|
+
}
|
|
77
69
|
namer = (0, MochaNamer_1.getMochaNamer)(that.currentTest);
|
|
78
70
|
}
|
|
79
71
|
function getNamer() {
|
|
80
72
|
return namer;
|
|
81
73
|
}
|
|
82
74
|
function verify(sut, options) {
|
|
83
|
-
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
|
|
75
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha")) {
|
|
84
76
|
return;
|
|
77
|
+
}
|
|
85
78
|
options = options || new Options_1.Options();
|
|
86
79
|
options = options.withNamer(getNamer());
|
|
87
80
|
const config = options.getConfig(approvals.getConfig());
|
|
@@ -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:
|
|
5
|
+
constructor(mochaTest: Context, overrideBasePath?: string);
|
|
6
6
|
getFullTestName(testContext: Runnable): string;
|
|
7
7
|
pathCreator(type: string, ext: string): string;
|
|
8
8
|
}
|