@renderorange/jest-prove-reporter 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -0
  3. package/index.js +123 -0
  4. package/package.json +48 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Blaine Motsinger
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @renderorange/jest-prove-reporter
2
+
3
+ A Jest reporter that produces output reminiscent of Perl's prove test harness — terse, scannable, and easy to diff.
4
+
5
+ ## Why?
6
+
7
+ Jest's default reporter is friendly but verbose. If prefer Perl's prove-style summaries this reporter shows you one line per test file with a clear pass/fail and runtime, then a final summary at the end.
8
+
9
+ ## Example Output
10
+
11
+ Compact mode (default):
12
+
13
+ ```
14
+ foo.test.js ............... ok 500 ms
15
+ bar.test.js ............... ok 1.5 s
16
+ fail.test.js .............. not ok 200 ms
17
+
18
+ Test Summary Report
19
+ -------------------
20
+ fail.test.js (Wstat: 1)
21
+ Files=3, Tests=4, 2.2 s
22
+ Result: FAIL
23
+ ```
24
+
25
+ Verbose mode delegates to jest-tap-reporter and emits full TAP output.
26
+
27
+ ## Installation
28
+
29
+ ```
30
+ npm install --save-dev @renderorange/jest-prove-reporter
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ Add the reporter to your Jest config:
36
+
37
+ ```
38
+ {
39
+ "jest": {
40
+ "reporters": ["@renderorange/jest-prove-reporter"]
41
+ }
42
+ }
43
+ ```
44
+
45
+ Or on the command line:
46
+
47
+ ```
48
+ jest --reporters=@renderorange/jest-prove-reporter
49
+ ```
50
+
51
+ ## Configuration
52
+
53
+ The reporter accepts a verbose option. Priority is: reporter option → Jest's globalConfig.verbose → VERBOSE environment variable.
54
+
55
+ ```
56
+ {
57
+ "jest": {
58
+ "reporters": [
59
+ ["@renderorange/jest-prove-reporter", { "verbose": true }]
60
+ ]
61
+ }
62
+ }
63
+ ```
64
+
65
+ License
66
+
67
+ MIT
package/index.js ADDED
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ const TapReporter = require("jest-tap-reporter");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+
7
+ const IGNORE_DIRS = new Set(["node_modules", ".git"]);
8
+
9
+ function find_test_files (dir) {
10
+ const files = [];
11
+ try {
12
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
13
+ for (const entry of entries) {
14
+ if (entry.isDirectory() && IGNORE_DIRS.has(entry.name)) continue;
15
+ const full = path.join(dir, entry.name);
16
+ if (entry.isDirectory()) {
17
+ files.push(...find_test_files(full));
18
+ } else if (entry.name.endsWith(".test.js")) {
19
+ files.push(entry.name);
20
+ }
21
+ }
22
+ } catch (_) {
23
+ // directory may not exist
24
+ }
25
+ return files;
26
+ }
27
+
28
+ class ProveReporter {
29
+ constructor (globalConfig, options) {
30
+ this._globalConfig = globalConfig;
31
+ this._options = options || {};
32
+ this._verbose = this._options.verbose !== undefined
33
+ ? this._options.verbose
34
+ : (globalConfig.verbose !== undefined
35
+ ? globalConfig.verbose
36
+ : !!process.env.VERBOSE);
37
+ this._results = [];
38
+ this._started = false;
39
+ this._totalTime = 0;
40
+
41
+ if (this._verbose) {
42
+ this._tap = new TapReporter(globalConfig, { logLevel: "ERROR" });
43
+ this._maxNameLength = 0;
44
+ } else {
45
+ this._maxNameLength = this._compute_max_name_length(globalConfig.roots || []);
46
+ }
47
+ }
48
+
49
+ _compute_max_name_length (roots) {
50
+ let max = 0;
51
+ for (const root of roots) {
52
+ for (const name of find_test_files(root)) {
53
+ if (name.length > max) max = name.length;
54
+ }
55
+ }
56
+ return max > 0 ? max : 30;
57
+ }
58
+
59
+ onRunStart (results, options) {
60
+ if (this._tap) {
61
+ this._tap.onRunStart(results, options || {});
62
+ }
63
+ }
64
+
65
+ onTestResult (test, testResult) {
66
+ if (!this._started) {
67
+ this._started = true;
68
+ }
69
+
70
+ if (this._tap) {
71
+ this._tap.onTestResult(test, testResult);
72
+ return;
73
+ }
74
+
75
+ const testPath = test.path;
76
+ const name = testPath.split("/")
77
+ .pop();
78
+ const passed = testResult.numFailingTests === 0;
79
+ const duration = testResult.perfStats ? testResult.perfStats.runtime : 0;
80
+
81
+ this._results.push({ name, passed, duration });
82
+ this._totalTime += duration;
83
+
84
+ const pad = this._maxNameLength + 2;
85
+ const dots = ".".repeat(Math.max(0, pad - name.length));
86
+ const status = passed ? "ok" : "not ok";
87
+ const time = this._formatTime(duration);
88
+ process.stdout.write(name + " " + dots + " " + status + " " + time + "\n");
89
+ }
90
+
91
+ _formatTime (ms) {
92
+ if (ms >= 1000) {
93
+ return (ms / 1000).toFixed(1) + " s";
94
+ }
95
+ return Math.round(ms) + " ms";
96
+ }
97
+
98
+ onRunComplete (contexts, results) {
99
+ if (this._tap) {
100
+ this._tap.onRunComplete(contexts, results);
101
+ return;
102
+ }
103
+
104
+ process.stdout.write("\n");
105
+
106
+ const failed = this._results.filter((r) => !r.passed);
107
+
108
+ if (failed.length > 0) {
109
+ process.stdout.write("Test Summary Report\n");
110
+ process.stdout.write("-------------------\n");
111
+ for (const r of failed) {
112
+ process.stdout.write(r.name + " (Wstat: 1)\n");
113
+ }
114
+ }
115
+
116
+ process.stdout.write(
117
+ "Files=" + this._results.length + ", Tests=" + results.numPassedTests + ", " + this._formatTime(this._totalTime) + "\n",
118
+ );
119
+ process.stdout.write("Result: " + (failed.length === 0 ? "PASS" : "FAIL") + "\n");
120
+ }
121
+ }
122
+
123
+ module.exports = ProveReporter;
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@renderorange/jest-prove-reporter",
3
+ "version": "1.0.1",
4
+ "description": "Jest reporter that produces output similar to Perl's prove harness",
5
+ "license": "MIT",
6
+ "author": "Blaine Motsinger <blaine@renderorange.com>",
7
+ "main": "index.js",
8
+ "files": [
9
+ "index.js",
10
+ "LICENSE",
11
+ "README.md"
12
+ ],
13
+ "keywords": [
14
+ "jest",
15
+ "reporter",
16
+ "tap",
17
+ "prove",
18
+ "perl"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/renderorange/jest-prove-reporter.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/renderorange/jest-prove-reporter/issues"
26
+ },
27
+ "homepage": "https://github.com/renderorange/jest-prove-reporter#readme",
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "test": "jest",
33
+ "test:watch": "jest --watch",
34
+ "test:coverage": "jest --coverage",
35
+ "lint": "node node_modules/eslint/bin/eslint.js . --fix",
36
+ "lint:check": "node node_modules/eslint/bin/eslint.js ."
37
+ },
38
+ "peerDependencies": {
39
+ "jest": ">=29.0.0",
40
+ "jest-tap-reporter": ">=1.9.0"
41
+ },
42
+ "devDependencies": {
43
+ "@stylistic/eslint-plugin": "^3.0.0",
44
+ "eslint": "^9.0.0",
45
+ "jest": "^29.7.0",
46
+ "jest-tap-reporter": "^1.9.0"
47
+ }
48
+ }