@testomatio/reporter 2.1.1 → 2.1.2-beta.1-alias
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/lib/bin/startTest.js +38 -91
- package/lib/utils/utils.js +1 -3
- package/package.json +1 -1
- package/src/bin/startTest.js +43 -114
- package/src/utils/utils.js +3 -5
package/lib/bin/startTest.js
CHANGED
|
@@ -4,103 +4,50 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
10
|
-
const client_js_1 = __importDefault(require("../client.js"));
|
|
11
|
-
const constants_js_1 = require("../constants.js");
|
|
7
|
+
const node_child_process_1 = require("node:child_process");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
12
9
|
const utils_js_1 = require("../utils/utils.js");
|
|
13
|
-
const
|
|
14
|
-
|
|
10
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
11
|
+
// Define __dirname - this will be replaced by build script with actual __dirname for CommonJS
|
|
12
|
+
const cliPath = (0, node_path_1.join)(__dirname, 'cli.js');
|
|
15
13
|
const version = (0, utils_js_1.getPackageVersion)();
|
|
16
14
|
console.log(picocolors_1.default.cyan(picocolors_1.default.bold(` 🤩 Testomat.io Reporter v${version}`)));
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
dotenv_1.default.config({ path: opts.envFile });
|
|
29
|
-
const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config_js_1.config.TESTOMATIO;
|
|
30
|
-
const title = process.env.TESTOMATIO_TITLE;
|
|
31
|
-
if (launch) {
|
|
32
|
-
console.log('Starting a new Run on Testomat.io...');
|
|
33
|
-
const client = new client_js_1.default({ apiKey });
|
|
34
|
-
client.createRun().then(() => {
|
|
35
|
-
console.log(process.env.runId);
|
|
36
|
-
process.exit(0);
|
|
37
|
-
});
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (finish) {
|
|
41
|
-
// TODO: add error in case of TESTOMATIO environment variable is not set
|
|
42
|
-
// because command is fine in console, but actually (on testomat.io) run is not finished
|
|
43
|
-
if (!process.env.TESTOMATIO_RUN) {
|
|
44
|
-
console.log('TESTOMATIO_RUN environment variable must be set.');
|
|
45
|
-
return process.exit(1);
|
|
15
|
+
// Parse command line arguments to map start-test-run options to @testomatio/reporter run format
|
|
16
|
+
const args = process.argv.slice(2);
|
|
17
|
+
const newArgs = ['run'];
|
|
18
|
+
let i = 0;
|
|
19
|
+
while (i < args.length) {
|
|
20
|
+
const arg = args[i];
|
|
21
|
+
if (arg === '-c' || arg === '--command') {
|
|
22
|
+
// Map -c/--command to positional argument for run command
|
|
23
|
+
i++;
|
|
24
|
+
if (i < args.length) {
|
|
25
|
+
newArgs.push(args[i]);
|
|
46
26
|
}
|
|
47
|
-
console.log('Finishing Run on Testomat.io...');
|
|
48
|
-
const client = new client_js_1.default({ apiKey });
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
client.updateRunStatus(constants_js_1.STATUS.FINISHED).then(() => {
|
|
51
|
-
console.log(picocolors_1.default.yellow(`Run ${process.env.TESTOMATIO_RUN} was finished`));
|
|
52
|
-
process.exit(0);
|
|
53
|
-
});
|
|
54
|
-
return;
|
|
55
27
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return;
|
|
28
|
+
else if (arg.startsWith('--command=')) {
|
|
29
|
+
// Handle --command=value format
|
|
30
|
+
const command = arg.split('=', 2)[1];
|
|
31
|
+
newArgs.push(command);
|
|
61
32
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const pipeOptions = optsArray.join(':');
|
|
66
|
-
try {
|
|
67
|
-
const tests = await client.prepareRun({ pipe, pipeOptions });
|
|
68
|
-
if (!tests || tests.length === 0) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const grep = ` --grep (${tests.join('|')})`;
|
|
72
|
-
command += grep;
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
console.log(constants_js_1.APP_PREFIX, err);
|
|
76
|
-
}
|
|
33
|
+
else if (arg === '--launch') {
|
|
34
|
+
// Map --launch to start command
|
|
35
|
+
newArgs[0] = 'start';
|
|
77
36
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const cmd = (0, cross_spawn_1.spawn)(testCmds[0], testCmds.slice(1), { stdio: 'inherit' });
|
|
82
|
-
cmd.on('close', code => {
|
|
83
|
-
console.log(constants_js_1.APP_PREFIX, '⚠️ ', `Runner exited with ${picocolors_1.default.bold(code)}, report is ignored`);
|
|
84
|
-
if (code > exitCode)
|
|
85
|
-
exitCode = code;
|
|
86
|
-
process.exitCode = exitCode;
|
|
87
|
-
});
|
|
88
|
-
return;
|
|
37
|
+
else if (arg === '--finish') {
|
|
38
|
+
// Map --finish to finish command
|
|
39
|
+
newArgs[0] = 'finish';
|
|
89
40
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const status = code === 0 ? 'passed' : 'failed';
|
|
96
|
-
client.updateRunStatus(status, true);
|
|
97
|
-
if (code > exitCode)
|
|
98
|
-
exitCode = code;
|
|
99
|
-
process.exitCode = exitCode;
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
if (process.argv.length <= 2) {
|
|
104
|
-
program.outputHelp();
|
|
41
|
+
else {
|
|
42
|
+
// Pass through other arguments
|
|
43
|
+
newArgs.push(arg);
|
|
44
|
+
}
|
|
45
|
+
i++;
|
|
105
46
|
}
|
|
106
|
-
|
|
47
|
+
// Execute the main CLI with mapped arguments
|
|
48
|
+
const child = (0, node_child_process_1.spawn)(process.execPath, [cliPath, ...newArgs], {
|
|
49
|
+
stdio: 'inherit'
|
|
50
|
+
});
|
|
51
|
+
child.on('exit', (code) => {
|
|
52
|
+
process.exit(code);
|
|
53
|
+
});
|
package/lib/utils/utils.js
CHANGED
|
@@ -321,7 +321,7 @@ const fileSystem = {
|
|
|
321
321
|
exports.fileSystem = fileSystem;
|
|
322
322
|
const foundedTestLog = (app, tests) => {
|
|
323
323
|
const n = tests.length;
|
|
324
|
-
return console.log(app, `✅ We found
|
|
324
|
+
return n === 1 ? console.log(app, `✅ We found one test!`) : console.log(app, `✅ We found ${n} tests!`);
|
|
325
325
|
};
|
|
326
326
|
exports.foundedTestLog = foundedTestLog;
|
|
327
327
|
const humanize = text => {
|
|
@@ -399,8 +399,6 @@ function storeRunId(runId) {
|
|
|
399
399
|
function readLatestRunId() {
|
|
400
400
|
try {
|
|
401
401
|
const filePath = path_1.default.join(os_1.default.tmpdir(), `testomatio.latest.run`);
|
|
402
|
-
if (!fs_1.default.existsSync(filePath))
|
|
403
|
-
return null;
|
|
404
402
|
const stats = fs_1.default.statSync(filePath);
|
|
405
403
|
const diff = +new Date() - +stats.mtime;
|
|
406
404
|
const diffHours = diff / 1000 / 60 / 60;
|
package/package.json
CHANGED
package/src/bin/startTest.js
CHANGED
|
@@ -1,124 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { spawn } from '
|
|
3
|
-
import {
|
|
4
|
-
import pc from 'picocolors';
|
|
5
|
-
import TestomatClient from '../client.js';
|
|
6
|
-
import { APP_PREFIX, STATUS } from '../constants.js';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { join, dirname } from 'node:path';
|
|
7
4
|
import { getPackageVersion } from '../utils/utils.js';
|
|
8
|
-
import
|
|
9
|
-
|
|
5
|
+
import pc from 'picocolors';
|
|
6
|
+
|
|
7
|
+
// Define __dirname - this will be replaced by build script with actual __dirname for CommonJS
|
|
8
|
+
const __dirname = typeof globalThis.__dirname !== 'undefined' ? globalThis.__dirname : '.';
|
|
9
|
+
const cliPath = join(__dirname, 'cli.js');
|
|
10
10
|
|
|
11
11
|
const version = getPackageVersion();
|
|
12
12
|
console.log(pc.cyan(pc.bold(` 🤩 Testomat.io Reporter v${version}`)));
|
|
13
|
-
const program = new Command();
|
|
14
|
-
|
|
15
|
-
program
|
|
16
|
-
.option('-c, --command <cmd>', 'Test runner command')
|
|
17
|
-
.option('--launch', 'Start a new run and return its ID')
|
|
18
|
-
.option('--finish', 'Finish Run by its ID')
|
|
19
|
-
.option('--env-file <envfile>', 'Load environment variables from env file')
|
|
20
|
-
.option('--filter <filter>', 'Additional execution filter')
|
|
21
|
-
.action(async opts => {
|
|
22
|
-
const { launch, finish, filter } = opts;
|
|
23
|
-
let { command } = opts;
|
|
24
|
-
|
|
25
|
-
if (opts.envFile) dotenv.config({ path: opts.envFile });
|
|
26
|
-
|
|
27
|
-
const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config.TESTOMATIO;
|
|
28
|
-
const title = process.env.TESTOMATIO_TITLE;
|
|
29
|
-
|
|
30
|
-
if (launch) {
|
|
31
|
-
console.log('Starting a new Run on Testomat.io...');
|
|
32
|
-
const client = new TestomatClient({ apiKey });
|
|
33
|
-
|
|
34
|
-
client.createRun().then(() => {
|
|
35
|
-
console.log(process.env.runId);
|
|
36
|
-
process.exit(0);
|
|
37
|
-
});
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (finish) {
|
|
42
|
-
// TODO: add error in case of TESTOMATIO environment variable is not set
|
|
43
|
-
// because command is fine in console, but actually (on testomat.io) run is not finished
|
|
44
|
-
if (!process.env.TESTOMATIO_RUN) {
|
|
45
|
-
console.log('TESTOMATIO_RUN environment variable must be set.');
|
|
46
|
-
return process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
console.log('Finishing Run on Testomat.io...');
|
|
50
|
-
|
|
51
|
-
const client = new TestomatClient({ apiKey });
|
|
52
13
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
14
|
+
// Parse command line arguments to map start-test-run options to @testomatio/reporter run format
|
|
15
|
+
const args = process.argv.slice(2);
|
|
16
|
+
const newArgs = ['run'];
|
|
17
|
+
|
|
18
|
+
let i = 0;
|
|
19
|
+
while (i < args.length) {
|
|
20
|
+
const arg = args[i];
|
|
21
|
+
|
|
22
|
+
if (arg === '-c' || arg === '--command') {
|
|
23
|
+
// Map -c/--command to positional argument for run command
|
|
24
|
+
i++;
|
|
25
|
+
if (i < args.length) {
|
|
26
|
+
newArgs.push(args[i]);
|
|
59
27
|
}
|
|
28
|
+
} else if (arg.startsWith('--command=')) {
|
|
29
|
+
// Handle --command=value format
|
|
30
|
+
const command = arg.split('=', 2)[1];
|
|
31
|
+
newArgs.push(command);
|
|
32
|
+
} else if (arg === '--launch') {
|
|
33
|
+
// Map --launch to start command
|
|
34
|
+
newArgs[0] = 'start';
|
|
35
|
+
} else if (arg === '--finish') {
|
|
36
|
+
// Map --finish to finish command
|
|
37
|
+
newArgs[0] = 'finish';
|
|
38
|
+
} else {
|
|
39
|
+
// Pass through other arguments
|
|
40
|
+
newArgs.push(arg);
|
|
41
|
+
}
|
|
42
|
+
i++;
|
|
43
|
+
}
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!command.split) {
|
|
64
|
-
process.exitCode = 255;
|
|
65
|
-
console.log(APP_PREFIX, `No command provided. Use -c option to launch a test runner.`);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const client = new TestomatClient({ apiKey, title, parallel: true });
|
|
70
|
-
|
|
71
|
-
if (filter) {
|
|
72
|
-
const [pipe, ...optsArray] = filter.split(':');
|
|
73
|
-
const pipeOptions = optsArray.join(':');
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const tests = await client.prepareRun({ pipe, pipeOptions });
|
|
77
|
-
|
|
78
|
-
if (!tests || tests.length === 0) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const grep = ` --grep (${tests.join('|')})`;
|
|
83
|
-
command += grep;
|
|
84
|
-
} catch (err) {
|
|
85
|
-
console.log(APP_PREFIX, err);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const testCmds = command.split(' ');
|
|
90
|
-
console.log(APP_PREFIX, `🚀 Running`, pc.green(command));
|
|
91
|
-
|
|
92
|
-
if (!apiKey) {
|
|
93
|
-
const cmd = spawn(testCmds[0], testCmds.slice(1), { stdio: 'inherit' });
|
|
94
|
-
|
|
95
|
-
cmd.on('close', code => {
|
|
96
|
-
console.log(APP_PREFIX, '⚠️ ', `Runner exited with ${pc.bold(code)}, report is ignored`);
|
|
97
|
-
|
|
98
|
-
if (code > exitCode) exitCode = code;
|
|
99
|
-
process.exitCode = exitCode;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
client.createRun().then(() => {
|
|
106
|
-
const cmd = spawn(testCmds[0], testCmds.slice(1), { stdio: 'inherit' });
|
|
107
|
-
|
|
108
|
-
cmd.on('close', code => {
|
|
109
|
-
const emoji = code === 0 ? '🟢' : '🔴';
|
|
110
|
-
console.log(APP_PREFIX, emoji, `Runner exited with ${pc.bold(code)}`);
|
|
111
|
-
const status = code === 0 ? 'passed' : 'failed';
|
|
112
|
-
client.updateRunStatus(status, true);
|
|
113
|
-
|
|
114
|
-
if (code > exitCode) exitCode = code;
|
|
115
|
-
process.exitCode = exitCode;
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
|
45
|
+
// Execute the main CLI with mapped arguments
|
|
119
46
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
47
|
+
const child = spawn(process.execPath, [cliPath, ...newArgs], {
|
|
48
|
+
stdio: 'inherit'
|
|
49
|
+
});
|
|
123
50
|
|
|
124
|
-
|
|
51
|
+
child.on('exit', (code) => {
|
|
52
|
+
process.exit(code);
|
|
53
|
+
});
|
package/src/utils/utils.js
CHANGED
|
@@ -53,7 +53,7 @@ const parseSuite = suiteTitle => {
|
|
|
53
53
|
*/
|
|
54
54
|
const validateSuiteId = suiteId => {
|
|
55
55
|
if (!suiteId) return null;
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
const match = suiteId.match(SUITE_ID_REGEX);
|
|
58
58
|
return match ? match[0] : null;
|
|
59
59
|
};
|
|
@@ -273,7 +273,7 @@ const fileSystem = {
|
|
|
273
273
|
const foundedTestLog = (app, tests) => {
|
|
274
274
|
const n = tests.length;
|
|
275
275
|
|
|
276
|
-
return console.log(app, `✅ We found
|
|
276
|
+
return n === 1 ? console.log(app, `✅ We found one test!`) : console.log(app, `✅ We found ${n} tests!`);
|
|
277
277
|
};
|
|
278
278
|
|
|
279
279
|
const humanize = text => {
|
|
@@ -354,14 +354,12 @@ function storeRunId(runId) {
|
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
/**
|
|
357
|
-
*
|
|
357
|
+
*
|
|
358
358
|
* @returns {String|null} latest run ID
|
|
359
359
|
*/
|
|
360
360
|
function readLatestRunId() {
|
|
361
361
|
try {
|
|
362
362
|
const filePath = path.join(os.tmpdir(), `testomatio.latest.run`);
|
|
363
|
-
if (!fs.existsSync(filePath)) return null;
|
|
364
|
-
|
|
365
363
|
const stats = fs.statSync(filePath);
|
|
366
364
|
const diff = +new Date() - +stats.mtime;
|
|
367
365
|
const diffHours = diff / 1000 / 60 / 60;
|