qase-javascript-commons 2.5.3 → 2.5.5

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/changelog.md CHANGED
@@ -1,3 +1,23 @@
1
+ # qase-javascript-commons@2.5.5
2
+
3
+ ## What's new
4
+
5
+ Significantly improved startup performance by optimizing host data collection:
6
+
7
+ - Replaced slow `npm list --depth=10 --json` fallback with fast `require.resolve()`-based package version lookup.
8
+ - Replaced `execSync('node --version')` with `process.version`.
9
+ - Replaced `execSync('npm --version')` with `process.env.npm_config_user_agent` parsing (with execSync fallback).
10
+ - Eliminated duplicate `getHostInfo()` call in `ReportReporter.complete()` by passing pre-collected host data from `QaseReporter`.
11
+ - Included `report` mode in the `needsHostData` guard so host data is collected once during init.
12
+
13
+ Worst-case startup time reduced from ~10-25 seconds to ~55 ms.
14
+
15
+ # qase-javascript-commons@2.5.4
16
+
17
+ ## What's new
18
+
19
+ - Fixed an issue where non-string parameter values (e.g. numbers) were sent to the Qase API as-is, causing validation errors. The `transformParams` method now converts all parameter values to strings.
20
+
1
21
  # qase-javascript-commons@2.5.3
2
22
 
3
23
  ## What's new
@@ -146,8 +146,8 @@ class ClientV2 extends clientV1_1.ClientV1 {
146
146
  transformParams(params) {
147
147
  const transformedParams = {};
148
148
  for (const [key, value] of Object.entries(params)) {
149
- if (value) {
150
- transformedParams[key] = value;
149
+ if (value != null) {
150
+ transformedParams[key] = String(value);
151
151
  }
152
152
  }
153
153
  return transformedParams;
package/dist/qase.js CHANGED
@@ -97,13 +97,7 @@ class QaseReporter {
97
97
  this.logger.logDebug(`Config: ${JSON.stringify(this.sanitizeOptions(composedOptions))}`);
98
98
  const effectiveMode = composedOptions.mode || options_1.ModeEnum.off;
99
99
  const effectiveFallback = composedOptions.fallback || options_1.ModeEnum.off;
100
- const needsHostData = effectiveMode === options_1.ModeEnum.testops ||
101
- effectiveMode === options_1.ModeEnum.testops_multi ||
102
- effectiveFallback === options_1.ModeEnum.testops ||
103
- effectiveFallback === options_1.ModeEnum.testops_multi;
104
- this.hostData = needsHostData
105
- ? (0, hostData_1.getHostInfo)(options.frameworkPackage, options.reporterName)
106
- : (0, hostData_1.getMinimalHostData)();
100
+ this.hostData = (0, hostData_1.getHostInfo)(options.frameworkPackage, options.reporterName);
107
101
  this.logger.logDebug(`Host data: ${JSON.stringify(this.hostData)}`);
108
102
  this.captureLogs = composedOptions.captureLogs;
109
103
  try {
@@ -474,7 +468,7 @@ class QaseReporter {
474
468
  case options_1.ModeEnum.report: {
475
469
  const localOptions = options.report?.connections?.[writer_1.DriverEnum.local];
476
470
  const writer = new writer_1.FsWriter(localOptions);
477
- return new reporters_1.ReportReporter(this.logger, writer, options.frameworkPackage, options.reporterName, options.environment, options.rootSuite, options.testops?.run?.id);
471
+ return new reporters_1.ReportReporter(this.logger, writer, options.frameworkPackage, options.reporterName, options.environment, options.rootSuite, options.testops?.run?.id, this.hostData);
478
472
  }
479
473
  case options_1.ModeEnum.off:
480
474
  throw new disabled_exception_1.DisabledException();
@@ -2,6 +2,7 @@ import { AbstractReporter } from './abstract-reporter';
2
2
  import { Attachment } from '../models';
3
3
  import { WriterInterface } from '../writer';
4
4
  import { LoggerInterface } from '../utils/logger';
5
+ import { HostData } from '../models/host-data';
5
6
  /**
6
7
  * @class ReportReporter
7
8
  * @extends AbstractReporter
@@ -13,6 +14,7 @@ export declare class ReportReporter extends AbstractReporter {
13
14
  private readonly environment;
14
15
  private readonly runId;
15
16
  private readonly rootSuite;
17
+ private readonly hostData;
16
18
  private startTime;
17
19
  /**
18
20
  * @param {LoggerInterface} logger
@@ -22,8 +24,9 @@ export declare class ReportReporter extends AbstractReporter {
22
24
  * @param {string | undefined} environment
23
25
  * @param {string | undefined} rootSuite
24
26
  * @param {number | undefined} runId
27
+ * @param {HostData | undefined} hostData
25
28
  */
26
- constructor(logger: LoggerInterface, writer: WriterInterface, frameworkName: string, reporterName: string, environment?: string, rootSuite?: string, runId?: number);
29
+ constructor(logger: LoggerInterface, writer: WriterInterface, frameworkName: string, reporterName: string, environment?: string, rootSuite?: string, runId?: number, hostData?: HostData);
27
30
  /**
28
31
  * @returns {Promise<void>}
29
32
  */
@@ -15,6 +15,7 @@ class ReportReporter extends abstract_reporter_1.AbstractReporter {
15
15
  environment;
16
16
  runId;
17
17
  rootSuite;
18
+ hostData;
18
19
  startTime = Date.now();
19
20
  /**
20
21
  * @param {LoggerInterface} logger
@@ -24,8 +25,9 @@ class ReportReporter extends abstract_reporter_1.AbstractReporter {
24
25
  * @param {string | undefined} environment
25
26
  * @param {string | undefined} rootSuite
26
27
  * @param {number | undefined} runId
28
+ * @param {HostData | undefined} hostData
27
29
  */
28
- constructor(logger, writer, frameworkName, reporterName, environment, rootSuite, runId) {
30
+ constructor(logger, writer, frameworkName, reporterName, environment, rootSuite, runId, hostData) {
29
31
  super(logger);
30
32
  this.writer = writer;
31
33
  this.frameworkName = frameworkName;
@@ -33,6 +35,7 @@ class ReportReporter extends abstract_reporter_1.AbstractReporter {
33
35
  this.environment = environment;
34
36
  this.runId = runId;
35
37
  this.rootSuite = rootSuite;
38
+ this.hostData = hostData;
36
39
  }
37
40
  /**
38
41
  * @returns {Promise<void>}
@@ -103,7 +106,7 @@ class ReportReporter extends abstract_reporter_1.AbstractReporter {
103
106
  threads: [],
104
107
  suites: [],
105
108
  environment: this.environment ?? '',
106
- host_data: (0, hostData_1.getHostInfo)(this.frameworkName, this.reporterName),
109
+ host_data: this.hostData ?? (0, hostData_1.getHostInfo)(this.frameworkName, this.reporterName),
107
110
  };
108
111
  for (const result of this.results) {
109
112
  report.stats.total++;
@@ -1,10 +1,4 @@
1
1
  import { HostData } from '../models/host-data';
2
- /**
3
- * Returns minimal host data without slow operations (no npm list, no execSync for node/npm).
4
- * Use when reporter mode is "off" to avoid startup delay.
5
- * @returns {HostData} Minimal host information object
6
- */
7
- export declare function getMinimalHostData(): HostData;
8
2
  /**
9
3
  * Gets information about the current host environment
10
4
  * @param {string} framework The framework name to check version for
@@ -33,13 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.getMinimalHostData = getMinimalHostData;
37
36
  exports.getHostInfo = getHostInfo;
38
37
  const os = __importStar(require("os"));
39
38
  const cp = __importStar(require("child_process"));
40
39
  const fs = __importStar(require("fs"));
41
- const path = __importStar(require("path"));
42
- const child_process_1 = require("child_process");
40
+ const get_package_version_1 = require("./get-package-version");
43
41
  /**
44
42
  * Gets detailed OS information based on the platform
45
43
  * @returns {string} Detailed OS information
@@ -76,110 +74,24 @@ function getDetailedOSInfo() {
76
74
  }
77
75
  }
78
76
  /**
79
- * Executes a command and returns its trimmed output
80
- * @param {string} command Command to execute
81
- * @param {string} defaultValue Default value if command fails
82
- * @returns {string} Command output or default value
77
+ * Gets npm version from environment or by executing npm command
78
+ * @returns {string} npm version string
83
79
  */
84
- function execCommand(command, defaultValue = '') {
85
- try {
86
- return cp.execSync(command).toString().trim();
87
- }
88
- catch (error) {
89
- console.error(`Error executing command '${command}':`, error);
90
- return defaultValue;
91
- }
92
- }
93
- /**
94
- * Recursively searches for a package in dependencies tree
95
- * @param {Record<string, PackageInfo>} dependencies The dependencies object to search in
96
- * @param {string} packageName The name of the package to find
97
- * @returns {string | null} The package version or null if not found
98
- */
99
- function findPackageInDependencies(dependencies, packageName) {
100
- // If no dependencies, return null
101
- if (!dependencies)
102
- return null;
103
- // Check if the package exists at the current level
104
- if (packageName in dependencies) {
105
- return dependencies[packageName]?.version ?? null;
106
- }
107
- // Recursively search in nested dependencies
108
- for (const dep of Object.values(dependencies)) {
109
- if (dep.dependencies) {
110
- const foundVersion = findPackageInDependencies(dep.dependencies, packageName);
111
- if (foundVersion) {
112
- return foundVersion;
113
- }
80
+ function getNpmVersion() {
81
+ const userAgent = process.env['npm_config_user_agent'];
82
+ if (userAgent) {
83
+ const match = userAgent.match(/^npm\/(\S+)/);
84
+ if (match?.[1]) {
85
+ return match[1];
114
86
  }
115
87
  }
116
- return null;
117
- }
118
- /**
119
- * Gets the version of a Node.js package
120
- * @param {string} packageName The name of the package
121
- * @returns {string | null} The package version or null if not found
122
- */
123
- function getPackageVersion(packageName) {
124
- if (!packageName)
125
- return null;
126
88
  try {
127
- // First try to get from node_modules
128
- const packagePath = path.resolve(process.cwd(), 'node_modules', packageName, 'package.json');
129
- if (fs.existsSync(packagePath)) {
130
- const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
131
- return packageJson.version;
132
- }
133
- // Try using npm list as fallback with recursive search
134
- let output = null;
135
- try {
136
- output = (0, child_process_1.execSync)(`npm list --depth=10 --json`, { stdio: "pipe" }).toString();
137
- if (!output)
138
- return null;
139
- }
140
- catch (error) {
141
- return null;
142
- }
143
- try {
144
- const npmList = JSON.parse(output);
145
- // Try direct dependency
146
- const directVersion = npmList.dependencies?.[packageName]?.version;
147
- if (directVersion)
148
- return directVersion;
149
- // Try recursive search
150
- return findPackageInDependencies(npmList.dependencies, packageName);
151
- }
152
- catch (parseError) {
153
- console.error('Error parsing npm list output:', parseError);
154
- return null;
155
- }
89
+ return cp.execSync('npm --version', { stdio: 'pipe' }).toString().trim();
156
90
  }
157
- catch (error) {
158
- console.error(`Error getting version for package ${packageName}:`, error);
159
- return null;
91
+ catch {
92
+ return '';
160
93
  }
161
94
  }
162
- /**
163
- * Returns minimal host data without slow operations (no npm list, no execSync for node/npm).
164
- * Use when reporter mode is "off" to avoid startup delay.
165
- * @returns {HostData} Minimal host information object
166
- */
167
- function getMinimalHostData() {
168
- return {
169
- system: os.platform(),
170
- machineName: os.hostname(),
171
- release: os.release(),
172
- version: '',
173
- arch: os.arch(),
174
- node: '',
175
- npm: '',
176
- framework: '',
177
- reporter: '',
178
- commons: '',
179
- apiClientV1: '',
180
- apiClientV2: '',
181
- };
182
- }
183
95
  /**
184
96
  * Gets information about the current host environment
185
97
  * @param {string} framework The framework name to check version for
@@ -194,13 +106,13 @@ function getHostInfo(framework, reporterName) {
194
106
  release: os.release(),
195
107
  version: getDetailedOSInfo(),
196
108
  arch: os.arch(),
197
- node: execCommand('node --version'),
198
- npm: execCommand('npm --version'),
199
- framework: getPackageVersion(framework) ?? '',
200
- reporter: getPackageVersion(reporterName) ?? '',
201
- commons: getPackageVersion('qase-javascript-commons') ?? '',
202
- apiClientV1: getPackageVersion('qase-api-client') ?? '',
203
- apiClientV2: getPackageVersion('qase-api-v2-client') ?? '',
109
+ node: process.version,
110
+ npm: getNpmVersion(),
111
+ framework: (0, get_package_version_1.getPackageVersion)(framework) ?? '',
112
+ reporter: (0, get_package_version_1.getPackageVersion)(reporterName) ?? '',
113
+ commons: (0, get_package_version_1.getPackageVersion)('qase-javascript-commons') ?? '',
114
+ apiClientV1: (0, get_package_version_1.getPackageVersion)('qase-api-client') ?? '',
115
+ apiClientV2: (0, get_package_version_1.getPackageVersion)('qase-api-v2-client') ?? '',
204
116
  };
205
117
  }
206
118
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qase-javascript-commons",
3
- "version": "2.5.3",
3
+ "version": "2.5.5",
4
4
  "description": "Qase JS Reporters",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",