@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.
- package/bin/index.js +3 -37
- package/lib/AUtils.js +21 -48
- package/lib/Approvals.d.ts +9 -5
- package/lib/Approvals.js +44 -76
- 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.d.ts +2 -0
- package/lib/FinalMessages.js +5 -1
- package/lib/Logs/ApprovedFileLog.js +9 -39
- package/lib/Logs/FailedFileLog.js +8 -38
- 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 +21 -57
- package/lib/Providers/Jest/CombinationApprovals.js +1 -1
- package/lib/Providers/Jest/JestApprovals.js +8 -51
- 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 +13 -53
- package/lib/Providers/Mocha/MochaNamer.d.ts +2 -2
- package/lib/Providers/Mocha/MochaNamer.js +8 -9
- package/lib/Providers/Vitest/VitestApprovals.js +8 -40
- 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/GenericDiffReporterBase.js +9 -42
- package/lib/Reporting/ReportByOpeningTheReceivedFile.d.ts +1 -1
- package/lib/Reporting/ReportLaunchingCircuitBreaker.d.ts +2 -0
- package/lib/Reporting/ReportLaunchingCircuitBreaker.js +6 -0
- 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 +6 -36
- package/lib/Reporting/Reporters/donothingReporter.js +1 -3
- package/lib/Reporting/Reporters/gitdiffReporter.js +0 -1
- 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 +15 -26
- package/lib/Reporting/Reporters/p4mergeReporter.js +27 -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.js +1 -1
- package/lib/Scrubbers/DateScrubber.js +1 -1
- package/lib/Scrubbers/Scrubbers.js +3 -18
- package/lib/StringWriter.js +10 -40
- 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 +15 -50
- package/lib/config.js +15 -45
- 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 -6
- package/readme.md +1 -1
package/bin/index.js
CHANGED
|
@@ -1,38 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
3
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
4
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
5
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -46,14 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
14
|
};
|
|
48
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
-
const event_stream_1 = __importDefault(require("event-stream"));
|
|
50
|
-
const autils = __importStar(require("../lib/AUtils"));
|
|
51
16
|
const fs_1 = __importDefault(require("fs"));
|
|
52
17
|
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const event_stream_1 = __importDefault(require("event-stream"));
|
|
53
19
|
const marked_1 = require("marked");
|
|
54
20
|
const marked_terminal_renderer_1 = require("marked-terminal-renderer");
|
|
55
21
|
const minimist_1 = __importDefault(require("minimist"));
|
|
56
22
|
const Approvals_1 = require("../lib/Approvals");
|
|
23
|
+
const AUtils_1 = require("../lib/AUtils");
|
|
57
24
|
const ConsoleUtils_1 = require("../lib/Utilities/ConsoleUtils");
|
|
58
25
|
const verbose = process.argv.includes("--verbose");
|
|
59
26
|
const printHelp = process.argv.includes("--help");
|
|
@@ -121,8 +88,7 @@ function main() {
|
|
|
121
88
|
console.log("approval opts: ", opts);
|
|
122
89
|
}
|
|
123
90
|
opts.forceApproveAll =
|
|
124
|
-
|
|
125
|
-
autils.hasCommandLineArgument("-f");
|
|
91
|
+
(0, AUtils_1.hasCommandLineArgument)("--forceapproveall") || (0, AUtils_1.hasCommandLineArgument)("-f");
|
|
126
92
|
process.stdin.pipe(event_stream_1.default.mapSync((data) => {
|
|
127
93
|
const dataToVerify = data.toString();
|
|
128
94
|
(0, Approvals_1.configure)(opts);
|
package/lib/AUtils.js
CHANGED
|
@@ -1,58 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
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.stringifyKeysInOrder = exports.fixFilePathSlashes = exports.searchForExecutable = exports.findProgramOnPath = exports.isBinaryFile = exports.hasCommandLineArgument = exports.assertFileExists = exports.createEmptyFileIfNotExists = void 0;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const shelljs_1 = __importDefault(require("shelljs"));
|
|
10
|
+
const osTools_1 = require("./osTools");
|
|
41
11
|
const _cachedProgramLookups = {};
|
|
42
12
|
const createEmptyFileIfNotExists = (file) => {
|
|
43
|
-
if (!
|
|
44
|
-
const ext = (
|
|
13
|
+
if (!fs_1.default.existsSync(file)) {
|
|
14
|
+
const ext = (path_1.default.extname(file) || "").toLowerCase();
|
|
45
15
|
if (ext === ".png") {
|
|
46
|
-
|
|
16
|
+
fs_1.default.writeFileSync(file, fs_1.default.readFileSync(path_1.default.join(__dirname, "DummyApprovedFiles", "UnapprovedImage.png")));
|
|
47
17
|
}
|
|
48
18
|
else {
|
|
49
|
-
|
|
19
|
+
fs_1.default.writeFileSync(file, "");
|
|
50
20
|
}
|
|
51
21
|
}
|
|
52
22
|
};
|
|
53
23
|
exports.createEmptyFileIfNotExists = createEmptyFileIfNotExists;
|
|
54
24
|
const assertFileExists = (file) => {
|
|
55
|
-
if (!
|
|
25
|
+
if (!fs_1.default.existsSync(file)) {
|
|
56
26
|
throw new Error("File not found: " + file);
|
|
57
27
|
}
|
|
58
28
|
};
|
|
@@ -73,8 +43,9 @@ const isBinaryFile = (buffer) => {
|
|
|
73
43
|
};
|
|
74
44
|
exports.isBinaryFile = isBinaryFile;
|
|
75
45
|
const trimExtension = (filePath) => {
|
|
76
|
-
if (!filePath)
|
|
46
|
+
if (!filePath) {
|
|
77
47
|
return filePath;
|
|
48
|
+
}
|
|
78
49
|
const i = filePath.lastIndexOf(".");
|
|
79
50
|
const ext = i < 0 ? "" : filePath.substr(i);
|
|
80
51
|
return ext ? filePath.substring(0, filePath.length - ext.length) : filePath;
|
|
@@ -83,12 +54,14 @@ const findProgramOnPath = (programName) => {
|
|
|
83
54
|
if (_cachedProgramLookups.hasOwnProperty(programName)) {
|
|
84
55
|
return _cachedProgramLookups[programName];
|
|
85
56
|
}
|
|
86
|
-
const output =
|
|
57
|
+
const output = shelljs_1.default.exec(`${osTools_1.findProgramPathCommand} ${programName}`, {
|
|
58
|
+
silent: true,
|
|
59
|
+
});
|
|
87
60
|
let result = null;
|
|
88
61
|
if (output.stdout) {
|
|
89
62
|
const file = output.stdout.split("\n")[0].trim();
|
|
90
63
|
const fixedFile = fixFilePathSlashes(file);
|
|
91
|
-
if (
|
|
64
|
+
if (fs_1.default.existsSync(fixedFile)) {
|
|
92
65
|
result = fixedFile;
|
|
93
66
|
}
|
|
94
67
|
}
|
|
@@ -112,7 +85,7 @@ const searchForExecutable = (folderInProgramInFiles, fileName) => {
|
|
|
112
85
|
return programOnPath;
|
|
113
86
|
}
|
|
114
87
|
const lookInProgramFiles = (fileName_) => {
|
|
115
|
-
if (
|
|
88
|
+
if (osTools_1.platform.isWindows) {
|
|
116
89
|
let tryVar = findInPath("C:/Program Files", folderInProgramInFiles || "", fileName_);
|
|
117
90
|
if (tryVar) {
|
|
118
91
|
return tryVar;
|
|
@@ -125,9 +98,9 @@ const searchForExecutable = (folderInProgramInFiles, fileName) => {
|
|
|
125
98
|
return null;
|
|
126
99
|
};
|
|
127
100
|
const findInPath = (root, dir, file) => {
|
|
128
|
-
const fullPath =
|
|
101
|
+
const fullPath = path_1.default.join(root, dir, file);
|
|
129
102
|
const fixedFullPath = fixFilePathSlashes(fullPath);
|
|
130
|
-
if (
|
|
103
|
+
if (fs_1.default.existsSync(fixedFullPath)) {
|
|
131
104
|
return fixedFullPath;
|
|
132
105
|
}
|
|
133
106
|
return null;
|
package/lib/Approvals.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Approvals module.
|
|
3
|
+
* @module approvals
|
|
4
|
+
*/
|
|
5
|
+
import { Config } 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
|
*/
|
|
@@ -18,13 +22,13 @@ export { Scrubbers as scrubbers };
|
|
|
18
22
|
*
|
|
19
23
|
* @param {*} overrideOptions
|
|
20
24
|
*/
|
|
21
|
-
export declare function configure(overrideOptions:
|
|
25
|
+
export declare function configure(overrideOptions: Config): typeof module.exports;
|
|
22
26
|
/**
|
|
23
27
|
* Allows the creation of an approvals configuration object using any passed in options to override the defaults.
|
|
24
28
|
* @param {Object} overrideOptions
|
|
25
29
|
* @returns {Object} approvals config object with any options overridden.
|
|
26
30
|
*/
|
|
27
|
-
export declare function getConfig(overrideOptions?:
|
|
31
|
+
export declare function getConfig(overrideOptions?: Config): Config;
|
|
28
32
|
/**
|
|
29
33
|
* Configure approvals to hook into Mocha tests.
|
|
30
34
|
* @param {*} optionalBaseDir - An optional folder to save approval files to.
|
|
@@ -101,4 +105,4 @@ export declare function verifyAsJSONAndScrub(dirName: string, testName: string,
|
|
|
101
105
|
* @param {Function} [reporterFactory]
|
|
102
106
|
* @param {Object} [optionsOverride]
|
|
103
107
|
*/
|
|
104
|
-
export declare function verifyWithControl(namer: Namer, writer: Writer, reporterFactory?: ReporterLoader | null, optionsOverride?: Partial<
|
|
108
|
+
export declare function verifyWithControl(namer: Namer, writer: Writer, reporterFactory?: ReporterLoader | null, optionsOverride?: Partial<Config>): void;
|
package/lib/Approvals.js
CHANGED
|
@@ -1,38 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
2
|
+
/**
|
|
3
|
+
* Approvals module.
|
|
4
|
+
* @module approvals
|
|
5
|
+
*/
|
|
36
6
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
8
|
};
|
|
@@ -45,29 +15,24 @@ exports.verify = verify;
|
|
|
45
15
|
exports.verifyAsJSON = verifyAsJSON;
|
|
46
16
|
exports.verifyAsJSONAndScrub = verifyAsJSONAndScrub;
|
|
47
17
|
exports.verifyWithControl = verifyWithControl;
|
|
48
|
-
/**
|
|
49
|
-
* Approvals module.
|
|
50
|
-
* @module approvals
|
|
51
|
-
*/
|
|
52
|
-
const callsite_1 = __importDefault(require("callsite"));
|
|
53
18
|
const path_1 = __importDefault(require("path"));
|
|
54
19
|
const url_1 = require("url");
|
|
55
|
-
const
|
|
56
|
-
const
|
|
20
|
+
const callsite_1 = __importDefault(require("callsite"));
|
|
21
|
+
const AUtils_1 = require("./AUtils");
|
|
22
|
+
const config_1 = require("./config");
|
|
57
23
|
const FileApprover_1 = require("./FileApprover");
|
|
58
24
|
const FinalMessages_1 = require("./FinalMessages");
|
|
59
25
|
const ManualNamer_1 = require("./ManualNamer");
|
|
26
|
+
const postRunCleanup_1 = require("./postRunCleanup");
|
|
27
|
+
const BeforeEachVerifierBase_1 = require("./Providers/BeforeEachVerifierBase");
|
|
28
|
+
const MochaNamer_1 = require("./Providers/Mocha/MochaNamer");
|
|
29
|
+
const OptionalFramework_1 = require("./Providers/OptionalFramework");
|
|
60
30
|
const ReporterFactory_1 = require("./Reporting/ReporterFactory");
|
|
31
|
+
const multiReporter_1 = __importDefault(require("./Reporting/Reporters/multiReporter"));
|
|
61
32
|
const Scrubbers_1 = require("./Scrubbers/Scrubbers");
|
|
62
33
|
Object.defineProperty(exports, "scrubbers", { enumerable: true, get: function () { return Scrubbers_1.Scrubbers; } });
|
|
63
34
|
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");
|
|
35
|
+
const BinaryWriter_1 = require("./Writers/BinaryWriter");
|
|
71
36
|
if (typeof beforeEach === "function") {
|
|
72
37
|
beforeEach(function () {
|
|
73
38
|
if (!this) {
|
|
@@ -78,16 +43,15 @@ if (typeof beforeEach === "function") {
|
|
|
78
43
|
};
|
|
79
44
|
});
|
|
80
45
|
}
|
|
81
|
-
|
|
82
|
-
const listOfApprovedFiles = [];
|
|
46
|
+
const approvedFilesSeenDuringTests = [];
|
|
83
47
|
process.on("approvalFileApproved", function (fileName) {
|
|
84
|
-
if (
|
|
85
|
-
|
|
48
|
+
if (approvedFilesSeenDuringTests.indexOf(fileName) === -1) {
|
|
49
|
+
approvedFilesSeenDuringTests.push(fileName);
|
|
86
50
|
}
|
|
87
51
|
});
|
|
88
52
|
process.on("exit", function () {
|
|
89
|
-
const options =
|
|
90
|
-
(0, postRunCleanup_1.postRunCleanup)(options,
|
|
53
|
+
const options = (0, config_1.currentConfig)();
|
|
54
|
+
(0, postRunCleanup_1.postRunCleanup)(options, approvedFilesSeenDuringTests);
|
|
91
55
|
const finalMessages = FinalMessages_1.FinalMessages.getMessages();
|
|
92
56
|
if (finalMessages.length) {
|
|
93
57
|
console.log("******************************");
|
|
@@ -110,7 +74,7 @@ process.on("exit", function () {
|
|
|
110
74
|
* @param {*} overrideOptions
|
|
111
75
|
*/
|
|
112
76
|
function configure(overrideOptions) {
|
|
113
|
-
|
|
77
|
+
(0, config_1.configure)(overrideOptions);
|
|
114
78
|
return module.exports;
|
|
115
79
|
}
|
|
116
80
|
/**
|
|
@@ -119,26 +83,30 @@ function configure(overrideOptions) {
|
|
|
119
83
|
* @returns {Object} approvals config object with any options overridden.
|
|
120
84
|
*/
|
|
121
85
|
function getConfig(overrideOptions) {
|
|
122
|
-
return
|
|
86
|
+
return (0, config_1.getConfig)(overrideOptions);
|
|
123
87
|
}
|
|
124
88
|
/**
|
|
125
89
|
* Configure approvals to hook into Mocha tests.
|
|
126
90
|
* @param {*} optionalBaseDir - An optional folder to save approval files to.
|
|
127
91
|
*/
|
|
128
92
|
function mocha(optionalBaseDir) {
|
|
129
|
-
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
|
|
93
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha")) {
|
|
130
94
|
return module.exports;
|
|
131
|
-
|
|
95
|
+
}
|
|
132
96
|
if (!optionalBaseDir) {
|
|
133
|
-
|
|
134
|
-
if (fileName.startsWith("file://")) {
|
|
135
|
-
fileName = (0, url_1.fileURLToPath)(fileName);
|
|
136
|
-
}
|
|
137
|
-
optionalBaseDir = path_1.default.dirname(fileName);
|
|
97
|
+
optionalBaseDir = directoryOfCallerOfMocha();
|
|
138
98
|
}
|
|
139
99
|
(0, BeforeEachVerifierBase_1.beforeEachVerifierBase)(MochaNamer_1.MochaNamer, "require('@approval-tests/approvals').mocha();", optionalBaseDir);
|
|
140
100
|
return module.exports;
|
|
141
101
|
}
|
|
102
|
+
function directoryOfCallerOfMocha() {
|
|
103
|
+
// callsite()[0] is this function, [1] is mocha(), [2] is the test file that called mocha()
|
|
104
|
+
let fileName = (0, callsite_1.default)()[2].getFileName();
|
|
105
|
+
if (fileName.startsWith("file://")) {
|
|
106
|
+
fileName = (0, url_1.fileURLToPath)(fileName);
|
|
107
|
+
}
|
|
108
|
+
return path_1.default.dirname(fileName);
|
|
109
|
+
}
|
|
142
110
|
/**
|
|
143
111
|
* `reporters` gives access to the `MultiReporter`
|
|
144
112
|
*
|
|
@@ -157,7 +125,7 @@ exports.reporters = {
|
|
|
157
125
|
* ]
|
|
158
126
|
* });
|
|
159
127
|
*/
|
|
160
|
-
MultiReporter:
|
|
128
|
+
MultiReporter: multiReporter_1.default,
|
|
161
129
|
};
|
|
162
130
|
/**
|
|
163
131
|
* Use this to apply the scrubber function to any data before running verify.
|
|
@@ -181,19 +149,10 @@ exports.reporters = {
|
|
|
181
149
|
*/
|
|
182
150
|
function verifyAndScrub(dirName, testName, data, scrubber, optionsOverride) {
|
|
183
151
|
scrubber = scrubber || Scrubbers_1.Scrubbers.noScrubber;
|
|
184
|
-
// backwards compatible option
|
|
185
152
|
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
|
-
"}.");
|
|
153
|
+
optionsOverride = convertDeprecatedReportersArray(optionsOverride);
|
|
195
154
|
}
|
|
196
|
-
const newOptions =
|
|
155
|
+
const newOptions = (0, config_1.getConfig)(optionsOverride);
|
|
197
156
|
const namer = new ManualNamer_1.ManualNamer(dirName, testName);
|
|
198
157
|
let writer;
|
|
199
158
|
if (data instanceof Buffer) {
|
|
@@ -205,6 +164,15 @@ function verifyAndScrub(dirName, testName, data, scrubber, optionsOverride) {
|
|
|
205
164
|
}
|
|
206
165
|
verifyWithControl(namer, writer, null, newOptions);
|
|
207
166
|
}
|
|
167
|
+
function convertDeprecatedReportersArray(reporterNames) {
|
|
168
|
+
const stringReporters = JSON.stringify(reporterNames);
|
|
169
|
+
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: ' +
|
|
170
|
+
stringReporters +
|
|
171
|
+
" with this { reporters: " +
|
|
172
|
+
stringReporters +
|
|
173
|
+
"}.");
|
|
174
|
+
return { reporters: reporterNames };
|
|
175
|
+
}
|
|
208
176
|
/**
|
|
209
177
|
*
|
|
210
178
|
* @example
|
|
@@ -274,7 +242,7 @@ function verifyAsJSONAndScrub(dirName, testName, data, scrubber, optionsOverride
|
|
|
274
242
|
* @param {Object} [optionsOverride]
|
|
275
243
|
*/
|
|
276
244
|
function verifyWithControl(namer, writer, reporterFactory, optionsOverride) {
|
|
277
|
-
const newOptions =
|
|
245
|
+
const newOptions = (0, config_1.getConfig)(optionsOverride);
|
|
278
246
|
const loader = reporterFactory ||
|
|
279
247
|
function () {
|
|
280
248
|
return [ReporterFactory_1.ReporterFactory.loadReporter(newOptions.reporters)];
|
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.d.ts
CHANGED
package/lib/FinalMessages.js
CHANGED
|
@@ -9,8 +9,12 @@ class FinalMessages {
|
|
|
9
9
|
static addKeyMessage(key, message) {
|
|
10
10
|
messages[key] = message;
|
|
11
11
|
}
|
|
12
|
+
/** Removes all messages; intended for tests only. */
|
|
13
|
+
static clear() {
|
|
14
|
+
messages.length = 0;
|
|
15
|
+
Object.keys(messages).forEach((key) => delete messages[key]);
|
|
16
|
+
}
|
|
12
17
|
static getMessages() {
|
|
13
|
-
//return messages;
|
|
14
18
|
return Object.keys(messages).map((x) => messages[x]);
|
|
15
19
|
}
|
|
16
20
|
}
|
|
@@ -1,43 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
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.ApprovedFileLog = void 0;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const JestUtils_1 = require("../Utilities/JestUtils");
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
40
9
|
const JestSetup_1 = require("../Providers/Jest/JestSetup");
|
|
10
|
+
const JestUtils_1 = require("../Utilities/JestUtils");
|
|
41
11
|
const LogUtils_1 = require("./LogUtils");
|
|
42
12
|
let runOnce = false;
|
|
43
13
|
class ApprovedFileLog {
|
|
@@ -54,15 +24,15 @@ class ApprovedFileLog {
|
|
|
54
24
|
}
|
|
55
25
|
static forceClearLogFile() {
|
|
56
26
|
const logFilePath = this.getLogFilePath();
|
|
57
|
-
|
|
27
|
+
fs_1.default.writeFileSync(logFilePath, "");
|
|
58
28
|
}
|
|
59
29
|
static getLogFilePath() {
|
|
60
|
-
return
|
|
30
|
+
return path_1.default.join(LogUtils_1.LogUtils.ensureTempDirectoryExists(), ".approved_files.log");
|
|
61
31
|
}
|
|
62
32
|
static log(filePath) {
|
|
63
33
|
this.clearLogFile();
|
|
64
34
|
const logFilePath = this.getLogFilePath();
|
|
65
|
-
|
|
35
|
+
fs_1.default.appendFileSync(logFilePath, filePath + "\n");
|
|
66
36
|
}
|
|
67
37
|
}
|
|
68
38
|
exports.ApprovedFileLog = ApprovedFileLog;
|