@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.
@@ -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 cross_spawn_1 = require("cross-spawn");
8
- const commander_1 = require("commander");
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 config_js_1 = require("../config.js");
14
- const dotenv_1 = __importDefault(require("dotenv"));
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
- const program = new commander_1.Command();
18
- program
19
- .option('-c, --command <cmd>', 'Test runner command')
20
- .option('--launch', 'Start a new run and return its ID')
21
- .option('--finish', 'Finish Run by its ID')
22
- .option('--env-file <envfile>', 'Load environment variables from env file')
23
- .option('--filter <filter>', 'Additional execution filter')
24
- .action(async (opts) => {
25
- const { launch, finish, filter } = opts;
26
- let { command } = opts;
27
- if (opts.envFile)
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
- let exitCode = 0;
57
- if (!command.split) {
58
- process.exitCode = 255;
59
- console.log(constants_js_1.APP_PREFIX, `No command provided. Use -c option to launch a test runner.`);
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
- const client = new client_js_1.default({ apiKey, title, parallel: true });
63
- if (filter) {
64
- const [pipe, ...optsArray] = filter.split(':');
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
- const testCmds = command.split(' ');
79
- console.log(constants_js_1.APP_PREFIX, `🚀 Running`, picocolors_1.default.green(command));
80
- if (!apiKey) {
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
- client.createRun().then(() => {
91
- const cmd = (0, cross_spawn_1.spawn)(testCmds[0], testCmds.slice(1), { stdio: 'inherit' });
92
- cmd.on('close', code => {
93
- const emoji = code === 0 ? '🟢' : '🔴';
94
- console.log(constants_js_1.APP_PREFIX, emoji, `Runner exited with ${picocolors_1.default.bold(code)}`);
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
- program.parse(process.argv);
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
+ });
@@ -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 ${n === 1 ? 'one test' : `${n} tests`} in Testomat.io!`);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "2.1.1",
3
+ "version": "2.1.2-beta.1-alias",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -1,124 +1,53 @@
1
1
  #!/usr/bin/env node
2
- import { spawn } from 'cross-spawn';
3
- import { Command } from 'commander';
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 { config } from '../config.js';
9
- import dotenv from 'dotenv';
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
- // @ts-ignore
54
- client.updateRunStatus(STATUS.FINISHED).then(() => {
55
- console.log(pc.yellow(`Run ${process.env.TESTOMATIO_RUN} was finished`));
56
- process.exit(0);
57
- });
58
- return;
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
- let exitCode = 0;
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
- if (process.argv.length <= 2) {
121
- program.outputHelp();
122
- }
47
+ const child = spawn(process.execPath, [cliPath, ...newArgs], {
48
+ stdio: 'inherit'
49
+ });
123
50
 
124
- program.parse(process.argv);
51
+ child.on('exit', (code) => {
52
+ process.exit(code);
53
+ });
@@ -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 ${n === 1 ? 'one test' : `${n} tests`} in Testomat.io!`);
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;