@alternative-path/testlens-playwright-reporter 0.3.8 → 0.3.9
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/index.d.ts +5 -0
- package/index.js +52 -25
- package/index.ts +51 -25
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -157,6 +157,11 @@ export interface SpecData {
|
|
|
157
157
|
export declare class TestLensReporter implements Reporter {
|
|
158
158
|
private config;
|
|
159
159
|
private axiosInstance;
|
|
160
|
+
/**
|
|
161
|
+
* Automatically detect and load system CA certificates
|
|
162
|
+
* Uses Node.js built-in root certificates (works across all platforms)
|
|
163
|
+
*/
|
|
164
|
+
private static getSystemCaCertificates;
|
|
160
165
|
private runId;
|
|
161
166
|
private runMetadata;
|
|
162
167
|
private specMap;
|
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const os = tslib_1.__importStar(require("os"));
|
|
|
7
7
|
const path = tslib_1.__importStar(require("path"));
|
|
8
8
|
const fs = tslib_1.__importStar(require("fs"));
|
|
9
9
|
const https = tslib_1.__importStar(require("https"));
|
|
10
|
+
const tls = tslib_1.__importStar(require("tls"));
|
|
10
11
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
11
12
|
const child_process_1 = require("child_process");
|
|
12
13
|
// Lazy-load mime module to support ESM
|
|
@@ -22,23 +23,33 @@ async function getMime() {
|
|
|
22
23
|
class TestLensReporter {
|
|
23
24
|
/**
|
|
24
25
|
* Automatically detect and load system CA certificates
|
|
25
|
-
*
|
|
26
|
+
* Uses Node.js built-in root certificates (works across all platforms)
|
|
26
27
|
*/
|
|
27
28
|
static getSystemCaCertificates() {
|
|
28
|
-
|
|
29
|
+
// Use Node.js's built-in root certificates (available in Node.js 12.3.0+)
|
|
30
|
+
// This includes all common root CAs and works reliably across Windows, macOS, and Linux
|
|
31
|
+
try {
|
|
32
|
+
if (tls.rootCertificates && Array.isArray(tls.rootCertificates) && tls.rootCertificates.length > 0) {
|
|
33
|
+
// Convert string certificates to Buffer
|
|
34
|
+
const rootCerts = tls.rootCertificates.map(cert => Buffer.from(cert));
|
|
35
|
+
if (process.env.DEBUG) {
|
|
36
|
+
console.log(`✓ Using Node.js built-in root certificates (${rootCerts.length} certificates)`);
|
|
37
|
+
}
|
|
38
|
+
return rootCerts;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
// Fall through to file-based detection if tls.rootCertificates is not available
|
|
43
|
+
if (process.env.DEBUG) {
|
|
44
|
+
console.log('⚠️ Node.js built-in root certificates not available, trying file-based detection');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Fallback: Try to load from file system (for older Node.js versions or special cases)
|
|
29
48
|
const platform = os.platform();
|
|
30
|
-
|
|
49
|
+
const certificates = [];
|
|
50
|
+
// Fallback: Try to load certificates from common file system locations
|
|
31
51
|
const certPaths = [];
|
|
32
|
-
if (platform === '
|
|
33
|
-
// Windows: Node.js uses Windows certificate store automatically
|
|
34
|
-
// But we can also check common locations
|
|
35
|
-
const winPaths = [
|
|
36
|
-
process.env.CERT_PATH,
|
|
37
|
-
'C:\\Windows\\System32\\certmgr.msc', // Not a file, but indicates cert store
|
|
38
|
-
];
|
|
39
|
-
certPaths.push(...winPaths.filter(Boolean));
|
|
40
|
-
}
|
|
41
|
-
else if (platform === 'darwin') {
|
|
52
|
+
if (platform === 'darwin') {
|
|
42
53
|
// macOS: Common certificate locations
|
|
43
54
|
certPaths.push('/etc/ssl/cert.pem', '/usr/local/etc/openssl/cert.pem', '/opt/homebrew/etc/openssl/cert.pem', '/System/Library/OpenSSL/certs/cert.pem');
|
|
44
55
|
}
|
|
@@ -63,7 +74,9 @@ class TestLensReporter {
|
|
|
63
74
|
// This is expected as not all paths will exist on every system
|
|
64
75
|
}
|
|
65
76
|
}
|
|
66
|
-
|
|
77
|
+
// Return undefined if no certificates found (let Node.js use defaults)
|
|
78
|
+
// Return certificates array if we found any
|
|
79
|
+
return certificates.length > 0 ? certificates : undefined;
|
|
67
80
|
}
|
|
68
81
|
/**
|
|
69
82
|
* Parse custom metadata from environment variables
|
|
@@ -151,27 +164,34 @@ class TestLensReporter {
|
|
|
151
164
|
try {
|
|
152
165
|
if (fs.existsSync(this.config.caCertificate)) {
|
|
153
166
|
const customCert = fs.readFileSync(this.config.caCertificate);
|
|
154
|
-
// Combine system certs with custom cert
|
|
155
|
-
|
|
167
|
+
// Combine system certs with custom cert if system certs are available
|
|
168
|
+
if (systemCerts && Array.isArray(systemCerts) && systemCerts.length > 0) {
|
|
169
|
+
ca = [...systemCerts, customCert];
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
ca = customCert;
|
|
173
|
+
}
|
|
156
174
|
console.log(`✓ Using custom CA certificate: ${this.config.caCertificate}`);
|
|
157
175
|
}
|
|
158
176
|
else {
|
|
159
177
|
console.warn(`⚠️ CA certificate file not found: ${this.config.caCertificate}`);
|
|
160
178
|
// Fall back to system certs if custom cert not found
|
|
161
|
-
ca = systemCerts
|
|
179
|
+
ca = systemCerts || undefined;
|
|
162
180
|
}
|
|
163
181
|
}
|
|
164
182
|
catch (error) {
|
|
165
183
|
console.warn(`⚠️ Failed to read CA certificate file: ${this.config.caCertificate}`, error.message);
|
|
166
184
|
// Fall back to system certs if custom cert read fails
|
|
167
|
-
ca = systemCerts
|
|
185
|
+
ca = systemCerts || undefined;
|
|
168
186
|
}
|
|
169
187
|
}
|
|
170
188
|
else {
|
|
171
189
|
// Use automatically detected system certificates
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
|
|
190
|
+
// On Windows, systemCerts will be undefined to let Node.js use Windows certificate store
|
|
191
|
+
// On Unix systems, systemCerts will contain certificates or be undefined
|
|
192
|
+
ca = systemCerts;
|
|
193
|
+
// If ca is undefined, Node.js will use its default certificate store
|
|
194
|
+
// This is the correct behavior, especially on Windows
|
|
175
195
|
}
|
|
176
196
|
// Check various ways SSL validation can be disabled (in order of precedence)
|
|
177
197
|
if (this.config.ignoreSslErrors) {
|
|
@@ -196,10 +216,17 @@ class TestLensReporter {
|
|
|
196
216
|
minVersion: 'TLSv1.2',
|
|
197
217
|
maxVersion: 'TLSv1.3'
|
|
198
218
|
};
|
|
199
|
-
// Add CA certificates if available
|
|
200
|
-
//
|
|
201
|
-
|
|
202
|
-
|
|
219
|
+
// Add CA certificates if available
|
|
220
|
+
// On Windows, ca will be undefined to let Node.js use Windows certificate store automatically
|
|
221
|
+
// On Unix systems, ca will contain certificates if found, or undefined to use Node.js defaults
|
|
222
|
+
if (ca !== undefined) {
|
|
223
|
+
if (Array.isArray(ca) && ca.length > 0) {
|
|
224
|
+
httpsAgentOptions.ca = ca;
|
|
225
|
+
}
|
|
226
|
+
else if (typeof ca === 'string' || Buffer.isBuffer(ca)) {
|
|
227
|
+
httpsAgentOptions.ca = ca;
|
|
228
|
+
}
|
|
229
|
+
// If ca is undefined, we don't set it, allowing Node.js to use its default certificate store
|
|
203
230
|
}
|
|
204
231
|
this.axiosInstance = axios_1.default.create({
|
|
205
232
|
baseURL: this.config.apiEndpoint,
|
package/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as os from 'os';
|
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import * as fs from 'fs';
|
|
5
5
|
import * as https from 'https';
|
|
6
|
+
import * as tls from 'tls';
|
|
6
7
|
import axios, { AxiosInstance } from 'axios';
|
|
7
8
|
import type { Reporter, TestCase, TestResult, FullConfig, Suite } from '@playwright/test/reporter';
|
|
8
9
|
import { execSync } from 'child_process';
|
|
@@ -185,24 +186,35 @@ export class TestLensReporter implements Reporter {
|
|
|
185
186
|
|
|
186
187
|
/**
|
|
187
188
|
* Automatically detect and load system CA certificates
|
|
188
|
-
*
|
|
189
|
+
* Uses Node.js built-in root certificates (works across all platforms)
|
|
189
190
|
*/
|
|
190
|
-
private static getSystemCaCertificates(): Buffer[] {
|
|
191
|
-
|
|
191
|
+
private static getSystemCaCertificates(): Buffer[] | undefined {
|
|
192
|
+
// Use Node.js's built-in root certificates (available in Node.js 12.3.0+)
|
|
193
|
+
// This includes all common root CAs and works reliably across Windows, macOS, and Linux
|
|
194
|
+
try {
|
|
195
|
+
if (tls.rootCertificates && Array.isArray(tls.rootCertificates) && tls.rootCertificates.length > 0) {
|
|
196
|
+
// Convert string certificates to Buffer
|
|
197
|
+
const rootCerts = tls.rootCertificates.map(cert => Buffer.from(cert));
|
|
198
|
+
if (process.env.DEBUG) {
|
|
199
|
+
console.log(`✓ Using Node.js built-in root certificates (${rootCerts.length} certificates)`);
|
|
200
|
+
}
|
|
201
|
+
return rootCerts;
|
|
202
|
+
}
|
|
203
|
+
} catch (error) {
|
|
204
|
+
// Fall through to file-based detection if tls.rootCertificates is not available
|
|
205
|
+
if (process.env.DEBUG) {
|
|
206
|
+
console.log('⚠️ Node.js built-in root certificates not available, trying file-based detection');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Fallback: Try to load from file system (for older Node.js versions or special cases)
|
|
192
211
|
const platform = os.platform();
|
|
212
|
+
const certificates: Buffer[] = [];
|
|
193
213
|
|
|
194
|
-
//
|
|
214
|
+
// Fallback: Try to load certificates from common file system locations
|
|
195
215
|
const certPaths: string[] = [];
|
|
196
216
|
|
|
197
|
-
if (platform === '
|
|
198
|
-
// Windows: Node.js uses Windows certificate store automatically
|
|
199
|
-
// But we can also check common locations
|
|
200
|
-
const winPaths = [
|
|
201
|
-
process.env.CERT_PATH,
|
|
202
|
-
'C:\\Windows\\System32\\certmgr.msc', // Not a file, but indicates cert store
|
|
203
|
-
];
|
|
204
|
-
certPaths.push(...winPaths.filter(Boolean) as string[]);
|
|
205
|
-
} else if (platform === 'darwin') {
|
|
217
|
+
if (platform === 'darwin') {
|
|
206
218
|
// macOS: Common certificate locations
|
|
207
219
|
certPaths.push(
|
|
208
220
|
'/etc/ssl/cert.pem',
|
|
@@ -240,7 +252,9 @@ export class TestLensReporter implements Reporter {
|
|
|
240
252
|
}
|
|
241
253
|
}
|
|
242
254
|
|
|
243
|
-
|
|
255
|
+
// Return undefined if no certificates found (let Node.js use defaults)
|
|
256
|
+
// Return certificates array if we found any
|
|
257
|
+
return certificates.length > 0 ? certificates : undefined;
|
|
244
258
|
}
|
|
245
259
|
private runId: string;
|
|
246
260
|
private runMetadata: RunMetadata;
|
|
@@ -343,24 +357,30 @@ export class TestLensReporter implements Reporter {
|
|
|
343
357
|
try {
|
|
344
358
|
if (fs.existsSync(this.config.caCertificate)) {
|
|
345
359
|
const customCert = fs.readFileSync(this.config.caCertificate);
|
|
346
|
-
// Combine system certs with custom cert
|
|
347
|
-
|
|
360
|
+
// Combine system certs with custom cert if system certs are available
|
|
361
|
+
if (systemCerts && Array.isArray(systemCerts) && systemCerts.length > 0) {
|
|
362
|
+
ca = [...systemCerts, customCert];
|
|
363
|
+
} else {
|
|
364
|
+
ca = customCert;
|
|
365
|
+
}
|
|
348
366
|
console.log(`✓ Using custom CA certificate: ${this.config.caCertificate}`);
|
|
349
367
|
} else {
|
|
350
368
|
console.warn(`⚠️ CA certificate file not found: ${this.config.caCertificate}`);
|
|
351
369
|
// Fall back to system certs if custom cert not found
|
|
352
|
-
ca = systemCerts
|
|
370
|
+
ca = systemCerts || undefined;
|
|
353
371
|
}
|
|
354
372
|
} catch (error) {
|
|
355
373
|
console.warn(`⚠️ Failed to read CA certificate file: ${this.config.caCertificate}`, (error as Error).message);
|
|
356
374
|
// Fall back to system certs if custom cert read fails
|
|
357
|
-
ca = systemCerts
|
|
375
|
+
ca = systemCerts || undefined;
|
|
358
376
|
}
|
|
359
377
|
} else {
|
|
360
378
|
// Use automatically detected system certificates
|
|
361
|
-
|
|
362
|
-
//
|
|
363
|
-
|
|
379
|
+
// On Windows, systemCerts will be undefined to let Node.js use Windows certificate store
|
|
380
|
+
// On Unix systems, systemCerts will contain certificates or be undefined
|
|
381
|
+
ca = systemCerts;
|
|
382
|
+
// If ca is undefined, Node.js will use its default certificate store
|
|
383
|
+
// This is the correct behavior, especially on Windows
|
|
364
384
|
}
|
|
365
385
|
|
|
366
386
|
// Check various ways SSL validation can be disabled (in order of precedence)
|
|
@@ -386,10 +406,16 @@ export class TestLensReporter implements Reporter {
|
|
|
386
406
|
maxVersion: 'TLSv1.3'
|
|
387
407
|
};
|
|
388
408
|
|
|
389
|
-
// Add CA certificates if available
|
|
390
|
-
//
|
|
391
|
-
|
|
392
|
-
|
|
409
|
+
// Add CA certificates if available
|
|
410
|
+
// On Windows, ca will be undefined to let Node.js use Windows certificate store automatically
|
|
411
|
+
// On Unix systems, ca will contain certificates if found, or undefined to use Node.js defaults
|
|
412
|
+
if (ca !== undefined) {
|
|
413
|
+
if (Array.isArray(ca) && ca.length > 0) {
|
|
414
|
+
httpsAgentOptions.ca = ca;
|
|
415
|
+
} else if (typeof ca === 'string' || Buffer.isBuffer(ca)) {
|
|
416
|
+
httpsAgentOptions.ca = ca;
|
|
417
|
+
}
|
|
418
|
+
// If ca is undefined, we don't set it, allowing Node.js to use its default certificate store
|
|
393
419
|
}
|
|
394
420
|
|
|
395
421
|
this.axiosInstance = axios.create({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alternative-path/testlens-playwright-reporter",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "Universal Playwright reporter for TestLens - works with both TypeScript and JavaScript projects",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|