@andrii_kremlovskyi/playwright-traces-reader 2.7.0 → 4.1.0

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.
@@ -0,0 +1,160 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.InconsistentTraceVersionError = exports.UnsupportedTraceVersionError = exports.MAX_SUPPORTED_TRACE_VERSION = void 0;
37
+ exports.assertSupportedTraceVersion = assertSupportedTraceVersion;
38
+ exports.inspectTraceCompatibility = inspectTraceCompatibility;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ const ndjson_1 = require("./ndjson");
42
+ exports.MAX_SUPPORTED_TRACE_VERSION = 8;
43
+ class UnsupportedTraceVersionError extends Error {
44
+ constructor(traceVersion, maxSupportedVersion) {
45
+ super(`Trace schema version ${traceVersion} is newer than the maximum supported version ${maxSupportedVersion}. Update playwright-traces-reader before parsing this trace.`);
46
+ this.traceVersion = traceVersion;
47
+ this.maxSupportedVersion = maxSupportedVersion;
48
+ this.name = 'UnsupportedTraceVersionError';
49
+ }
50
+ }
51
+ exports.UnsupportedTraceVersionError = UnsupportedTraceVersionError;
52
+ class InconsistentTraceVersionError extends Error {
53
+ constructor(traceVersions) {
54
+ super(`Trace contains inconsistent schema versions: ${traceVersions.join(', ')}.`);
55
+ this.traceVersions = traceVersions;
56
+ this.name = 'InconsistentTraceVersionError';
57
+ }
58
+ }
59
+ exports.InconsistentTraceVersionError = InconsistentTraceVersionError;
60
+ function increment(counts, key) {
61
+ counts.set(key, (counts.get(key) ?? 0) + 1);
62
+ }
63
+ function sortedRecord(counts) {
64
+ return Object.fromEntries([...counts].sort(([left], [right]) => left.localeCompare(right)));
65
+ }
66
+ function collectResourceReferences(value, key, result) {
67
+ if (typeof value === 'string') {
68
+ if ((key === 'sha1' || key === '_sha1') && value)
69
+ result.add(value);
70
+ return;
71
+ }
72
+ if (Array.isArray(value)) {
73
+ for (const item of value)
74
+ collectResourceReferences(item, null, result);
75
+ return;
76
+ }
77
+ if (!value || typeof value !== 'object')
78
+ return;
79
+ for (const [childKey, childValue] of Object.entries(value))
80
+ collectResourceReferences(childValue, childKey, result);
81
+ }
82
+ function assertVersions(traceVersions) {
83
+ const versions = [...traceVersions].sort((left, right) => left - right);
84
+ if (versions.length > 1)
85
+ throw new InconsistentTraceVersionError(versions);
86
+ if (versions[0] !== undefined && versions[0] > exports.MAX_SUPPORTED_TRACE_VERSION)
87
+ throw new UnsupportedTraceVersionError(versions[0], exports.MAX_SUPPORTED_TRACE_VERSION);
88
+ }
89
+ async function assertSupportedTraceVersion(traceDir) {
90
+ const entries = await fs.promises.readdir(traceDir, { withFileTypes: true });
91
+ const traceFiles = entries
92
+ .filter(entry => entry.isFile() && entry.name.endsWith('.trace') && entry.name !== 'test.trace')
93
+ .map(entry => entry.name)
94
+ .sort();
95
+ const traceVersions = new Set();
96
+ for (const traceFile of traceFiles) {
97
+ for await (const event of (0, ndjson_1.readNdjson)(path.join(traceDir, traceFile))) {
98
+ if (event.type !== 'context-options')
99
+ continue;
100
+ if (typeof event.version === 'number')
101
+ traceVersions.add(event.version);
102
+ break;
103
+ }
104
+ }
105
+ assertVersions(traceVersions);
106
+ }
107
+ async function inspectTraceCompatibility(traceContext) {
108
+ const entries = await fs.promises.readdir(traceContext.traceDir, { withFileTypes: true });
109
+ const eventFiles = entries
110
+ .filter(entry => entry.isFile() && (entry.name.endsWith('.trace') || entry.name.endsWith('.network')))
111
+ .map(entry => entry.name)
112
+ .sort();
113
+ const traceVersions = new Set();
114
+ const playwrightVersions = new Set();
115
+ const referencedResources = new Set();
116
+ const allEventTypes = new Map();
117
+ const files = [];
118
+ for (const eventFile of eventFiles) {
119
+ const eventTypes = new Map();
120
+ let eventCount = 0;
121
+ for await (const event of (0, ndjson_1.readNdjson)(path.join(traceContext.traceDir, eventFile))) {
122
+ eventCount += 1;
123
+ const eventType = typeof event.type === 'string' ? event.type : '<missing>';
124
+ increment(eventTypes, eventType);
125
+ increment(allEventTypes, eventType);
126
+ collectResourceReferences(event, null, referencedResources);
127
+ if (event.type === 'context-options') {
128
+ if (typeof event.version === 'number')
129
+ traceVersions.add(event.version);
130
+ if (typeof event.playwrightVersion === 'string')
131
+ playwrightVersions.add(event.playwrightVersion);
132
+ }
133
+ }
134
+ files.push({ file: eventFile, eventCount, eventTypes: sortedRecord(eventTypes) });
135
+ }
136
+ assertVersions(traceVersions);
137
+ const resourcesDir = path.join(traceContext.traceDir, 'resources');
138
+ const resourceNames = fs.existsSync(resourcesDir)
139
+ ? new Set(await fs.promises.readdir(resourcesDir))
140
+ : new Set();
141
+ const references = [...referencedResources].sort();
142
+ const missingResources = references.filter(reference => {
143
+ if (resourceNames.has(reference))
144
+ return false;
145
+ if (reference.endsWith('.bin') && resourceNames.has(reference.slice(0, -4)))
146
+ return false;
147
+ return true;
148
+ });
149
+ const versions = [...traceVersions];
150
+ return {
151
+ traceDir: traceContext.traceDir,
152
+ traceVersion: versions[0] ?? null,
153
+ playwrightVersions: [...playwrightVersions].sort(),
154
+ files,
155
+ eventTypes: sortedRecord(allEventTypes),
156
+ referencedResources: references,
157
+ missingResources,
158
+ };
159
+ }
160
+ //# sourceMappingURL=traceCompatibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traceCompatibility.js","sourceRoot":"","sources":["../src/traceCompatibility.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,kEAmBC;AAED,8DAyDC;AAhKD,uCAAyB;AACzB,2CAA6B;AAC7B,qCAAsC;AAGzB,QAAA,2BAA2B,GAAG,CAAC,CAAC;AAwB7C,MAAa,4BAA6B,SAAQ,KAAK;IACrD,YACkB,YAAoB,EACpB,mBAA2B;QAE3C,KAAK,CAAC,wBAAwB,YAAY,gDAAgD,mBAAmB,8DAA8D,CAAC,CAAC;QAH7J,iBAAY,GAAZ,YAAY,CAAQ;QACpB,wBAAmB,GAAnB,mBAAmB,CAAQ;QAG3C,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC7C,CAAC;CACF;AARD,oEAQC;AAED,MAAa,6BAA8B,SAAQ,KAAK;IACtD,YAA4B,aAAuB;QACjD,KAAK,CAAC,gDAAgD,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QADzD,kBAAa,GAAb,aAAa,CAAU;QAEjD,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;IAC9C,CAAC;CACF;AALD,sEAKC;AAED,SAAS,SAAS,CAAC,MAA2B,EAAE,GAAW;IACzD,MAAM,CAAC,GAAG,CAAC,GAAG,EAA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ACH,MAAM,QAAQ,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC;IAEpC,OAAO;QACL,QAAQ,EAAE,YAAY,CAAC,QAAQ;QAC/B,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI;QACjC,kBAAkB,EAAE,CAAC,GAAG,kBAAkB,CAAC,CAAC,IAAI,EAAE;QAClD,KAAK;QACL,UAAU,EAAE,YAAY,CAAC,aAAa,CAAC;QACvC,mBAAmB,EAAE,UAAU;QAC/B,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrii_kremlovskyi/playwright-traces-reader",
3
- "version": "2.7.0",
3
+ "version": "4.1.0",
4
4
  "description": "Parse Playwright trace files into structured data for AI agents and tooling",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,7 +14,12 @@
14
14
  "scripts": {
15
15
  "build": "tsc",
16
16
  "prepublishOnly": "npm run build",
17
- "test": "jest"
17
+ "test": "npm run test:unit",
18
+ "test:unit": "jest tests/cli.test.ts tests/hubCli.test.ts tests/parseTrace.test.ts tests/sanity.test.ts tests/traceCache.test.ts",
19
+ "test:real-fixture": "npm run build && jest --runInBand tests/realReportCompatibility.test.ts",
20
+ "test:all": "npm run test:unit && npm run test:real-fixture",
21
+ "compatibility:generate": "tsx scripts/generateCompatibilityReport.ts",
22
+ "compatibility:run": "npm run build && jest --runInBand tests/realReportCompatibility.test.ts"
18
23
  },
19
24
  "keywords": [
20
25
  "playwright",
@@ -58,6 +63,7 @@
58
63
  "tsconfig": {
59
64
  "module": "Node16",
60
65
  "moduleResolution": "Node16",
66
+ "isolatedModules": true,
61
67
  "esModuleInterop": true,
62
68
  "types": [
63
69
  "node",