qase-javascript-commons 2.2.16 → 2.2.17

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,10 @@
1
+ # qase-javascript-commons@2.2.17
2
+
3
+ ## What's new
4
+
5
+ - Logging of host system details to improve debugging and traceability.
6
+ - Output of installed packages in logs for better environment visibility.
7
+
1
8
  # qase-javascript-commons@2.2.16
2
9
 
3
10
  ## What's new
@@ -1,11 +1,13 @@
1
- export type HostData = {
1
+ export interface HostData {
2
2
  system: string;
3
- node: string;
3
+ machineName: string;
4
4
  release: string;
5
5
  version: string;
6
- machine: string;
7
- python: string;
8
- pip: string;
9
- node_version: string;
6
+ arch: string;
7
+ node: string;
10
8
  npm: string;
11
- };
9
+ framework: string;
10
+ reporter: string;
11
+ commons: string;
12
+ apiClient: string;
13
+ }
package/dist/qase.d.ts CHANGED
@@ -15,14 +15,6 @@ export interface ReporterInterface {
15
15
  */
16
16
  export declare class QaseReporter implements ReporterInterface {
17
17
  private static instance;
18
- /**
19
- * @param {string} frameworkPackage
20
- * @param {string} frameworkName
21
- * @param {string} reporterName
22
- * @returns {Record<string, string>}
23
- * @private
24
- */
25
- private static createHeaders;
26
18
  /**
27
19
  * @type {InternalReporterInterface}
28
20
  * @private
package/dist/qase.js CHANGED
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.QaseReporter = void 0;
7
- const child_process_1 = require("child_process");
8
7
  const env_schema_1 = __importDefault(require("env-schema"));
9
8
  const chalk_1 = __importDefault(require("chalk"));
10
9
  const qaseio_1 = require("qaseio");
@@ -13,11 +12,11 @@ const options_1 = require("./options");
13
12
  const env_1 = require("./env");
14
13
  const models_1 = require("./models");
15
14
  const writer_1 = require("./writer");
16
- const get_package_version_1 = require("./utils/get-package-version");
17
15
  const custom_boundary_1 = require("./utils/custom-boundary");
18
16
  const disabled_exception_1 = require("./utils/disabled-exception");
19
17
  const logger_1 = require("./utils/logger");
20
18
  const state_1 = require("./state/state");
19
+ const hostData_1 = require("./utils/hostData");
21
20
  /**
22
21
  * @type {Record<TestStatusEnum, (test: TestResultType) => string>}
23
22
  */
@@ -35,38 +34,6 @@ const resultLogMap = {
35
34
  */
36
35
  class QaseReporter {
37
36
  static instance;
38
- /**
39
- * @param {string} frameworkPackage
40
- * @param {string} frameworkName
41
- * @param {string} reporterName
42
- * @returns {Record<string, string>}
43
- * @private
44
- */
45
- static createHeaders(frameworkPackage, frameworkName, reporterName) {
46
- const { version: nodeVersion, platform: os, arch } = process;
47
- const npmVersion = (0, child_process_1.execSync)('npm -v', { encoding: 'utf8' }).replace(/['"\n]+/g, '');
48
- const qaseApiVersion = (0, get_package_version_1.getPackageVersion)('qaseio');
49
- const qaseReporterVersion = (0, get_package_version_1.getPackageVersion)('qase-javascript-commons');
50
- const frameworkVersion = (0, get_package_version_1.getPackageVersion)(frameworkPackage);
51
- const reporterVersion = (0, get_package_version_1.getPackageVersion)(reporterName);
52
- const client = [];
53
- if (frameworkVersion) {
54
- client.push(`${frameworkName}=${frameworkVersion}`);
55
- }
56
- if (reporterVersion) {
57
- client.push(`qase-${frameworkName}=${reporterVersion}`);
58
- }
59
- if (qaseReporterVersion) {
60
- client.push(`qase-core-reporter=${qaseReporterVersion}`);
61
- }
62
- if (qaseApiVersion) {
63
- client.push(`qaseio=${String(qaseApiVersion)}`);
64
- }
65
- return {
66
- 'X-Client': client.join('; '),
67
- 'X-Platform': `node=${nodeVersion}; npm=${npmVersion}; os=${os}; arch=${arch}`,
68
- };
69
- }
70
37
  /**
71
38
  * @type {InternalReporterInterface}
72
39
  * @private
@@ -117,6 +84,8 @@ class QaseReporter {
117
84
  this.options = composedOptions;
118
85
  this.logger = new logger_1.Logger({ debug: composedOptions.debug });
119
86
  this.logger.logDebug(`Config: ${JSON.stringify(this.sanitizeOptions(composedOptions))}`);
87
+ const hostData = (0, hostData_1.getHostInfo)(options.frameworkPackage, options.reporterName);
88
+ this.logger.logDebug(`Host data: ${JSON.stringify(hostData)}`);
120
89
  this.captureLogs = composedOptions.captureLogs;
121
90
  try {
122
91
  this.upstreamReporter = this.createReporter(
@@ -253,7 +222,6 @@ class QaseReporter {
253
222
  */
254
223
  startTestRun() {
255
224
  if (this.withState) {
256
- console.log("Clean state");
257
225
  state_1.StateManager.clearState();
258
226
  }
259
227
  if (!this.disabled) {
@@ -413,7 +381,7 @@ class QaseReporter {
413
381
  * @private
414
382
  */
415
383
  createReporter(mode, options) {
416
- const { frameworkPackage, frameworkName, reporterName, environment, rootSuite, report = {}, testops = {}, } = options;
384
+ const { frameworkPackage, reporterName, environment, rootSuite, report = {}, testops = {}, } = options;
417
385
  switch (mode) {
418
386
  case options_1.ModeEnum.testops: {
419
387
  const { api: { token, headers, ...api } = {}, project, run: { title, description, ...run } = {}, plan = {}, batch = {}, useV2, defect, uploadAttachments, } = testops;
@@ -427,7 +395,6 @@ class QaseReporter {
427
395
  token,
428
396
  headers: {
429
397
  ...headers,
430
- ...QaseReporter.createHeaders(frameworkPackage, frameworkName, reporterName),
431
398
  },
432
399
  ...api,
433
400
  }, custom_boundary_1.CustomBoundaryFormData);
@@ -448,7 +415,7 @@ class QaseReporter {
448
415
  case options_1.ModeEnum.report: {
449
416
  const localOptions = report.connections?.[writer_1.DriverEnum.local];
450
417
  const writer = new writer_1.FsWriter(localOptions);
451
- return new reporters_1.ReportReporter(this.logger, writer, environment, rootSuite, testops.run?.id);
418
+ return new reporters_1.ReportReporter(this.logger, writer, frameworkPackage, reporterName, environment, rootSuite, testops.run?.id);
452
419
  }
453
420
  case options_1.ModeEnum.off:
454
421
  throw new disabled_exception_1.DisabledException();
@@ -7,6 +7,8 @@ import { LoggerInterface } from '../utils/logger';
7
7
  */
8
8
  export declare class ReportReporter extends AbstractReporter {
9
9
  private writer;
10
+ private frameworkName;
11
+ private reporterName;
10
12
  private readonly environment;
11
13
  private readonly runId;
12
14
  private readonly rootSuite;
@@ -14,11 +16,13 @@ export declare class ReportReporter extends AbstractReporter {
14
16
  /**
15
17
  * @param {LoggerInterface} logger
16
18
  * @param {WriterInterface} writer
19
+ * @param {string} frameworkName
20
+ * @param {string} reporterName
17
21
  * @param {string | undefined} environment
18
22
  * @param {string | undefined} rootSuite
19
23
  * @param {number | undefined} runId
20
24
  */
21
- constructor(logger: LoggerInterface, writer: WriterInterface, environment?: string, rootSuite?: string, runId?: number);
25
+ constructor(logger: LoggerInterface, writer: WriterInterface, frameworkName: string, reporterName: string, environment?: string, rootSuite?: string, runId?: number);
22
26
  /**
23
27
  * @returns {Promise<void>}
24
28
  */
@@ -35,16 +39,4 @@ export declare class ReportReporter extends AbstractReporter {
35
39
  * @returns {TestStepType[]}
36
40
  */
37
41
  private copyStepAttachments;
38
- /**
39
- * @returns {HostData}
40
- */
41
- private getHostInfo;
42
- /**
43
- * @returns {string}
44
- */
45
- private getComputerName;
46
- /**
47
- * @returns {string}
48
- */
49
- private getDetailedOSInfo;
50
42
  }
@@ -1,40 +1,17 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.ReportReporter = void 0;
27
4
  const abstract_reporter_1 = require("./abstract-reporter");
28
5
  const models_1 = require("../models");
29
- const os = __importStar(require("os"));
30
- const cp = __importStar(require("child_process"));
31
- const process = __importStar(require("process"));
6
+ const hostData_1 = require("../utils/hostData");
32
7
  /**
33
8
  * @class ReportReporter
34
9
  * @extends AbstractReporter
35
10
  */
36
11
  class ReportReporter extends abstract_reporter_1.AbstractReporter {
37
12
  writer;
13
+ frameworkName;
14
+ reporterName;
38
15
  environment;
39
16
  runId;
40
17
  rootSuite;
@@ -42,13 +19,17 @@ class ReportReporter extends abstract_reporter_1.AbstractReporter {
42
19
  /**
43
20
  * @param {LoggerInterface} logger
44
21
  * @param {WriterInterface} writer
22
+ * @param {string} frameworkName
23
+ * @param {string} reporterName
45
24
  * @param {string | undefined} environment
46
25
  * @param {string | undefined} rootSuite
47
26
  * @param {number | undefined} runId
48
27
  */
49
- constructor(logger, writer, environment, rootSuite, runId) {
28
+ constructor(logger, writer, frameworkName, reporterName, environment, rootSuite, runId) {
50
29
  super(logger);
51
30
  this.writer = writer;
31
+ this.frameworkName = frameworkName;
32
+ this.reporterName = reporterName;
52
33
  this.environment = environment;
53
34
  this.runId = runId;
54
35
  this.rootSuite = rootSuite;
@@ -120,7 +101,7 @@ class ReportReporter extends abstract_reporter_1.AbstractReporter {
120
101
  threads: [],
121
102
  suites: [],
122
103
  environment: this.environment ?? '',
123
- host_data: this.getHostInfo(),
104
+ host_data: (0, hostData_1.getHostInfo)(this.frameworkName, this.reporterName),
124
105
  };
125
106
  for (const result of this.results) {
126
107
  report.stats.total++;
@@ -168,49 +149,5 @@ class ReportReporter extends abstract_reporter_1.AbstractReporter {
168
149
  }
169
150
  return steps;
170
151
  }
171
- /**
172
- * @returns {HostData}
173
- */
174
- getHostInfo() {
175
- return {
176
- system: process.platform,
177
- node: this.getComputerName(),
178
- release: os.release(),
179
- version: this.getDetailedOSInfo(),
180
- machine: os.arch(),
181
- python: '',
182
- pip: '',
183
- node_version: cp.execSync('node --version').toString().trim(),
184
- npm: cp.execSync('npm --version').toString().trim(),
185
- };
186
- }
187
- /**
188
- * @returns {string}
189
- */
190
- getComputerName() {
191
- switch (process.platform) {
192
- case 'win32':
193
- return process.env['COMPUTERNAME'] ?? '';
194
- case 'darwin':
195
- return cp.execSync('scutil --get ComputerName').toString().trim();
196
- case 'linux': {
197
- const prettyname = cp.execSync('hostnamectl --pretty').toString().trim();
198
- return prettyname === '' ? os.hostname() : prettyname;
199
- }
200
- default:
201
- return os.hostname();
202
- }
203
- }
204
- /**
205
- * @returns {string}
206
- */
207
- getDetailedOSInfo() {
208
- if (process.platform === 'darwin') {
209
- return cp.execSync('uname -a').toString().trim();
210
- }
211
- else {
212
- return `${os.type()} ${os.release()} ${os.arch()}`;
213
- }
214
- }
215
152
  }
216
153
  exports.ReportReporter = ReportReporter;
@@ -0,0 +1,8 @@
1
+ import { HostData } from '../models/host-data';
2
+ /**
3
+ * Gets information about the current host environment
4
+ * @param {string} framework The framework name to check version for
5
+ * @param {string} reporterName The reporter name to check version for
6
+ * @returns {HostData} Host information object
7
+ */
8
+ export declare function getHostInfo(framework: string, reporterName: string): HostData;
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getHostInfo = void 0;
27
+ const os = __importStar(require("os"));
28
+ const cp = __importStar(require("child_process"));
29
+ const fs = __importStar(require("fs"));
30
+ const path = __importStar(require("path"));
31
+ /**
32
+ * Gets detailed OS information based on the platform
33
+ * @returns {string} Detailed OS information
34
+ */
35
+ function getDetailedOSInfo() {
36
+ const platform = process.platform;
37
+ try {
38
+ if (platform === 'win32') {
39
+ // Windows
40
+ return cp.execSync('ver').toString().trim();
41
+ }
42
+ else if (platform === 'darwin') {
43
+ // macOS
44
+ return cp.execSync('sw_vers -productVersion').toString().trim();
45
+ }
46
+ else {
47
+ // Linux and others
48
+ try {
49
+ const osRelease = fs.readFileSync('/etc/os-release', 'utf8');
50
+ const prettyName = osRelease.match(/PRETTY_NAME="(.+)"/);
51
+ if (prettyName?.[1]) {
52
+ return prettyName[1];
53
+ }
54
+ }
55
+ catch {
56
+ // Fallback if /etc/os-release doesn't exist or can't be read
57
+ }
58
+ return os.release();
59
+ }
60
+ }
61
+ catch (error) {
62
+ console.error('Error getting detailed OS info:', error);
63
+ return os.release();
64
+ }
65
+ }
66
+ /**
67
+ * Executes a command and returns its trimmed output
68
+ * @param {string} command Command to execute
69
+ * @param {string} defaultValue Default value if command fails
70
+ * @returns {string} Command output or default value
71
+ */
72
+ function execCommand(command, defaultValue = '') {
73
+ try {
74
+ return cp.execSync(command).toString().trim();
75
+ }
76
+ catch (error) {
77
+ console.error(`Error executing command '${command}':`, error);
78
+ return defaultValue;
79
+ }
80
+ }
81
+ /**
82
+ * Recursively searches for a package in dependencies tree
83
+ * @param {Record<string, PackageInfo>} dependencies The dependencies object to search in
84
+ * @param {string} packageName The name of the package to find
85
+ * @returns {string | null} The package version or null if not found
86
+ */
87
+ function findPackageInDependencies(dependencies, packageName) {
88
+ // If no dependencies, return null
89
+ if (!dependencies)
90
+ return null;
91
+ // Check if the package exists at the current level
92
+ if (packageName in dependencies) {
93
+ return dependencies[packageName]?.version ?? null;
94
+ }
95
+ // Recursively search in nested dependencies
96
+ for (const dep of Object.values(dependencies)) {
97
+ if (dep.dependencies) {
98
+ const foundVersion = findPackageInDependencies(dep.dependencies, packageName);
99
+ if (foundVersion) {
100
+ return foundVersion;
101
+ }
102
+ }
103
+ }
104
+ return null;
105
+ }
106
+ /**
107
+ * Gets the version of a Node.js package
108
+ * @param {string} packageName The name of the package
109
+ * @returns {string | null} The package version or null if not found
110
+ */
111
+ function getPackageVersion(packageName) {
112
+ if (!packageName)
113
+ return null;
114
+ try {
115
+ // First try to get from node_modules
116
+ const packagePath = path.resolve(process.cwd(), 'node_modules', packageName, 'package.json');
117
+ if (fs.existsSync(packagePath)) {
118
+ const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
119
+ return packageJson.version;
120
+ }
121
+ // Try using npm list as fallback with recursive search
122
+ const output = execCommand(`npm list --depth=10 --json`);
123
+ if (!output)
124
+ return null;
125
+ try {
126
+ const npmList = JSON.parse(output);
127
+ // Try direct dependency
128
+ const directVersion = npmList.dependencies?.[packageName]?.version;
129
+ if (directVersion)
130
+ return directVersion;
131
+ // Try recursive search
132
+ return findPackageInDependencies(npmList.dependencies, packageName);
133
+ }
134
+ catch (parseError) {
135
+ console.error('Error parsing npm list output:', parseError);
136
+ return null;
137
+ }
138
+ }
139
+ catch (error) {
140
+ console.error(`Error getting version for package ${packageName}:`, error);
141
+ return null;
142
+ }
143
+ }
144
+ /**
145
+ * Gets information about the current host environment
146
+ * @param {string} framework The framework name to check version for
147
+ * @param {string} reporterName The reporter name to check version for
148
+ * @returns {HostData} Host information object
149
+ */
150
+ function getHostInfo(framework, reporterName) {
151
+ try {
152
+ return {
153
+ system: process.platform,
154
+ machineName: os.hostname(),
155
+ release: os.release(),
156
+ version: getDetailedOSInfo(),
157
+ arch: os.arch(),
158
+ node: execCommand('node --version'),
159
+ npm: execCommand('npm --version'),
160
+ framework: getPackageVersion(framework) ?? '',
161
+ reporter: getPackageVersion(reporterName) ?? '',
162
+ commons: getPackageVersion('qase-javascript-commons') ?? '',
163
+ apiClient: getPackageVersion('qaseio') ?? '',
164
+ };
165
+ }
166
+ catch (error) {
167
+ return {
168
+ system: process.platform,
169
+ machineName: os.hostname() || '',
170
+ release: os.release(),
171
+ version: '',
172
+ arch: os.arch(),
173
+ node: '',
174
+ npm: '',
175
+ framework: '',
176
+ reporter: '',
177
+ commons: '',
178
+ apiClient: '',
179
+ };
180
+ }
181
+ }
182
+ exports.getHostInfo = getHostInfo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qase-javascript-commons",
3
- "version": "2.2.16",
3
+ "version": "2.2.17",
4
4
  "description": "Qase JS Reporters",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",