@9l/playwright 0.1.2 → 0.2.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.
package/README.md CHANGED
@@ -10,13 +10,13 @@ completing does not verify that behavior.
10
10
  Published on [npm](https://www.npmjs.com/package/@9l/playwright):
11
11
 
12
12
  ```sh
13
- npm install --save-dev @9l/playwright@0.1.2 @playwright/test@1.64.0
13
+ npm install --save-dev @9l/playwright@0.2.0 @playwright/test@1.64.0
14
14
  npm exec playwright install chromium
15
15
  ```
16
16
 
17
17
  Use Node 24 for the qualified runtime (Node 22 minimum), Playwright 1.61.1
18
- through 1.64.0, and Chromium. macOS and Linux on amd64/arm64 are the qualified
19
- runner targets. The peer range is `@playwright/test` `>=1.61.1 <2`; CI qualifies
18
+ through 1.64.0, and Chromium. macOS, Linux and Windows on amd64/arm64 are the
19
+ qualified runner targets (Windows from CLI 0.2.0). The peer range is `@playwright/test` `>=1.61.1 <2`; CI qualifies
20
20
  every published release from 1.61.1 through 1.64.0 (1.61.1, 1.62.0, 1.62.1,
21
21
  1.63.0 and 1.64.0). Later versions, and other browser engines, install but are
22
22
  unqualified.
package/dist/prove.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { BrowserContext, Request } from '@playwright/test';
2
2
  export declare const proveProtocol = "9l.prove/1";
3
- export declare const faultKinds: readonly ["abort", "http-500", "empty-json"];
3
+ export declare const faultKinds: readonly ["abort", "http-500", "empty-json", "http-401", "http-403", "http-429", "malformed-json"];
4
4
  export type FaultKind = typeof faultKinds[number];
5
5
  export type Target = {
6
6
  method: string;
@@ -27,4 +27,5 @@ export declare function openProveChannel(env: NodeJS.ProcessEnv, testInfo: {
27
27
  testId: string;
28
28
  retry: number;
29
29
  }): ProveChannel | undefined;
30
+ export declare function replaceJSON(kind: 'empty-json' | 'malformed-json', text: string): string | undefined;
30
31
  export declare function instrument(context: BrowserContext, channel: ProveChannel): Promise<void>;
package/dist/prove.js CHANGED
@@ -5,6 +5,7 @@ exports.requestTarget = requestTarget;
5
5
  exports.matches = matches;
6
6
  exports.readFault = readFault;
7
7
  exports.openProveChannel = openProveChannel;
8
+ exports.replaceJSON = replaceJSON;
8
9
  exports.instrument = instrument;
9
10
  const node_crypto_1 = require("node:crypto");
10
11
  const node_fs_1 = require("node:fs");
@@ -16,7 +17,8 @@ const protocol_1 = require("./protocol");
16
17
  // Records go to a private per-test file that Go names and removes. They never
17
18
  // enter the 9l.engine/1 stream, whose metadata excludes URLs by design.
18
19
  exports.proveProtocol = '9l.prove/1';
19
- exports.faultKinds = ['abort', 'http-500', 'empty-json'];
20
+ // Must match prove.Kinds in internal/prove/prove.go.
21
+ exports.faultKinds = ['abort', 'http-500', 'empty-json', 'http-401', 'http-403', 'http-429', 'malformed-json'];
20
22
  const maxRecords = 2000;
21
23
  const maxRecordBytes = 4096;
22
24
  const maxPathBytes = 2048;
@@ -115,9 +117,22 @@ function openProveChannel(env, testInfo) {
115
117
  // reporter uses, so Go can judge each test separately and notice retries.
116
118
  const testId = (0, node_crypto_1.createHash)('sha256').update(testInfo.testId).digest('hex');
117
119
  channel.record({ type: 'hello', protocol: exports.proveProtocol, mode: fault ? 'fault' : 'observe', testId, retry: testInfo.retry });
120
+ // Only an engine that asks gets this record: an older one rejects records
121
+ // outside its schema. It tells Go which kinds this build can apply.
122
+ if (!fault && env.NINELIVES_PROVE_CAPABILITIES === '1')
123
+ channel.record({ type: 'capabilities', faults: [...exports.faultKinds] });
118
124
  return channel;
119
125
  }
120
- function emptyLike(text) {
126
+ const statusFaults = {
127
+ 'http-500': { status: 500 },
128
+ 'http-401': { status: 401 },
129
+ 'http-403': { status: 403 },
130
+ 'http-429': { status: 429, headers: { 'retry-after': '1' } },
131
+ };
132
+ // The replacement body for a JSON object or array, or undefined when the
133
+ // response is neither. malformed-json keeps the first half of the trimmed
134
+ // text: any proper prefix of an object or array leaves a bracket unclosed.
135
+ function replaceJSON(kind, text) {
121
136
  let value;
122
137
  try {
123
138
  value = JSON.parse(text);
@@ -125,9 +140,12 @@ function emptyLike(text) {
125
140
  catch {
126
141
  return undefined;
127
142
  }
128
- if (Array.isArray(value))
129
- return '[]';
130
- return value !== null && typeof value === 'object' ? '{}' : undefined;
143
+ if (value === null || typeof value !== 'object')
144
+ return undefined;
145
+ if (kind === 'empty-json')
146
+ return Array.isArray(value) ? '[]' : '{}';
147
+ const trimmed = text.trim();
148
+ return trimmed.slice(0, Math.max(1, Math.floor(trimmed.length / 2)));
131
149
  }
132
150
  function isJSON(contentType) {
133
151
  const media = (contentType ?? '').split(';')[0].trim().toLowerCase();
@@ -159,11 +177,13 @@ async function instrument(context, channel) {
159
177
  const applied = () => channel.record({ type: 'applied', fault: fault.id });
160
178
  if (fault.kind === 'abort')
161
179
  return route.abort('failed').then(applied);
162
- if (fault.kind === 'http-500')
163
- return route.fulfill({ status: 500, body: '' }).then(applied);
164
- // empty-json needs the real response first; say why when it cannot be
165
- // replaced: the upstream was unreachable, or the body was not an object
166
- // or array.
180
+ const status = statusFaults[fault.kind];
181
+ if (status)
182
+ return route.fulfill({ ...status, body: '' }).then(applied);
183
+ const kind = fault.kind;
184
+ // The JSON faults need the real response first; say why when it cannot
185
+ // be replaced: the upstream was unreachable, or the body was not an
186
+ // object or array.
167
187
  let response;
168
188
  try {
169
189
  response = await route.fetch();
@@ -172,11 +192,11 @@ async function instrument(context, channel) {
172
192
  channel.record({ type: 'not-applicable', fault: fault.id, reason: 'unreachable' });
173
193
  return route.continue().catch(() => { });
174
194
  }
175
- const empty = emptyLike(await response.text().catch(() => ''));
176
- if (empty === undefined) {
195
+ const body = replaceJSON(kind, await response.text().catch(() => ''));
196
+ if (body === undefined) {
177
197
  channel.record({ type: 'not-applicable', fault: fault.id, reason: 'not-json' });
178
198
  return route.fulfill({ response });
179
199
  }
180
- return route.fulfill({ response, body: empty }).then(applied);
200
+ return route.fulfill({ response, body }).then(applied);
181
201
  });
182
202
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@9l/playwright",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Playwright fixtures and the versioned 9lives Go engine bridge",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/Quality-Max/9lives-runner#local-playwright-sdk",