@approval-tests/approvals 7.5.8 → 7.5.10
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/help.md +7 -7
- package/bin/index.js +81 -64
- package/bin/index.ts +73 -71
- package/lib/Approvals.d.ts +1 -1
- package/lib/Approvals.js +4 -1
- package/lib/Approvals.ts +3 -1
- package/lib/Providers/Jest/JestApprovals.js +3 -0
- package/lib/Providers/Jest/JestApprovals.ts +2 -0
- package/lib/Providers/Jest/JestNamer.js +2 -2
- package/lib/Providers/Jest/JestNamer.ts +1 -1
- package/lib/Providers/Jest/JestReporter.js +6 -3
- package/lib/Providers/Jest/JestReporter.ts +5 -2
- package/lib/Providers/Mocha/MochaApprovals.js +9 -2
- package/lib/Providers/Mocha/MochaApprovals.ts +5 -1
- package/lib/Providers/Mocha/MochaNamer.d.ts +1 -1
- package/lib/Providers/Mocha/MochaNamer.ts +1 -1
- package/lib/Providers/OptionalFramework.d.ts +1 -0
- package/lib/Providers/OptionalFramework.js +15 -0
- package/lib/Providers/OptionalFramework.ts +11 -0
- package/lib/Providers/Vitest/VitestApprovals.js +3 -0
- package/lib/Providers/Vitest/VitestApprovals.ts +2 -0
- package/lib/Providers/Vitest/VitestReporter.js +4 -1
- package/lib/Providers/Vitest/VitestReporter.ts +3 -1
- package/lib/Writers/BinaryWriter.js +2 -2
- package/lib/Writers/BinaryWriter.ts +2 -2
- package/package.json +32 -25
- package/readme.md +26 -23
package/bin/help.md
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
`approvals testName [options]`
|
|
4
4
|
|
|
5
|
-
| Arg
|
|
6
|
-
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
7
|
-
|
|
|
8
|
-
|
|
|
9
|
-
|
|
|
10
|
-
|
|
|
11
|
-
|
|
|
5
|
+
| Arg | Description |
|
|
6
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
7
|
+
| [-f \| --forceapproveall] | Skip the approve step and apply the results to the .approved.txt file (good for a first time run) |
|
|
8
|
+
| [--reporter difftool] | supports multiple EX: `--reporter opendiff --reporter gitdiff` |
|
|
9
|
+
| [--outdir] | dir to place approval file - defaults to current directory |
|
|
10
|
+
| [--verbose] | extra debug info |
|
|
11
|
+
| TODO: | We need to extend the supported args to include other approval options. (file an [issue](https://github.com/approvals/Approvals.NodeJS/issues) if you need one that's not here) |
|
|
12
12
|
|
|
13
13
|
# Examples
|
|
14
14
|
|
package/bin/index.js
CHANGED
|
@@ -33,6 +33,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
return result;
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
36
45
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
46
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
47
|
};
|
|
@@ -41,79 +50,87 @@ const event_stream_1 = __importDefault(require("event-stream"));
|
|
|
41
50
|
const autils = __importStar(require("../lib/AUtils"));
|
|
42
51
|
const fs_1 = __importDefault(require("fs"));
|
|
43
52
|
const path_1 = __importDefault(require("path"));
|
|
44
|
-
const marked_1 =
|
|
45
|
-
const
|
|
53
|
+
const marked_1 = require("marked");
|
|
54
|
+
const marked_terminal_renderer_1 = require("marked-terminal-renderer");
|
|
46
55
|
const minimist_1 = __importDefault(require("minimist"));
|
|
47
56
|
const Approvals_1 = require("../lib/Approvals");
|
|
48
57
|
const ConsoleUtils_1 = require("../lib/Utilities/ConsoleUtils");
|
|
49
58
|
const verbose = process.argv.includes("--verbose");
|
|
50
59
|
const printHelp = process.argv.includes("--help");
|
|
51
60
|
function printHelpMessage() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
if (verbose) {
|
|
63
|
+
console.log("printing help...");
|
|
64
|
+
}
|
|
65
|
+
const helpFile = fs_1.default.readFileSync(path_1.default.join(__dirname, "help.md"), "utf8");
|
|
66
|
+
marked_1.marked.use((0, marked_terminal_renderer_1.createTerminalRenderer)((0, marked_terminal_renderer_1.darkTheme)()));
|
|
67
|
+
console.log(yield marked_1.marked.parse(helpFile));
|
|
58
68
|
});
|
|
59
|
-
let output = marked_1.default.parse(helpFile);
|
|
60
|
-
output = output.replace(/ /g, " ");
|
|
61
|
-
console.log(output);
|
|
62
69
|
}
|
|
63
70
|
function errAndExit(msg) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
printHelpMessage();
|
|
70
|
-
process.exit();
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
yield printHelpMessage();
|
|
73
|
+
console.log((0, ConsoleUtils_1.redText)(msg));
|
|
74
|
+
process.exit(1);
|
|
75
|
+
});
|
|
71
76
|
}
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
function main() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
if (printHelp) {
|
|
80
|
+
yield printHelpMessage();
|
|
81
|
+
process.exit();
|
|
82
|
+
}
|
|
83
|
+
if (verbose) {
|
|
84
|
+
console.log("process.argv: ", process.argv);
|
|
85
|
+
}
|
|
86
|
+
const argv = (0, minimist_1.default)(process.argv.slice(2), {
|
|
87
|
+
alias: {
|
|
88
|
+
reporters: ["r"],
|
|
89
|
+
},
|
|
90
|
+
boolean: ["verbose"],
|
|
91
|
+
});
|
|
92
|
+
if (verbose) {
|
|
93
|
+
console.log("parsed args: ", argv);
|
|
94
|
+
}
|
|
95
|
+
let reporters = argv.reporter;
|
|
96
|
+
if (typeof reporters === "string") {
|
|
97
|
+
reporters = [reporters];
|
|
98
|
+
}
|
|
99
|
+
const testname = argv._[0];
|
|
100
|
+
if (!testname) {
|
|
101
|
+
yield errAndExit('Missing parameter: supply a test name ex: echo "hello" | approvals myFirstTest. This will become the file name myFirstTest.approved.txt in the current directory');
|
|
102
|
+
}
|
|
103
|
+
const outdir = argv.outdir || process.cwd();
|
|
104
|
+
if (!fs_1.default.existsSync(outdir)) {
|
|
105
|
+
yield errAndExit("Directory not found: " + outdir);
|
|
106
|
+
}
|
|
107
|
+
const errorOnStaleApprovedFiles = argv.errorOnStaleApprovedFiles === "true";
|
|
108
|
+
if (verbose) {
|
|
109
|
+
console.log("outdir: ", outdir);
|
|
110
|
+
console.log("errorOnStaleApprovedFiles: ", errorOnStaleApprovedFiles);
|
|
111
|
+
console.log("testname: ", testname);
|
|
112
|
+
console.log("reporters: ", reporters ||
|
|
113
|
+
"undefined (but will fallback to approvals preconfigure defaults)");
|
|
114
|
+
}
|
|
115
|
+
const opts = {};
|
|
116
|
+
if (reporters) {
|
|
117
|
+
opts.reporters = reporters;
|
|
118
|
+
}
|
|
119
|
+
opts.errorOnStaleApprovedFiles = errorOnStaleApprovedFiles;
|
|
120
|
+
if (verbose) {
|
|
121
|
+
console.log("approval opts: ", opts);
|
|
122
|
+
}
|
|
123
|
+
opts.forceApproveAll =
|
|
124
|
+
autils.hasCommandLineArgument("--forceapproveall") ||
|
|
125
|
+
autils.hasCommandLineArgument("-f");
|
|
126
|
+
process.stdin.pipe(event_stream_1.default.mapSync((data) => {
|
|
127
|
+
const dataToVerify = data.toString();
|
|
128
|
+
(0, Approvals_1.configure)(opts);
|
|
129
|
+
(0, Approvals_1.verify)(outdir, testname, dataToVerify);
|
|
130
|
+
}));
|
|
131
|
+
});
|
|
74
132
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
boolean: ["verbose"],
|
|
133
|
+
void main().catch((error) => {
|
|
134
|
+
console.error(error);
|
|
135
|
+
process.exitCode = 1;
|
|
80
136
|
});
|
|
81
|
-
if (verbose) {
|
|
82
|
-
console.log("parsed args: ", argv);
|
|
83
|
-
}
|
|
84
|
-
let reporters = argv.reporter;
|
|
85
|
-
if (typeof reporters === "string") {
|
|
86
|
-
reporters = [reporters];
|
|
87
|
-
}
|
|
88
|
-
const testname = argv._[0];
|
|
89
|
-
if (!testname) {
|
|
90
|
-
errAndExit('Missing parameter: supply a test name ex: echo "hello" | approvals myFirstTest. This will become the file name myFirstTest.approved.txt in the current directory');
|
|
91
|
-
}
|
|
92
|
-
const outdir = argv.outdir || process.cwd();
|
|
93
|
-
if (!fs_1.default.existsSync(outdir)) {
|
|
94
|
-
errAndExit("Directory not found: " + outdir);
|
|
95
|
-
}
|
|
96
|
-
const errorOnStaleApprovedFiles = argv.errorOnStaleApprovedFiles === "true";
|
|
97
|
-
if (verbose) {
|
|
98
|
-
console.log("outdir: ", outdir);
|
|
99
|
-
console.log("errorOnStaleApprovedFiles: ", errorOnStaleApprovedFiles);
|
|
100
|
-
console.log("testname: ", testname);
|
|
101
|
-
console.log("reporters: ", reporters ||
|
|
102
|
-
"undefined (but will fallback to approvals preconfigure defaults)");
|
|
103
|
-
}
|
|
104
|
-
const opts = {};
|
|
105
|
-
if (reporters) {
|
|
106
|
-
opts.reporters = reporters;
|
|
107
|
-
}
|
|
108
|
-
opts.errorOnStaleApprovedFiles = errorOnStaleApprovedFiles;
|
|
109
|
-
if (verbose) {
|
|
110
|
-
console.log("approval opts: ", opts);
|
|
111
|
-
}
|
|
112
|
-
opts.forceApproveAll =
|
|
113
|
-
autils.hasCommandLineArgument("--forceapproveall") ||
|
|
114
|
-
autils.hasCommandLineArgument("-f");
|
|
115
|
-
process.stdin.pipe(event_stream_1.default.mapSync((data) => {
|
|
116
|
-
const dataToVerify = data.toString();
|
|
117
|
-
(0, Approvals_1.configure)(opts);
|
|
118
|
-
(0, Approvals_1.verify)(outdir, testname, dataToVerify);
|
|
119
|
-
}));
|
package/bin/index.ts
CHANGED
|
@@ -3,8 +3,8 @@ import es from "event-stream";
|
|
|
3
3
|
import * as autils from "../lib/AUtils";
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import path from "path";
|
|
6
|
-
import marked from "marked";
|
|
7
|
-
import
|
|
6
|
+
import { marked } from "marked";
|
|
7
|
+
import { createTerminalRenderer, darkTheme } from "marked-terminal-renderer";
|
|
8
8
|
import minimist from "minimist";
|
|
9
9
|
import { configure, verify } from "../lib/Approvals";
|
|
10
10
|
import { redText } from "../lib/Utilities/ConsoleUtils";
|
|
@@ -12,95 +12,97 @@ import { redText } from "../lib/Utilities/ConsoleUtils";
|
|
|
12
12
|
const verbose = process.argv.includes("--verbose");
|
|
13
13
|
const printHelp = process.argv.includes("--help");
|
|
14
14
|
|
|
15
|
-
function printHelpMessage() {
|
|
15
|
+
async function printHelpMessage(): Promise<void> {
|
|
16
16
|
if (verbose) {
|
|
17
17
|
console.log("printing help...");
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const helpFile = fs.readFileSync(path.join(__dirname, "help.md"), "utf8");
|
|
21
|
-
marked.
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
let output = marked.parse(helpFile) as string;
|
|
25
|
-
|
|
26
|
-
output = output.replace(/ /g, " ");
|
|
27
|
-
console.log(output);
|
|
21
|
+
marked.use(createTerminalRenderer(darkTheme()));
|
|
22
|
+
console.log(await marked.parse(helpFile));
|
|
28
23
|
}
|
|
29
24
|
|
|
30
|
-
function errAndExit(msg: string): void {
|
|
31
|
-
printHelpMessage();
|
|
25
|
+
async function errAndExit(msg: string): Promise<void> {
|
|
26
|
+
await printHelpMessage();
|
|
32
27
|
console.log(redText(msg));
|
|
33
28
|
process.exit(1);
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
async function main(): Promise<void> {
|
|
32
|
+
if (printHelp) {
|
|
33
|
+
await printHelpMessage();
|
|
34
|
+
process.exit();
|
|
35
|
+
}
|
|
40
36
|
|
|
41
|
-
if (verbose) {
|
|
42
|
-
|
|
43
|
-
}
|
|
37
|
+
if (verbose) {
|
|
38
|
+
console.log("process.argv: ", process.argv);
|
|
39
|
+
}
|
|
44
40
|
|
|
45
|
-
const argv = minimist(process.argv.slice(2), {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
41
|
+
const argv = minimist(process.argv.slice(2), {
|
|
42
|
+
alias: {
|
|
43
|
+
reporters: ["r"],
|
|
44
|
+
},
|
|
45
|
+
boolean: ["verbose"],
|
|
46
|
+
});
|
|
51
47
|
|
|
52
|
-
if (verbose) {
|
|
53
|
-
|
|
54
|
-
}
|
|
48
|
+
if (verbose) {
|
|
49
|
+
console.log("parsed args: ", argv);
|
|
50
|
+
}
|
|
55
51
|
|
|
56
|
-
let reporters = argv.reporter as string | string[];
|
|
57
|
-
if (typeof reporters === "string") {
|
|
58
|
-
|
|
59
|
-
}
|
|
52
|
+
let reporters = argv.reporter as string | string[];
|
|
53
|
+
if (typeof reporters === "string") {
|
|
54
|
+
reporters = [reporters];
|
|
55
|
+
}
|
|
60
56
|
|
|
61
|
-
const testname = argv._[0];
|
|
62
|
-
if (!testname) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
57
|
+
const testname = argv._[0];
|
|
58
|
+
if (!testname) {
|
|
59
|
+
await errAndExit(
|
|
60
|
+
'Missing parameter: supply a test name ex: echo "hello" | approvals myFirstTest. This will become the file name myFirstTest.approved.txt in the current directory',
|
|
61
|
+
);
|
|
62
|
+
}
|
|
67
63
|
|
|
68
|
-
const outdir = argv.outdir || process.cwd();
|
|
69
|
-
if (!fs.existsSync(outdir)) {
|
|
70
|
-
|
|
71
|
-
}
|
|
64
|
+
const outdir = argv.outdir || process.cwd();
|
|
65
|
+
if (!fs.existsSync(outdir)) {
|
|
66
|
+
await errAndExit("Directory not found: " + outdir);
|
|
67
|
+
}
|
|
72
68
|
|
|
73
|
-
const errorOnStaleApprovedFiles = argv.errorOnStaleApprovedFiles === "true";
|
|
69
|
+
const errorOnStaleApprovedFiles = argv.errorOnStaleApprovedFiles === "true";
|
|
74
70
|
|
|
75
|
-
if (verbose) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
71
|
+
if (verbose) {
|
|
72
|
+
console.log("outdir: ", outdir);
|
|
73
|
+
console.log("errorOnStaleApprovedFiles: ", errorOnStaleApprovedFiles);
|
|
74
|
+
console.log("testname: ", testname);
|
|
75
|
+
console.log(
|
|
76
|
+
"reporters: ",
|
|
77
|
+
reporters ||
|
|
78
|
+
"undefined (but will fallback to approvals preconfigure defaults)",
|
|
79
|
+
);
|
|
80
|
+
}
|
|
85
81
|
|
|
86
|
-
const opts: any = {};
|
|
87
|
-
if (reporters) {
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
opts.errorOnStaleApprovedFiles = errorOnStaleApprovedFiles;
|
|
82
|
+
const opts: any = {};
|
|
83
|
+
if (reporters) {
|
|
84
|
+
opts.reporters = reporters;
|
|
85
|
+
}
|
|
86
|
+
opts.errorOnStaleApprovedFiles = errorOnStaleApprovedFiles;
|
|
87
|
+
|
|
88
|
+
if (verbose) {
|
|
89
|
+
console.log("approval opts: ", opts);
|
|
90
|
+
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
opts.forceApproveAll =
|
|
93
|
+
autils.hasCommandLineArgument("--forceapproveall") ||
|
|
94
|
+
autils.hasCommandLineArgument("-f");
|
|
95
|
+
|
|
96
|
+
process.stdin.pipe(
|
|
97
|
+
es.mapSync((data: Buffer) => {
|
|
98
|
+
const dataToVerify = data.toString();
|
|
99
|
+
configure(opts);
|
|
100
|
+
verify(outdir, testname, dataToVerify);
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
94
103
|
}
|
|
95
104
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
process.stdin.pipe(
|
|
101
|
-
es.mapSync((data: Buffer) => {
|
|
102
|
-
const dataToVerify = data.toString();
|
|
103
|
-
configure(opts);
|
|
104
|
-
verify(outdir, testname, dataToVerify);
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
105
|
+
void main().catch((error: unknown) => {
|
|
106
|
+
console.error(error);
|
|
107
|
+
process.exitCode = 1;
|
|
108
|
+
});
|
package/lib/Approvals.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ export declare function verifyAsJSONAndScrub(dirName: string, testName: string,
|
|
|
94
94
|
/**
|
|
95
95
|
* This allows you to take full control of naming and writing files before verifying.
|
|
96
96
|
*
|
|
97
|
-
* For an example that we use to generate the docs within the readme, check out the [test/readmeTests.mts](test/readmeTests.mts) in this project.
|
|
97
|
+
* For an example that we use to generate the docs within the readme, check out the [test/mocha/readmeTests.mts](test/mocha/readmeTests.mts) in this project.
|
|
98
98
|
*
|
|
99
99
|
* @param {Object} namer
|
|
100
100
|
* @param {Object} writer
|
package/lib/Approvals.js
CHANGED
|
@@ -67,6 +67,7 @@ const AUtils_1 = require("./AUtils");
|
|
|
67
67
|
// they won't get a helpful error. So we put this in there - just in case"
|
|
68
68
|
const MochaNamer_1 = require("./Providers/Mocha/MochaNamer");
|
|
69
69
|
const BeforeEachVerifierBase_1 = require("./Providers/BeforeEachVerifierBase");
|
|
70
|
+
const OptionalFramework_1 = require("./Providers/OptionalFramework");
|
|
70
71
|
if (typeof beforeEach === "function") {
|
|
71
72
|
beforeEach(function () {
|
|
72
73
|
if (!this) {
|
|
@@ -125,6 +126,8 @@ function getConfig(overrideOptions) {
|
|
|
125
126
|
* @param {*} optionalBaseDir - An optional folder to save approval files to.
|
|
126
127
|
*/
|
|
127
128
|
function mocha(optionalBaseDir) {
|
|
129
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
|
|
130
|
+
return module.exports;
|
|
128
131
|
// if not providing a base dir, fallback to the current calling code's directory
|
|
129
132
|
if (!optionalBaseDir) {
|
|
130
133
|
let fileName = (0, callsite_1.default)()[1].getFileName();
|
|
@@ -263,7 +266,7 @@ function verifyAsJSONAndScrub(dirName, testName, data, scrubber, optionsOverride
|
|
|
263
266
|
/**
|
|
264
267
|
* This allows you to take full control of naming and writing files before verifying.
|
|
265
268
|
*
|
|
266
|
-
* For an example that we use to generate the docs within the readme, check out the [test/readmeTests.mts](test/readmeTests.mts) in this project.
|
|
269
|
+
* For an example that we use to generate the docs within the readme, check out the [test/mocha/readmeTests.mts](test/mocha/readmeTests.mts) in this project.
|
|
267
270
|
*
|
|
268
271
|
* @param {Object} namer
|
|
269
272
|
* @param {Object} writer
|
package/lib/Approvals.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { stringifyKeysInOrder } from "./AUtils";
|
|
|
26
26
|
import { MochaNamer } from "./Providers/Mocha/MochaNamer";
|
|
27
27
|
|
|
28
28
|
import { beforeEachVerifierBase } from "./Providers/BeforeEachVerifierBase";
|
|
29
|
+
import { isFrameworkAvailable } from "./Providers/OptionalFramework";
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* Contains some helpful and util scrubbers that can be used for scrubbing data before saving to a received file.
|
|
@@ -96,6 +97,7 @@ export function getConfig(overrideOptions?: cfg.Config): cfg.Config {
|
|
|
96
97
|
*/
|
|
97
98
|
|
|
98
99
|
export function mocha(optionalBaseDir?: string): typeof module.exports {
|
|
100
|
+
if (!isFrameworkAvailable("mocha")) return module.exports;
|
|
99
101
|
// if not providing a base dir, fallback to the current calling code's directory
|
|
100
102
|
if (!optionalBaseDir) {
|
|
101
103
|
let fileName = callsite()[1].getFileName();
|
|
@@ -293,7 +295,7 @@ export function verifyAsJSONAndScrub(
|
|
|
293
295
|
/**
|
|
294
296
|
* This allows you to take full control of naming and writing files before verifying.
|
|
295
297
|
*
|
|
296
|
-
* For an example that we use to generate the docs within the readme, check out the [test/readmeTests.mts](test/readmeTests.mts) in this project.
|
|
298
|
+
* For an example that we use to generate the docs within the readme, check out the [test/mocha/readmeTests.mts](test/mocha/readmeTests.mts) in this project.
|
|
297
299
|
*
|
|
298
300
|
* @param {Object} namer
|
|
299
301
|
* @param {Object} writer
|
|
@@ -52,7 +52,10 @@ const Options_1 = require("../../Core/Options");
|
|
|
52
52
|
const JestNamer_1 = require("./JestNamer");
|
|
53
53
|
const StringWriter_1 = require("../../StringWriter");
|
|
54
54
|
const approvals = __importStar(require("../../Approvals"));
|
|
55
|
+
const OptionalFramework_1 = require("../OptionalFramework");
|
|
55
56
|
function verify(sut, options) {
|
|
57
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("jest"))
|
|
58
|
+
return;
|
|
56
59
|
options = options || new Options_1.Options();
|
|
57
60
|
options = options.withNamer((0, JestNamer_1.getJestNamer)());
|
|
58
61
|
const config = options.getConfig(approvals.getConfig());
|
|
@@ -15,8 +15,10 @@ import { getJestNamer } from "./JestNamer";
|
|
|
15
15
|
|
|
16
16
|
import { StringWriter } from "../../StringWriter";
|
|
17
17
|
import * as approvals from "../../Approvals";
|
|
18
|
+
import { isFrameworkAvailable } from "../OptionalFramework";
|
|
18
19
|
|
|
19
20
|
export function verify(sut: any, options?: Options): void {
|
|
21
|
+
if (!isFrameworkAvailable("jest")) return;
|
|
20
22
|
options = options || new Options();
|
|
21
23
|
options = options.withNamer(getJestNamer());
|
|
22
24
|
const config = options.getConfig(approvals.getConfig());
|
|
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getJestNamer = getJestNamer;
|
|
7
|
-
const globals_1 = require("@jest/globals");
|
|
8
7
|
const path_1 = __importDefault(require("path"));
|
|
9
8
|
const Namer_1 = require("../../Namer");
|
|
10
9
|
const Namer_2 = require("../../Core/Namer");
|
|
11
10
|
function getJestNamer() {
|
|
12
|
-
const
|
|
11
|
+
const { expect } = require("@jest/globals");
|
|
12
|
+
const state = expect.getState();
|
|
13
13
|
const file = path_1.default.parse(state.testPath);
|
|
14
14
|
const testPath = file.dir;
|
|
15
15
|
const testFileName = file.name;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { expect } from "@jest/globals";
|
|
2
1
|
import path from "path";
|
|
3
2
|
import { Namer } from "../../Namer";
|
|
4
3
|
import { convertToFilename } from "../../Core/Namer";
|
|
5
4
|
|
|
6
5
|
export function getJestNamer(): Namer {
|
|
6
|
+
const { expect } = require("@jest/globals") as typeof import("@jest/globals");
|
|
7
7
|
const state = expect.getState();
|
|
8
8
|
const file = path.parse(state.testPath as string);
|
|
9
9
|
const testPath = file.dir;
|
|
@@ -4,19 +4,22 @@ 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
|
|
7
|
+
const OptionalFramework_1 = require("../OptionalFramework");
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
class JestReporter {
|
|
10
10
|
constructor() {
|
|
11
11
|
this.name = "JestReporter";
|
|
12
12
|
}
|
|
13
13
|
canReportOn(_fileName) {
|
|
14
|
-
return
|
|
14
|
+
return (0, OptionalFramework_1.isFrameworkAvailable)("jest");
|
|
15
15
|
}
|
|
16
16
|
report(approvedFilePath, receivedFilePath, _) {
|
|
17
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("jest"))
|
|
18
|
+
return;
|
|
19
|
+
const { expect } = require("@jest/globals");
|
|
17
20
|
const approvedText = fs_1.default.readFileSync(approvedFilePath).toString();
|
|
18
21
|
const receivedText = fs_1.default.readFileSync(receivedFilePath).toString();
|
|
19
|
-
|
|
22
|
+
expect(receivedText).toBe(approvedText);
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
exports.JestReporter = JestReporter;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isFrameworkAvailable } from "../OptionalFramework";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import { Config } from "../../config";
|
|
4
4
|
import { Reporter } from "../../Core/Reporter";
|
|
@@ -7,7 +7,7 @@ export class JestReporter implements Reporter {
|
|
|
7
7
|
name: string = "JestReporter";
|
|
8
8
|
|
|
9
9
|
canReportOn(_fileName: string) {
|
|
10
|
-
return
|
|
10
|
+
return isFrameworkAvailable("jest");
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
report(
|
|
@@ -15,6 +15,9 @@ export class JestReporter implements Reporter {
|
|
|
15
15
|
receivedFilePath: string,
|
|
16
16
|
_: Partial<Config>,
|
|
17
17
|
) {
|
|
18
|
+
if (!isFrameworkAvailable("jest")) return;
|
|
19
|
+
const { expect } =
|
|
20
|
+
require("@jest/globals") as typeof import("@jest/globals");
|
|
18
21
|
const approvedText = fs.readFileSync(approvedFilePath).toString();
|
|
19
22
|
const receivedText = fs.readFileSync(receivedFilePath).toString();
|
|
20
23
|
expect(receivedText).toBe(approvedText);
|
|
@@ -56,12 +56,15 @@ const Printers_1 = require("../../Utilities/Printers");
|
|
|
56
56
|
*/
|
|
57
57
|
const Options_1 = require("../../Core/Options");
|
|
58
58
|
const MochaNamer_1 = require("./MochaNamer");
|
|
59
|
-
const
|
|
59
|
+
const OptionalFramework_1 = require("../OptionalFramework");
|
|
60
60
|
const StringWriter_1 = __importDefault(require("../../StringWriter"));
|
|
61
61
|
const approvals = __importStar(require("../../Approvals"));
|
|
62
62
|
let mochaTest = null;
|
|
63
63
|
function it2(label, test) {
|
|
64
|
-
|
|
64
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
|
|
65
|
+
return;
|
|
66
|
+
const mocha = require("mocha");
|
|
67
|
+
mocha.it(label, function () {
|
|
65
68
|
mochaTest = this;
|
|
66
69
|
console.log("Mocha Test: ", mochaTest.test.name);
|
|
67
70
|
test();
|
|
@@ -69,12 +72,16 @@ function it2(label, test) {
|
|
|
69
72
|
}
|
|
70
73
|
let namer;
|
|
71
74
|
function setNamer(that) {
|
|
75
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
|
|
76
|
+
return;
|
|
72
77
|
namer = (0, MochaNamer_1.getMochaNamer)(that.currentTest);
|
|
73
78
|
}
|
|
74
79
|
function getNamer() {
|
|
75
80
|
return namer;
|
|
76
81
|
}
|
|
77
82
|
function verify(sut, options) {
|
|
83
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("mocha"))
|
|
84
|
+
return;
|
|
78
85
|
options = options || new Options_1.Options();
|
|
79
86
|
options = options.withNamer(getNamer());
|
|
80
87
|
const config = options.getConfig(approvals.getConfig());
|
|
@@ -12,7 +12,7 @@ import { printArray, printJson } from "../../Utilities/Printers";
|
|
|
12
12
|
*/
|
|
13
13
|
import { Options } from "../../Core/Options";
|
|
14
14
|
import { getMochaNamer } from "./MochaNamer";
|
|
15
|
-
import
|
|
15
|
+
import { isFrameworkAvailable } from "../OptionalFramework";
|
|
16
16
|
|
|
17
17
|
import StringWriter from "../../StringWriter";
|
|
18
18
|
|
|
@@ -22,6 +22,8 @@ import { Namer } from "../../Core/Namer";
|
|
|
22
22
|
let mochaTest: any = null;
|
|
23
23
|
|
|
24
24
|
export function it2(label: string, test: () => void): void {
|
|
25
|
+
if (!isFrameworkAvailable("mocha")) return;
|
|
26
|
+
const mocha = require("mocha") as typeof import("mocha");
|
|
25
27
|
mocha.it(label, function (this: any) {
|
|
26
28
|
mochaTest = this;
|
|
27
29
|
console.log("Mocha Test: ", mochaTest.test.name);
|
|
@@ -32,6 +34,7 @@ export function it2(label: string, test: () => void): void {
|
|
|
32
34
|
let namer: Namer;
|
|
33
35
|
|
|
34
36
|
export function setNamer(that: any): void {
|
|
37
|
+
if (!isFrameworkAvailable("mocha")) return;
|
|
35
38
|
namer = getMochaNamer(that.currentTest);
|
|
36
39
|
}
|
|
37
40
|
|
|
@@ -40,6 +43,7 @@ export function getNamer(): Namer {
|
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
export function verify(sut: any, options?: Options): void {
|
|
46
|
+
if (!isFrameworkAvailable("mocha")) return;
|
|
43
47
|
options = options || new Options();
|
|
44
48
|
options = options.withNamer(getNamer());
|
|
45
49
|
const config = options.getConfig(approvals.getConfig());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isFrameworkAvailable(framework: string): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFrameworkAvailable = isFrameworkAvailable;
|
|
4
|
+
function isFrameworkAvailable(framework) {
|
|
5
|
+
try {
|
|
6
|
+
require.resolve(framework);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (error.code !== "MODULE_NOT_FOUND") {
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -41,7 +41,10 @@ const Options_1 = require("../../Core/Options");
|
|
|
41
41
|
const VitestNamer_1 = require("./VitestNamer");
|
|
42
42
|
const StringWriter_1 = require("../../StringWriter");
|
|
43
43
|
const approvals = __importStar(require("../../Approvals"));
|
|
44
|
+
const OptionalFramework_1 = require("../OptionalFramework");
|
|
44
45
|
function verify(sut, options) {
|
|
46
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("vitest"))
|
|
47
|
+
return;
|
|
45
48
|
options = options || new Options_1.Options();
|
|
46
49
|
options = options.withNamer((0, VitestNamer_1.getVitestNamer)());
|
|
47
50
|
const config = options.getConfig(approvals.getConfig());
|
|
@@ -4,8 +4,10 @@ import { getVitestNamer } from "./VitestNamer";
|
|
|
4
4
|
|
|
5
5
|
import { StringWriter } from "../../StringWriter";
|
|
6
6
|
import * as approvals from "../../Approvals";
|
|
7
|
+
import { isFrameworkAvailable } from "../OptionalFramework";
|
|
7
8
|
|
|
8
9
|
export function verify(sut: any, options?: Options): void {
|
|
10
|
+
if (!isFrameworkAvailable("vitest")) return;
|
|
9
11
|
options = options || new Options();
|
|
10
12
|
options = options.withNamer(getVitestNamer());
|
|
11
13
|
const config = options.getConfig(approvals.getConfig());
|
|
@@ -5,14 +5,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.VitestReporter = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const OptionalFramework_1 = require("../OptionalFramework");
|
|
8
9
|
class VitestReporter {
|
|
9
10
|
constructor() {
|
|
10
11
|
this.name = "VitestReporter";
|
|
11
12
|
}
|
|
12
13
|
canReportOn(_fileName) {
|
|
13
|
-
return
|
|
14
|
+
return (0, OptionalFramework_1.isFrameworkAvailable)("vitest");
|
|
14
15
|
}
|
|
15
16
|
report(approvedFilePath, receivedFilePath, _) {
|
|
17
|
+
if (!(0, OptionalFramework_1.isFrameworkAvailable)("vitest"))
|
|
18
|
+
return;
|
|
16
19
|
const approvedText = fs_1.default.readFileSync(approvedFilePath).toString();
|
|
17
20
|
const receivedText = fs_1.default.readFileSync(receivedFilePath).toString();
|
|
18
21
|
expect(receivedText).toBe(approvedText);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import { Config } from "../../config";
|
|
3
3
|
import { Reporter } from "../../Core/Reporter";
|
|
4
|
+
import { isFrameworkAvailable } from "../OptionalFramework";
|
|
4
5
|
|
|
5
6
|
declare const expect: (actual: unknown) => { toBe(expected: unknown): void };
|
|
6
7
|
|
|
@@ -8,7 +9,7 @@ export class VitestReporter implements Reporter {
|
|
|
8
9
|
name: string = "VitestReporter";
|
|
9
10
|
|
|
10
11
|
canReportOn(_fileName: string) {
|
|
11
|
-
return
|
|
12
|
+
return isFrameworkAvailable("vitest");
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
report(
|
|
@@ -16,6 +17,7 @@ export class VitestReporter implements Reporter {
|
|
|
16
17
|
receivedFilePath: string,
|
|
17
18
|
_: Partial<Config>,
|
|
18
19
|
) {
|
|
20
|
+
if (!isFrameworkAvailable("vitest")) return;
|
|
19
21
|
const approvedText = fs.readFileSync(approvedFilePath).toString();
|
|
20
22
|
const receivedText = fs.readFileSync(receivedFilePath).toString();
|
|
21
23
|
expect(receivedText).toBe(approvedText);
|
|
@@ -39,7 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.BinaryWriter = void 0;
|
|
40
40
|
const fs = __importStar(require("fs"));
|
|
41
41
|
const path = __importStar(require("path"));
|
|
42
|
-
const mkdirp_1 =
|
|
42
|
+
const mkdirp_1 = require("mkdirp");
|
|
43
43
|
const file_type_1 = __importDefault(require("file-type")); // Assuming fileType provides synchronous methods
|
|
44
44
|
class BinaryWriter {
|
|
45
45
|
constructor(outputData) {
|
|
@@ -55,7 +55,7 @@ class BinaryWriter {
|
|
|
55
55
|
write(filePath) {
|
|
56
56
|
const dir = path.dirname(path.normalize(filePath));
|
|
57
57
|
if (!fs.existsSync(dir)) {
|
|
58
|
-
mkdirp_1.
|
|
58
|
+
(0, mkdirp_1.sync)(dir);
|
|
59
59
|
}
|
|
60
60
|
fs.writeFileSync(filePath, this.outputData);
|
|
61
61
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
|
-
import
|
|
3
|
+
import { sync } from "mkdirp";
|
|
4
4
|
import fileType from "file-type"; // Assuming fileType provides synchronous methods
|
|
5
5
|
import { Writer } from "../Core/Writer";
|
|
6
6
|
|
|
@@ -23,7 +23,7 @@ export class BinaryWriter implements Writer {
|
|
|
23
23
|
write(filePath: string): void {
|
|
24
24
|
const dir = path.dirname(path.normalize(filePath));
|
|
25
25
|
if (!fs.existsSync(dir)) {
|
|
26
|
-
|
|
26
|
+
sync(dir);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
fs.writeFileSync(filePath, this.outputData);
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"description": "Approval Tests Library - Capturing Human Intelligence",
|
|
7
|
-
"version": "7.5.
|
|
7
|
+
"version": "7.5.10",
|
|
8
8
|
"homepage": "http://approvaltests.com",
|
|
9
9
|
"author": {
|
|
10
10
|
"name": "Jason Jarrett",
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc",
|
|
42
|
-
"test": "
|
|
43
|
-
"vitest": "vitest
|
|
42
|
+
"test": "node scripts/test.cjs",
|
|
43
|
+
"vitest": "node scripts/test-isolated.cjs vitest",
|
|
44
44
|
"test2": "npm run mocha && npm run lint",
|
|
45
|
-
"lint": "eslint
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
45
|
+
"lint": "eslint lib test",
|
|
46
|
+
"mocha": "node scripts/test-isolated.cjs mocha",
|
|
47
|
+
"coverage": "node scripts/test-isolated.cjs mocha --coverage",
|
|
48
|
+
"jest": "node scripts/test-isolated.cjs jest"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"ansi-colors": "^4.1.3",
|
|
@@ -55,16 +55,14 @@
|
|
|
55
55
|
"event-stream": "^4.0.1",
|
|
56
56
|
"file-type": "^12.4.2",
|
|
57
57
|
"glob": "^13.0.0",
|
|
58
|
-
"jest": "^30.0.0",
|
|
59
58
|
"js-yaml": "^5.1.0",
|
|
60
59
|
"lodash": "^4.17.21",
|
|
61
|
-
"marked": "^
|
|
62
|
-
"marked-terminal": "^
|
|
60
|
+
"marked": "^18.0.14",
|
|
61
|
+
"marked-terminal-renderer": "^2.2.0",
|
|
63
62
|
"minimist": "^1.2.8",
|
|
64
63
|
"mkdirp": "^3.0.1",
|
|
65
64
|
"shelljs": "^0.10.0",
|
|
66
|
-
"temp": "^0.9.4"
|
|
67
|
-
"ts-jest": "^29.0.3"
|
|
65
|
+
"temp": "^0.9.4"
|
|
68
66
|
},
|
|
69
67
|
"devDependencies": {
|
|
70
68
|
"@types/chai": "^5.0.1",
|
|
@@ -75,25 +73,13 @@
|
|
|
75
73
|
"chai": "^6.0.1",
|
|
76
74
|
"eslint": "^10.2.1",
|
|
77
75
|
"eslint-plugin-promise": "^7.2.1",
|
|
78
|
-
"gulp": "^5.0.0",
|
|
79
|
-
"gulp-eslint": "^6.0.0",
|
|
80
|
-
"gulp-istanbul": "^1.1.3",
|
|
81
|
-
"gulp-load-plugins": "^2.0.7",
|
|
82
|
-
"gulp-mocha": "^10.0.1",
|
|
83
|
-
"gulp-watch": "^5.0.1",
|
|
84
|
-
"jest-junit": "^17.0.0",
|
|
85
76
|
"jsdoc-to-markdown": "^9.1.1",
|
|
86
|
-
"mocha": "^11.0.1",
|
|
87
|
-
"mocha-junit-reporter": "^2.2.1",
|
|
88
|
-
"mocha-multi-reporters": "^1.5.1",
|
|
89
|
-
"np": "^12.0.0",
|
|
90
77
|
"nyc": "^18.0.0",
|
|
91
78
|
"pre-commit": "^2.0.0",
|
|
92
79
|
"prettier": "^3.4.2",
|
|
93
80
|
"sinon": "^22.0.0",
|
|
94
81
|
"ts-node": "^10.9.1",
|
|
95
|
-
"typescript": "^6.0.2"
|
|
96
|
-
"vitest": "^5.0.1"
|
|
82
|
+
"typescript": "^6.0.2"
|
|
97
83
|
},
|
|
98
84
|
"keywords": [
|
|
99
85
|
"Approve",
|
|
@@ -105,5 +91,26 @@
|
|
|
105
91
|
"Testing",
|
|
106
92
|
"Verification",
|
|
107
93
|
"Verify"
|
|
94
|
+
],
|
|
95
|
+
"peerDependencies": {
|
|
96
|
+
"jest": "^30.0.0",
|
|
97
|
+
"mocha": "^12.0.2",
|
|
98
|
+
"vitest": "^5.0.1"
|
|
99
|
+
},
|
|
100
|
+
"peerDependenciesMeta": {
|
|
101
|
+
"jest": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"mocha": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
"vitest": {
|
|
108
|
+
"optional": true
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"workspaces": [
|
|
112
|
+
"test/mocha",
|
|
113
|
+
"test/jest",
|
|
114
|
+
"test/vitest"
|
|
108
115
|
]
|
|
109
116
|
}
|
package/readme.md
CHANGED
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
* [CLI](#cli)
|
|
14
14
|
* [Install Approvals CLI](#install-approvals-cli)
|
|
15
15
|
* [CLI Help](#cli-help)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
* [Usage](#usage)
|
|
17
|
+
* [Examples](#examples)
|
|
18
|
+
* [Simple hello world](#simple-hello-world)
|
|
19
|
+
* [Specify diff reporter (great for C.I.)](#specify-diff-reporter-great-for-ci)
|
|
20
|
+
* [Multiple diff reporters](#multiple-diff-reporters)
|
|
19
21
|
* [Reporters](#reporters)
|
|
20
22
|
* [Built-In Reporters](#built-in-reporters)
|
|
21
23
|
* [Supported Diff Tools](#supported-diff-tools)
|
|
@@ -67,6 +69,10 @@ What is an approval test? Check out a brief [overview here](http://staxmanade.co
|
|
|
67
69
|
|
|
68
70
|
## Getting Started
|
|
69
71
|
|
|
72
|
+
Mocha, Jest, and Vitest are optional peer dependencies. Install the framework
|
|
73
|
+
your tests use alongside Approvals. Approvals silently skips integrations for
|
|
74
|
+
frameworks that are not installed.
|
|
75
|
+
|
|
70
76
|
### Jest Typescript Starter Project
|
|
71
77
|
|
|
72
78
|
If you want to jump start a new project, clone the [Jest Starter Project](https://github.com/approvals/ApprovalTests.TypeScript.Jest.StarterProject)
|
|
@@ -88,10 +94,10 @@ Below is a simple getting started using Mocha.
|
|
|
88
94
|
npm install --save-dev @approval-tests/approvals
|
|
89
95
|
```
|
|
90
96
|
|
|
91
|
-
1. Install [Mocha](http://mochajs.org/)
|
|
97
|
+
1. Install [Mocha](http://mochajs.org/) in the project to execute our tests
|
|
92
98
|
|
|
93
99
|
```shell
|
|
94
|
-
npm install -
|
|
100
|
+
npm install --save-dev mocha
|
|
95
101
|
```
|
|
96
102
|
|
|
97
103
|
1. Create a sample Mocha test file called `SimpleLogger.test.js`.
|
|
@@ -110,7 +116,7 @@ Below is a simple getting started using Mocha.
|
|
|
110
116
|
1. Test the file with mocha.
|
|
111
117
|
|
|
112
118
|
```shell
|
|
113
|
-
mocha SimpleLogger.test.js
|
|
119
|
+
npx mocha SimpleLogger.test.js
|
|
114
120
|
```
|
|
115
121
|
|
|
116
122
|
1. You should be presented with a diff tool. (if not, you may need to install one?)
|
|
@@ -140,44 +146,41 @@ npm install -g @approval-tests/approvals
|
|
|
140
146
|
By running `approvals --help`
|
|
141
147
|
|
|
142
148
|
<!--BEGIN-CLI-DOCS-->
|
|
143
|
-
<!-- GENERATED - DO NOT MODIFY
|
|
149
|
+
<!-- GENERATED - DO NOT MODIFY CLI DOCS IN THIS README -->
|
|
144
150
|
<!-- Update docs in the source ./bin/help.md -->
|
|
145
|
-
```
|
|
146
151
|
|
|
147
|
-
|
|
152
|
+
#### Usage
|
|
148
153
|
|
|
149
154
|
`approvals testName [options]`
|
|
150
155
|
|
|
151
|
-
| Arg
|
|
152
|
-
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
153
|
-
|
|
|
154
|
-
| [--reporter difftool]
|
|
155
|
-
| [--outdir]
|
|
156
|
-
| [--verbose]
|
|
157
|
-
| TODO:
|
|
156
|
+
| Arg | Description |
|
|
157
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
158
|
+
| [-f \| --forceapproveall] | Skip the approve step and apply the results to the .approved.txt file (good for a first time run) |
|
|
159
|
+
| [--reporter difftool] | supports multiple EX: `--reporter opendiff --reporter gitdiff` |
|
|
160
|
+
| [--outdir] | dir to place approval file - defaults to current directory |
|
|
161
|
+
| [--verbose] | extra debug info |
|
|
162
|
+
| TODO: | We need to extend the supported args to include other approval options. (file an [issue](https://github.com/approvals/Approvals.NodeJS/issues) if you need one that's not here) |
|
|
158
163
|
|
|
159
|
-
|
|
164
|
+
#### Examples
|
|
160
165
|
|
|
161
|
-
|
|
166
|
+
##### Simple hello world
|
|
162
167
|
|
|
163
168
|
```
|
|
164
169
|
echo 'Hello World!' | approvals helloWorldTest
|
|
165
170
|
```
|
|
166
171
|
|
|
167
|
-
|
|
172
|
+
##### Specify diff reporter (great for C.I.)
|
|
168
173
|
|
|
169
174
|
```
|
|
170
175
|
echo 'Hello World!' | approvals helloWorldTest --reporter gitdiff
|
|
171
176
|
```
|
|
172
177
|
|
|
173
|
-
|
|
178
|
+
##### Multiple diff reporters
|
|
174
179
|
|
|
175
180
|
```
|
|
176
181
|
echo 'Hello World!' | approvals helloWorldTest --reporter gitdiff --reporter p4merge
|
|
177
182
|
```
|
|
178
183
|
|
|
179
|
-
```
|
|
180
|
-
|
|
181
184
|
<!--END-CLI-DOCS-->
|
|
182
185
|
|
|
183
186
|
<a name="reporters" />
|
|
@@ -508,7 +511,7 @@ approvals.verifyAndScrub(__dirname, 'sample-approval-test', { a: "some text in a
|
|
|
508
511
|
### approvals~verifyWithControl(namer, writer, [reporterFactory], [optionsOverride])
|
|
509
512
|
This allows you to take full control of naming and writing files before verifying.
|
|
510
513
|
|
|
511
|
-
For an example that we use to generate the docs within the readme, check out the [test/readmeTests.mts](test/readmeTests.mts) in this project.
|
|
514
|
+
For an example that we use to generate the docs within the readme, check out the [test/mocha/readmeTests.mts](test/mocha/readmeTests.mts) in this project.
|
|
512
515
|
|
|
513
516
|
**Kind**: inner method of [<code>approvals</code>](#module_approvals)
|
|
514
517
|
|