@testver/testver 0.2.0

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.
@@ -0,0 +1,165 @@
1
+ /**
2
+ * @testver/wdio-json-reporter
3
+ *
4
+ * A WebdriverIO reporter that writes results in the **Mocha JSON shape**
5
+ * Testver's mocha parser already understands (`.testver-results.json`):
6
+ *
7
+ * { stats, tests[], passes[], failures[], pending[] }
8
+ *
9
+ * Why this exists: when a test is launched via `npx wdio run` (the
10
+ * WebdriverIO test runner — not `npx mocha`), reporters are configured in
11
+ * the wdio config's `reporters` array, NOT via Mocha CLI flags. Testver's
12
+ * generated overlay (`wdio.testver.conf.*`) injects THIS reporter inline so
13
+ * structured per-test results land on disk regardless of command form.
14
+ *
15
+ * Loaded INLINE (`[ReporterClass, options]`) by the overlay — never as a
16
+ * path STRING (WDIO would mangle a Windows path into a `wdio-<path>-reporter`
17
+ * package name and fail under the ESM loader, exactly like services).
18
+ *
19
+ * CommonJS so it loads from both TS and JS projects. It extends the host
20
+ * project's own `@wdio/reporter` (resolved from the project, NOT from
21
+ * Testver's install — same trick the attach service uses for webdriverio).
22
+ */
23
+
24
+ 'use strict';
25
+
26
+ const fs = require('node:fs');
27
+ const path = require('node:path');
28
+ const Module = require('node:module');
29
+
30
+ /**
31
+ * Resolve `@wdio/reporter` from the USER's project (it's a transitive dep
32
+ * of `@wdio/cli`, so any project that can run `wdio` has it). Resolving
33
+ * from this vendored file's own location would miss it.
34
+ */
35
+ function loadBaseReporter() {
36
+ const bases = [];
37
+ if (process.env.TESTVER_PROJECT_DIR) bases.push(process.env.TESTVER_PROJECT_DIR);
38
+ bases.push(process.cwd());
39
+ for (const base of bases) {
40
+ try {
41
+ const req = Module.createRequire(path.join(base, '__testver_wdio_reporter__.cjs'));
42
+ const mod = req('@wdio/reporter');
43
+ return mod.default || mod;
44
+ } catch (_e) { /* try next base */ }
45
+ }
46
+ const mod = require('@wdio/reporter');
47
+ return mod.default || mod;
48
+ }
49
+
50
+ const WDIOReporter = loadBaseReporter();
51
+
52
+ function fileUrlToPath(f) {
53
+ if (typeof f !== 'string' || !f) return undefined;
54
+ if (f.startsWith('file://')) {
55
+ try { return require('node:url').fileURLToPath(f); }
56
+ catch { return f.replace(/^file:\/\//, ''); }
57
+ }
58
+ return f;
59
+ }
60
+
61
+ class TestverJsonReporter extends WDIOReporter {
62
+ constructor(options) {
63
+ // `stdout: false` — the user's `spec` reporter owns the terminal; we
64
+ // only write the JSON file.
65
+ super(Object.assign({ stdout: false }, options));
66
+ const opt = options || {};
67
+ this.outputFile =
68
+ opt.outputFile ||
69
+ process.env.TESTVER_WDIO_RESULTS ||
70
+ path.join(process.cwd(), '.testver-results.json');
71
+ this._collected = [];
72
+ this._suites = [];
73
+ }
74
+
75
+ onSuiteStart(suite) {
76
+ if (suite && suite.title) this._suites.push(suite.title);
77
+ }
78
+ onSuiteEnd() {
79
+ this._suites.pop();
80
+ }
81
+
82
+ onTestPass(test) { this._add(test, 'passed'); }
83
+ onTestFail(test) { this._add(test, 'failed'); }
84
+ onTestSkip(test) { this._add(test, 'skipped'); }
85
+
86
+ _add(test, state) {
87
+ const title = (test && test.title) || '(unnamed test)';
88
+ const fullTitle =
89
+ (test && test.fullTitle) ||
90
+ [...this._suites, title].join(' ').trim() ||
91
+ title;
92
+ const specFile =
93
+ (this.runnerStat && Array.isArray(this.runnerStat.specs) && this.runnerStat.specs[0]) ||
94
+ undefined;
95
+ const errObj =
96
+ (test && (test.error || (Array.isArray(test.errors) && test.errors[0]))) || null;
97
+ this._collected.push({
98
+ title,
99
+ fullTitle,
100
+ file: fileUrlToPath(specFile),
101
+ duration: (test && (test._duration || test.duration)) || 0,
102
+ state,
103
+ err: errObj ? { message: errObj.message, stack: errObj.stack } : undefined,
104
+ });
105
+ }
106
+
107
+ onRunnerEnd() {
108
+ try { this._flush(); } catch (_e) { /* best-effort — never break the run */ }
109
+ }
110
+
111
+ /**
112
+ * Merge this worker's results into the shared output file. WDIO runs each
113
+ * spec in its own worker, so multiple reporter instances may append —
114
+ * we read-merge-write (sequential mobile runs don't race; the runner
115
+ * clears the file before the run so the first writer starts fresh).
116
+ */
117
+ _flush() {
118
+ let prev = { stats: {}, tests: [], passes: [], failures: [], pending: [] };
119
+ try {
120
+ if (fs.existsSync(this.outputFile)) {
121
+ const raw = JSON.parse(fs.readFileSync(this.outputFile, 'utf-8'));
122
+ if (raw && Array.isArray(raw.tests)) prev = raw;
123
+ }
124
+ } catch { /* start fresh on unparseable prior file */ }
125
+
126
+ const tests = (prev.tests || []).slice();
127
+ const passes = (prev.passes || []).slice();
128
+ const failures = (prev.failures || []).slice();
129
+ const pending = (prev.pending || []).slice();
130
+
131
+ for (const t of this._collected) {
132
+ const entry = {
133
+ title: t.title,
134
+ fullTitle: t.fullTitle,
135
+ file: t.file,
136
+ duration: t.duration,
137
+ err: t.state === 'failed' && t.err ? t.err : {},
138
+ };
139
+ tests.push(entry);
140
+ if (t.state === 'passed') passes.push(entry);
141
+ else if (t.state === 'failed') failures.push(entry);
142
+ else pending.push(entry);
143
+ }
144
+
145
+ const prevDur = (prev.stats && prev.stats.duration) || 0;
146
+ const addDur = this._collected.reduce((s, t) => s + (t.duration || 0), 0);
147
+ const report = {
148
+ stats: {
149
+ tests: tests.length,
150
+ passes: passes.length,
151
+ failures: failures.length,
152
+ pending: pending.length,
153
+ duration: prevDur + addDur,
154
+ },
155
+ tests,
156
+ passes,
157
+ failures,
158
+ pending,
159
+ };
160
+ fs.writeFileSync(this.outputFile, JSON.stringify(report, null, 2), 'utf-8');
161
+ }
162
+ }
163
+
164
+ module.exports = TestverJsonReporter;
165
+ module.exports.default = TestverJsonReporter;
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@testver/wdio-json-reporter",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "main": "index.cjs",
6
+ "description": "WebdriverIO reporter that writes Mocha-JSON results for Testver result capture."
7
+ }
package/package.json ADDED
@@ -0,0 +1,113 @@
1
+ {
2
+ "name": "@testver/testver",
3
+ "version": "0.2.0",
4
+ "description": "AI-powered interactive CLI for test automation",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "bin": {
10
+ "testver": "./bin/testver.js"
11
+ },
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "bin/",
16
+ "dist/index.js",
17
+ "dist/index.d.ts",
18
+ "dist/wdio-attach-service/",
19
+ "dist/wdio-bootstrap/",
20
+ "dist/wdio-json-reporter/",
21
+ "dist/py-agent/",
22
+ "dist/java-agent/",
23
+ "dist/dotnet-agent/",
24
+ "src/ui/static/",
25
+ "deploy/",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "engines": {
30
+ "node": ">=20.0.0"
31
+ },
32
+ "scripts": {
33
+ "build": "tsup",
34
+ "build:ui": "cd ui-app && npx vite build",
35
+ "build:all": "pnpm run build:ui && tsup",
36
+ "dev": "tsup --watch",
37
+ "dev:ui": "cd ui-app && npx vite --port 3701",
38
+ "start": "node bin/testver.js",
39
+ "typecheck": "tsc --noEmit",
40
+ "test": "vitest",
41
+ "clean": "rimraf dist"
42
+ },
43
+ "keywords": [
44
+ "test-automation",
45
+ "ai",
46
+ "llm",
47
+ "playwright",
48
+ "selenium",
49
+ "cypress",
50
+ "cli",
51
+ "interactive",
52
+ "sdet"
53
+ ],
54
+ "license": "MIT",
55
+ "dependencies": {
56
+ "@anthropic-ai/sdk": "^0.80.0",
57
+ "@google/generative-ai": "^0.24.1",
58
+ "@modelcontextprotocol/sdk": "^1.27.1",
59
+ "@resvg/resvg-js": "^2.6.2",
60
+ "@types/archiver": "^7.0.0",
61
+ "archiver": "^7.0.1",
62
+ "better-sqlite3": "^12.8.0",
63
+ "chalk": "^5.6.2",
64
+ "chart.js": "^4.5.1",
65
+ "chokidar": "^5.0.0",
66
+ "cli-highlight": "^2.1.11",
67
+ "conf": "^15.1.0",
68
+ "csv-parse": "^6.2.1",
69
+ "debug": "^4.4.3",
70
+ "dotenv": "^17.3.1",
71
+ "express": "^4.21.2",
72
+ "form-data": "^4.0.5",
73
+ "glob": "^13.0.6",
74
+ "mammoth": "^1.12.0",
75
+ "marked": "^15.0.12",
76
+ "marked-terminal": "^7.3.0",
77
+ "multer": "^2.1.1",
78
+ "nodemailer": "^8.0.4",
79
+ "open": "^11.0.0",
80
+ "openai": "^6.32.0",
81
+ "ora": "^9.3.0",
82
+ "pdf-parse": "^2.4.5",
83
+ "pdfkit": "^0.18.0",
84
+ "playwright-core": "^1.58.2",
85
+ "simple-git": "^3.33.0",
86
+ "strip-ansi": "^7.2.0",
87
+ "svg-to-pdfkit": "^0.1.8",
88
+ "ws": "^8.20.0",
89
+ "xlsx": "^0.18.5",
90
+ "zod": "^4.3.6"
91
+ },
92
+ "devDependencies": {
93
+ "@types/better-sqlite3": "^7.6.13",
94
+ "@types/debug": "^4.1.13",
95
+ "@types/express": "^5.0.6",
96
+ "@types/multer": "^2.1.0",
97
+ "@types/node": "^25.5.0",
98
+ "@types/nodemailer": "^7.0.11",
99
+ "@types/pdf-parse": "^1.1.5",
100
+ "@types/ws": "^8.18.1",
101
+ "docx": "^9.6.1",
102
+ "rimraf": "^6.1.3",
103
+ "tsup": "^8.5.1",
104
+ "typescript": "^6.0.2",
105
+ "vitest": "^4.1.1"
106
+ },
107
+ "pnpm": {
108
+ "onlyBuiltDependencies": [
109
+ "better-sqlite3",
110
+ "esbuild"
111
+ ]
112
+ }
113
+ }