@test-station/cli 0.1.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.
Files changed (3) hide show
  1. package/package.json +22 -0
  2. package/src/cli.js +9 -0
  3. package/src/index.js +134 -0
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@test-station/cli",
3
+ "version": "0.1.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "type": "module",
8
+ "bin": {
9
+ "test-station": "./src/cli.js"
10
+ },
11
+ "exports": {
12
+ ".": "./src/index.js"
13
+ },
14
+ "dependencies": {
15
+ "@test-station/core": "workspace:*",
16
+ "@test-station/render-html": "workspace:*"
17
+ },
18
+ "scripts": {
19
+ "build": "node ../../scripts/check-package.mjs ./src/index.js && node --check ./src/cli.js",
20
+ "lint": "node ../../scripts/lint-syntax.mjs ./src"
21
+ }
22
+ }
package/src/cli.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from './index.js';
3
+
4
+ runCli().then((code) => {
5
+ process.exit(code);
6
+ }).catch((error) => {
7
+ process.stderr.write(`${error instanceof Error ? error.stack || error.message : String(error)}\n`);
8
+ process.exit(1);
9
+ });
package/src/index.js ADDED
@@ -0,0 +1,134 @@
1
+ import path from 'node:path';
2
+ import { loadConfig, summarizeConfig, runReport, readJson, formatConsoleSummary, createConsoleProgressReporter } from '@test-station/core';
3
+ import { writeHtmlReport } from '@test-station/render-html';
4
+
5
+ export function parseCliArgs(argv) {
6
+ const parsed = {
7
+ command: argv[0] || 'help',
8
+ config: './test-station.config.mjs',
9
+ input: null,
10
+ output: null,
11
+ outputDir: null,
12
+ dryRun: false,
13
+ coverage: false,
14
+ workspaceFilters: [],
15
+ };
16
+
17
+ for (let index = 1; index < argv.length; index += 1) {
18
+ const token = argv[index];
19
+ if (token === '--config') {
20
+ parsed.config = argv[index + 1];
21
+ index += 1;
22
+ continue;
23
+ }
24
+ if (token === '--input') {
25
+ parsed.input = argv[index + 1];
26
+ index += 1;
27
+ continue;
28
+ }
29
+ if (token === '--output') {
30
+ parsed.output = argv[index + 1];
31
+ index += 1;
32
+ continue;
33
+ }
34
+ if (token === '--output-dir') {
35
+ parsed.outputDir = argv[index + 1];
36
+ index += 1;
37
+ continue;
38
+ }
39
+ if (token === '--workspace' || token === '--package') {
40
+ parsed.workspaceFilters.push(argv[index + 1]);
41
+ index += 1;
42
+ continue;
43
+ }
44
+ if (token === '--dry-run') {
45
+ parsed.dryRun = true;
46
+ continue;
47
+ }
48
+ if (token === '--coverage') {
49
+ parsed.coverage = true;
50
+ }
51
+ }
52
+
53
+ return parsed;
54
+ }
55
+
56
+ export function renderHelp() {
57
+ return [
58
+ 'test-station CLI',
59
+ '',
60
+ 'Commands:',
61
+ ' test-station inspect --config ./test-station.config.mjs',
62
+ ' test-station run --config ./test-station.config.mjs [--dry-run] [--coverage] [--workspace <name>|--package <name>] [--output-dir <path>]',
63
+ ' test-station render --input ./artifacts/workspace-tests/report.json --output ./artifacts/workspace-tests',
64
+ ].join('\n');
65
+ }
66
+
67
+ export async function runCli(argv = process.argv.slice(2)) {
68
+ const args = parseCliArgs(argv);
69
+
70
+ if (args.command === 'help' || args.command === '--help' || args.command === '-h') {
71
+ process.stdout.write(`${renderHelp()}\n`);
72
+ return 0;
73
+ }
74
+
75
+ if (args.command === 'inspect') {
76
+ const loaded = await loadConfig(args.config);
77
+ process.stdout.write(`${JSON.stringify({ configPath: loaded.resolvedPath, summary: summarizeConfig(loaded.config) }, null, 2)}\n`);
78
+ return 0;
79
+ }
80
+
81
+ if (args.command === 'run') {
82
+ const loaded = await loadConfig(args.config);
83
+ const consoleEnabled = loaded.config?.render?.console !== false;
84
+ let progressReporter = null;
85
+
86
+ if (consoleEnabled) {
87
+ progressReporter = createConsoleProgressReporter({ stream: process.stdout });
88
+ }
89
+
90
+ const execution = await runReport({
91
+ configPath: args.config,
92
+ dryRun: args.dryRun,
93
+ coverage: args.coverage,
94
+ outputDir: args.outputDir,
95
+ workspaceFilters: args.workspaceFilters,
96
+ onEvent: progressReporter?.onEvent,
97
+ });
98
+
99
+ let htmlPath = null;
100
+ if (execution.context.config?.render?.html !== false) {
101
+ htmlPath = writeHtmlReport(execution.report, execution.context.project.outputDir, {
102
+ title: execution.context.project.name,
103
+ projectRootDir: execution.context.project.rootDir,
104
+ defaultView: execution.context.config?.render?.defaultView,
105
+ includeDetailedAnalysisToggle: execution.context.config?.render?.includeDetailedAnalysisToggle,
106
+ });
107
+ }
108
+
109
+ if (execution.context.config?.render?.console !== false) {
110
+ process.stdout.write(formatConsoleSummary(execution.report, execution.artifactPaths, { htmlPath }));
111
+ } else {
112
+ process.stdout.write(`${JSON.stringify({ report: execution.artifactPaths.reportJsonPath, html: htmlPath }, null, 2)}\n`);
113
+ }
114
+
115
+ return execution.report.summary.failedPackages > 0 || execution.report.summary.failedSuites > 0 ? 1 : 0;
116
+ }
117
+
118
+ if (args.command === 'render') {
119
+ const inputPath = args.input || path.resolve(process.cwd(), 'artifacts/workspace-tests/report.json');
120
+ const report = readJson(inputPath);
121
+ const outputDir = args.output || path.dirname(inputPath);
122
+ const reportPath = writeHtmlReport(report, outputDir, {
123
+ title: report?.meta?.projectName || report?.summary?.projectName || 'test-station',
124
+ projectRootDir: report?.meta?.projectRootDir || process.cwd(),
125
+ defaultView: report?.meta?.render?.defaultView,
126
+ includeDetailedAnalysisToggle: report?.meta?.render?.includeDetailedAnalysisToggle,
127
+ });
128
+ process.stdout.write(`${JSON.stringify({ input: inputPath, output: reportPath }, null, 2)}\n`);
129
+ return 0;
130
+ }
131
+
132
+ process.stderr.write(`Unknown command: ${args.command}\n\n${renderHelp()}\n`);
133
+ return 1;
134
+ }