@checksum-ai/runtime 4.16.2-beta.1 → 4.16.3

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 CHANGED
@@ -11,7 +11,6 @@ import {
11
11
  Dialog,
12
12
  } from "@playwright/test";
13
13
 
14
- // import { ExpectWrapper } from "./index.helpers";
15
14
  interface ChecksumAIMethod {
16
15
  (title: string): IChecksumPage;
17
16
  <T>(
@@ -110,7 +109,6 @@ export interface CompoundSelectionInterface {
110
109
  * target?: (base) => base.locator("<relative selector to target element>")
111
110
  * }).first().click();
112
111
  * ```
113
- * @param selection
114
112
  * @returns Locator to the common parent(s) or the target element(s) if specified.
115
113
  */
116
114
  compoundSelection(selection: {
package/package.json CHANGED
@@ -45,5 +45,5 @@
45
45
  "url": "https://github.com/checksum-ai/checksum-ai-monorepo/issues"
46
46
  },
47
47
  "homepage": "https://github.com/checksum-ai/checksum-ai-monorepo/tree/main/packages/runtime#readme",
48
- "version": "4.16.2-beta.1"
48
+ "version": "4.16.3"
49
49
  }
package/scripts/patch.js CHANGED
@@ -11,8 +11,6 @@ const availablePatchVersions = fs
11
11
  .map((patchFile) => path.basename(patchFile, ".js"))
12
12
  .sort();
13
13
 
14
- // console.log("patchVersions", availablePatchVersions);
15
-
16
14
  function findSuitablePatchVersion(version) {
17
15
  let suitablePatchVersion = availablePatchVersions[0];
18
16
  for (const patchVersion of availablePatchVersions) {
@@ -39,20 +37,12 @@ for (const projectPath of projectPaths) {
39
37
  const packageJSON = require(absolutePathToPackageJSON);
40
38
  const playwrightVersion = packageJSON.version;
41
39
  const patchVersion = findSuitablePatchVersion(playwrightVersion);
42
- // console.log(
43
- // "Found installed version",
44
- // playwrightVersion,
45
- // "and will use patch for version",
46
- // patchVersion
47
- // );
48
40
  const patchPath = resolve(
49
41
  join(getPlaywrightPatchesDirectory(), `${patchVersion}.js`)
50
42
  );
51
43
  require(patchPath)(projectPath);
52
- } else {
53
- // console.warn("Project path not found", projectPath);
54
44
  }
55
45
  } catch (e) {
56
- // ignore for now although we might want to notify users that patching wasn't successful
46
+ // Patching is best-effort: a failure here must not block the install.
57
47
  }
58
48
  }
@@ -1,52 +1,41 @@
1
1
  const fs = require("fs");
2
2
  const { join } = require("path");
3
3
 
4
- // Args
5
4
  const on = process.argv[2] !== "off";
6
5
 
7
- // -------- [Modifiers] -------- //
8
-
9
- // Amends the file with the given entry point text and append text
10
- // When "on" is true, the append text is added to the entry point,
11
- // otherwise the append text is completely removed from the file
6
+ // When `on`, appendText is spliced in after entryPointText; when off, it is
7
+ // stripped back out. Leaves no marker, so an amend cannot be detected later.
12
8
  function amend(filePath, entryPointText, appendText) {
13
9
  const data = fs.readFileSync(filePath, "utf8");
14
10
  if (!data.includes(entryPointText)) {
15
11
  throw new Error("Entry point not found!", entryPointText);
16
12
  }
17
- // Ignore if the append text is already present
18
13
  if (on && data.includes(appendText)) {
19
14
  return;
20
15
  }
21
- // Add or clear according to on state
22
16
  const result = on
23
17
  ? data.replace(entryPointText, entryPointText + appendText)
24
18
  : data.replace(appendText, "");
25
19
 
26
- // Write
27
20
  fs.writeFileSync(filePath, result, "utf8");
28
21
  }
29
22
 
30
- // Replaces content.
31
- // When "on" is true, the new content is written to the file replacing the original content,
32
- // otherwise the original content is restored.
23
+ // When `on`, newContent replaces originalContent; when off, the original is
24
+ // restored. The `/* checksumai */` prefix is the marker that makes the off
25
+ // direction findable.
33
26
  function replaceContent(filePath, originalContent, newContent) {
34
- // Read the file content
35
27
  const fileContent = fs.readFileSync(filePath, "utf8");
36
28
 
37
- // add a marker for newContent that can be later recognized for "off" state
38
29
  newContent = `/* checksumai */ ${newContent}`;
39
30
 
40
31
  if (on && fileContent.includes(newContent)) {
41
32
  return;
42
33
  }
43
34
 
44
- // Join the lines back into a single string
45
35
  const updatedContent = on
46
36
  ? fileContent.replace(originalContent, newContent)
47
37
  : fileContent.replace(newContent, originalContent);
48
38
 
49
- // Write the modified content back to the file
50
39
  fs.writeFileSync(filePath, updatedContent, "utf8");
51
40
  }
52
41
 
@@ -58,9 +47,6 @@ function doesFileExist(filePath) {
58
47
  return true;
59
48
  }
60
49
 
61
- // -------- [Modifications] -------- //
62
-
63
- // Remove conditions for injecting Playwright scripts
64
50
  function alwaysInjectScripts(projectRoot) {
65
51
  const file = join(
66
52
  projectRoot,
@@ -78,7 +64,6 @@ function alwaysInjectScripts(projectRoot) {
78
64
  replaceContent(file, originalContent, newContent);
79
65
  }
80
66
 
81
- // Add implementation for generateSelectorAndLocator and inject to Playwright console API
82
67
  function addGenerateSelectorAndLocator(projectRoot) {
83
68
  const file = join(
84
69
  projectRoot,
@@ -99,8 +84,6 @@ function addGenerateSelectorAndLocator(projectRoot) {
99
84
  amend(file, entryPointText2, appendText2);
100
85
  }
101
86
 
102
- // -------- [Runtime modifications] -------- //
103
-
104
87
  function expect(projectRoot) {
105
88
  const file = join(
106
89
  projectRoot,
@@ -216,12 +199,18 @@ function testType(projectRoot) {
216
199
  }
217
200
 
218
201
  function indexContent(projectRoot) {
219
- const file = join(projectRoot, "node_modules", "playwright", "lib", "index.js")
202
+ const file = join(
203
+ projectRoot,
204
+ "node_modules",
205
+ "playwright",
206
+ "lib",
207
+ "index.js"
208
+ );
220
209
  if (!doesFileExist) {
221
210
  return;
222
211
  }
223
212
  let originalContent, newContent;
224
- originalContent = `const browser = await playwright[browserName].launch();`
213
+ originalContent = `const browser = await playwright[browserName].launch();`;
225
214
  newContent = `
226
215
  let browser = playwright[browserName];
227
216
  try {
@@ -250,8 +239,8 @@ function indexContent(projectRoot) {
250
239
  );
251
240
  }
252
241
  browser = await browser.launch();
253
- `
254
- replaceContent(file, originalContent, newContent)
242
+ `;
243
+ replaceContent(file, originalContent, newContent);
255
244
  }
256
245
 
257
246
  function channelOwner(projectRoot) {
@@ -283,8 +272,6 @@ function channelOwner(projectRoot) {
283
272
  amend(file, entryPointText, appendText);
284
273
  }
285
274
 
286
- // -------- [Run] -------- //
287
-
288
275
  const isRuntime = true || process.env.RUNTIME === "true";
289
276
 
290
277
  function run(projectPath) {
@@ -299,11 +286,9 @@ function run(projectPath) {
299
286
  channelOwner(projectPath);
300
287
  indexContent(projectPath);
301
288
  }
302
- } else {
303
- // console.warn("Project path not found", projectPath);
304
289
  }
305
290
  } catch (e) {
306
- // ignore
291
+ // Patching is best-effort: a failure here must not block the install.
307
292
  }
308
293
  }
309
294
 
@@ -1,52 +1,41 @@
1
1
  const fs = require("fs");
2
2
  const { join } = require("path");
3
3
 
4
- // Args
5
4
  const on = process.argv[2] !== "off";
6
5
 
7
- // -------- [Modifiers] -------- //
8
-
9
- // Amends the file with the given entry point text and append text
10
- // When "on" is true, the append text is added to the entry point,
11
- // otherwise the append text is completely removed from the file
6
+ // When `on`, appendText is spliced in after entryPointText; when off, it is
7
+ // stripped back out. Leaves no marker, so an amend cannot be detected later.
12
8
  function amend(filePath, entryPointText, appendText) {
13
9
  const data = fs.readFileSync(filePath, "utf8");
14
10
  if (!data.includes(entryPointText)) {
15
11
  throw new Error("Entry point not found!", entryPointText);
16
12
  }
17
- // Ignore if the append text is already present
18
13
  if (on && data.includes(appendText)) {
19
14
  return;
20
15
  }
21
- // Add or clear according to on state
22
16
  const result = on
23
17
  ? data.replace(entryPointText, entryPointText + appendText)
24
18
  : data.replace(appendText, "");
25
19
 
26
- // Write
27
20
  fs.writeFileSync(filePath, result, "utf8");
28
21
  }
29
22
 
30
- // Replaces content.
31
- // When "on" is true, the new content is written to the file replacing the original content,
32
- // otherwise the original content is restored.
23
+ // When `on`, newContent replaces originalContent; when off, the original is
24
+ // restored. The `/* checksumai */` prefix is the marker that makes the off
25
+ // direction findable.
33
26
  function replaceContent(filePath, originalContent, newContent) {
34
- // Read the file content
35
27
  const fileContent = fs.readFileSync(filePath, "utf8");
36
28
 
37
- // add a marker for newContent that can be later recognized for "off" state
38
29
  newContent = `/* checksumai */ ${newContent}`;
39
30
 
40
31
  if (on && fileContent.includes(newContent)) {
41
32
  return;
42
33
  }
43
34
 
44
- // Join the lines back into a single string
45
35
  const updatedContent = on
46
36
  ? fileContent.replace(originalContent, newContent)
47
37
  : fileContent.replace(newContent, originalContent);
48
38
 
49
- // Write the modified content back to the file
50
39
  fs.writeFileSync(filePath, updatedContent, "utf8");
51
40
  }
52
41
 
@@ -58,9 +47,6 @@ function doesFileExist(filePath) {
58
47
  return true;
59
48
  }
60
49
 
61
- // -------- [Modifications] -------- //
62
-
63
- // Remove conditions for injecting Playwright scripts
64
50
  function alwaysInjectScripts(projectRoot) {
65
51
  const file = join(
66
52
  projectRoot,
@@ -78,7 +64,6 @@ function alwaysInjectScripts(projectRoot) {
78
64
  replaceContent(file, originalContent, newContent);
79
65
  }
80
66
 
81
- // Add implementation for generateSelectorAndLocator and inject to Playwright console API
82
67
  function addGenerateSelectorAndLocator(projectRoot) {
83
68
  const file = join(
84
69
  projectRoot,
@@ -99,8 +84,6 @@ function addGenerateSelectorAndLocator(projectRoot) {
99
84
  amend(file, entryPointText2, appendText2);
100
85
  }
101
86
 
102
- // -------- [Runtime modifications] -------- //
103
-
104
87
  function expect(projectRoot) {
105
88
  const file = join(
106
89
  projectRoot,
@@ -110,30 +93,6 @@ function expect(projectRoot) {
110
93
  return;
111
94
  }
112
95
  let originalContent, newContent;
113
-
114
- // originalContent = `return (...args) => {
115
- // const testInfo = (0, _globals.currentTestInfo)();`;
116
- // newContent = `return (...args) => {
117
- // let noSoft = false;
118
- // if (args.find(arg=>arg==='no-soft')){
119
- // noSoft = true;
120
- // args.pop();
121
- // }
122
- // const testInfo = (0, _globals.currentTestInfo)();`;
123
- // replaceContent(file, originalContent, newContent);
124
-
125
- // originalContent = `step.complete({
126
- // error
127
- // })`;
128
- // newContent = `step.complete({
129
- // error,
130
- // noSoft
131
- // })`;
132
- // replaceContent(file, originalContent, newContent);
133
-
134
- // originalContent = `if (this._info.isSoft) testInfo._failWithError(error);else throw error;`;
135
- // newContent = `if (this._info.isSoft && !noSoft) testInfo._failWithError(error);else throw error;`;
136
- // replaceContent(file, originalContent, newContent);
137
96
  }
138
97
 
139
98
  function testInfo(projectRoot) {
@@ -147,10 +106,6 @@ function testInfo(projectRoot) {
147
106
  let originalContent, newContent;
148
107
  let entryPointText, appendText;
149
108
 
150
- // originalContent = `const filteredStack = (0, _util.filteredStackTrace)((0, _utils.captureRawStack)());`;
151
- // newContent = `const filteredStack = (0, _util.filteredStackTrace)((0, _utils.captureRawStack)().filter(s=>!s.includes('@checksum-ai/runtime')));`;
152
- // replaceContent(file, originalContent, newContent);
153
-
154
109
  entryPointText = `data.location = data.location || filteredStack[0];`;
155
110
  appendText = `\nif (this._checksumInternal) {
156
111
  data.location = undefined;
@@ -256,10 +211,6 @@ function channelOwner(projectRoot) {
256
211
  }`;
257
212
  amend(file, entryPointText, appendText);
258
213
 
259
- // originalContent = `const stack = (0, _stackTrace.captureRawStack)();`;
260
- // newContent = `const stack = (0, _stackTrace.captureRawStack)().filter(s=>!s.includes('@checksum-ai/runtime'));`;
261
- // replaceContent(file, originalContent, newContent);
262
-
263
214
  entryPointText = `let apiName = stackTrace.apiName;`;
264
215
  appendText = `\nif (!isInternal && this._checksumTitle){
265
216
  apiName = this._checksumTitle;
@@ -289,8 +240,6 @@ function stackTrace(projectRoot) {
289
240
  replaceContent(file, originalContent, newContent);
290
241
  }
291
242
 
292
- // -------- [Run] -------- //
293
-
294
243
  const isRuntime = true || process.env.RUNTIME === "true";
295
244
 
296
245
  function run(projectPath) {
@@ -306,11 +255,9 @@ function run(projectPath) {
306
255
  stackTrace(projectPath);
307
256
  indexContent(projectPath);
308
257
  }
309
- } else {
310
- // console.warn("Project path not found", projectPath);
311
258
  }
312
259
  } catch (e) {
313
- // ignore
260
+ // Patching is best-effort: a failure here must not block the install.
314
261
  }
315
262
  }
316
263
 
@@ -1,52 +1,41 @@
1
1
  const fs = require("fs");
2
2
  const { join } = require("path");
3
3
 
4
- // Args
5
4
  const on = process.argv[2] !== "off";
6
5
 
7
- // -------- [Modifiers] -------- //
8
-
9
- // Amends the file with the given entry point text and append text
10
- // When "on" is true, the append text is added to the entry point,
11
- // otherwise the append text is completely removed from the file
6
+ // When `on`, appendText is spliced in after entryPointText; when off, it is
7
+ // stripped back out. Leaves no marker, so an amend cannot be detected later.
12
8
  function amend(filePath, entryPointText, appendText) {
13
9
  const data = fs.readFileSync(filePath, "utf8");
14
10
  if (!data.includes(entryPointText)) {
15
11
  throw new Error("Entry point not found!", entryPointText);
16
12
  }
17
- // Ignore if the append text is already present
18
13
  if (on && data.includes(appendText)) {
19
14
  return;
20
15
  }
21
- // Add or clear according to on state
22
16
  const result = on
23
17
  ? data.replace(entryPointText, entryPointText + appendText)
24
18
  : data.replace(appendText, "");
25
19
 
26
- // Write
27
20
  fs.writeFileSync(filePath, result, "utf8");
28
21
  }
29
22
 
30
- // Replaces content.
31
- // When "on" is true, the new content is written to the file replacing the original content,
32
- // otherwise the original content is restored.
23
+ // When `on`, newContent replaces originalContent; when off, the original is
24
+ // restored. The `/* checksumai */` prefix is the marker that makes the off
25
+ // direction findable.
33
26
  function replaceContent(filePath, originalContent, newContent) {
34
- // Read the file content
35
27
  const fileContent = fs.readFileSync(filePath, "utf8");
36
28
 
37
- // add a marker for newContent that can be later recognized for "off" state
38
29
  newContent = `/* checksumai */ ${newContent}`;
39
30
 
40
31
  if (on && fileContent.includes(newContent)) {
41
32
  return;
42
33
  }
43
34
 
44
- // Join the lines back into a single string
45
35
  const updatedContent = on
46
36
  ? fileContent.replace(originalContent, newContent)
47
37
  : fileContent.replace(newContent, originalContent);
48
38
 
49
- // Write the modified content back to the file
50
39
  fs.writeFileSync(filePath, updatedContent, "utf8");
51
40
  }
52
41
 
@@ -58,9 +47,6 @@ function doesFileExist(filePath) {
58
47
  return true;
59
48
  }
60
49
 
61
- // -------- [Modifications] -------- //
62
-
63
- // Remove conditions for injecting Playwright scripts
64
50
  function alwaysInjectScripts(projectRoot) {
65
51
  const file = join(
66
52
  projectRoot,
@@ -71,7 +57,6 @@ function alwaysInjectScripts(projectRoot) {
71
57
  }
72
58
  const originalContent =
73
59
  "if ((0, _debug.debugMode)() === 'console') await this.extendInjectedScript(consoleApiSource.source);";
74
- // "if ((0, _utils.debugMode)() === 'console') await this.extendInjectedScript(consoleApiSource.source);";
75
60
 
76
61
  const newContent =
77
62
  "await this.extendInjectedScript(consoleApiSource.source);";
@@ -79,7 +64,6 @@ function alwaysInjectScripts(projectRoot) {
79
64
  replaceContent(file, originalContent, newContent);
80
65
  }
81
66
 
82
- // Add implementation for generateSelectorAndLocator and inject to Playwright console API
83
67
  function addGenerateSelectorAndLocator(projectRoot) {
84
68
  const file = join(
85
69
  projectRoot,
@@ -100,8 +84,6 @@ function addGenerateSelectorAndLocator(projectRoot) {
100
84
  amend(file, entryPointText2, appendText2);
101
85
  }
102
86
 
103
- // -------- [Runtime modifications] -------- //
104
-
105
87
  function expect(projectRoot) {
106
88
  const file = join(
107
89
  projectRoot,
@@ -111,30 +93,6 @@ function expect(projectRoot) {
111
93
  return;
112
94
  }
113
95
  let originalContent, newContent;
114
-
115
- // originalContent = `return (...args) => {
116
- // const testInfo = (0, _globals.currentTestInfo)();`;
117
- // newContent = `return (...args) => {
118
- // let noSoft = false;
119
- // if (args.find(arg=>arg==='no-soft')){
120
- // noSoft = true;
121
- // args.pop();
122
- // }
123
- // const testInfo = (0, _globals.currentTestInfo)();`;
124
- // replaceContent(file, originalContent, newContent);
125
-
126
- // originalContent = `step.complete({
127
- // error
128
- // })`;
129
- // newContent = `step.complete({
130
- // error,
131
- // noSoft
132
- // })`;
133
- // replaceContent(file, originalContent, newContent);
134
-
135
- // originalContent = `if (this._info.isSoft) testInfo._failWithError(error);else throw error;`;
136
- // newContent = `if (this._info.isSoft && !noSoft) testInfo._failWithError(error);else throw error;`;
137
- // replaceContent(file, originalContent, newContent);
138
96
  }
139
97
 
140
98
  function testInfo(projectRoot) {
@@ -148,10 +106,6 @@ function testInfo(projectRoot) {
148
106
  let originalContent, newContent;
149
107
  let entryPointText, appendText;
150
108
 
151
- // originalContent = `const filteredStack = (0, _util.filteredStackTrace)((0, _utils.captureRawStack)());`;
152
- // newContent = `const filteredStack = (0, _util.filteredStackTrace)((0, _utils.captureRawStack)().filter(s=>!s.includes('@checksum-ai/runtime')));`;
153
- // replaceContent(file, originalContent, newContent);
154
-
155
109
  entryPointText = `data.location = data.location || filteredStack[0];`;
156
110
  appendText = `\nif (this._checksumInternal) {
157
111
  data.location = undefined;
@@ -189,7 +143,6 @@ function testType(projectRoot) {
189
143
  }
190
144
 
191
145
  entryPointText = `return await (0, _utils.currentZone)().with('stepZone', step).run(async () => {`;
192
- // entryPointText = `return await _utils.zones.run('stepZone', step, async () => {`;
193
146
  appendText = `\nif (options.obtainStep){
194
147
  options.obtainStep(step);
195
148
  }`;
@@ -253,18 +206,12 @@ function channelOwner(projectRoot) {
253
206
  let entryPointText, appendText;
254
207
 
255
208
  entryPointText = `async _wrapApiCall(func, isInternal) {`;
256
- // entryPointText = `async _wrapApiCall(func, isInternal = false) {`;
257
209
 
258
210
  appendText = `\nif (this._checksumInternal){
259
211
  isInternal = true;
260
212
  }`;
261
213
  amend(file, entryPointText, appendText);
262
214
 
263
- // originalContent = `const stack = (0, _stackTrace.captureRawStack)();`;
264
- // newContent = `const stack = (0, _stackTrace.captureRawStack)().filter(s=>!s.includes('@checksum-ai/runtime'));`;
265
- // replaceContent(file, originalContent, newContent);
266
-
267
- // entryPointText = `let apiName = stackTrace.apiName;`;
268
215
  entryPointText = `const apiZone = {
269
216
  apiName: stackTrace.apiName,
270
217
  frames: stackTrace.frames,
@@ -287,18 +234,11 @@ function channelOwner(projectRoot) {
287
234
  apiZone.apiName = apiZone.apiName.replace('proxy', 'page');
288
235
  }`;
289
236
  amend(file, entryPointText, appendText);
290
-
291
- // entryPointText = `if (isInternal) apiName = undefined;`;
292
- // appendText = `\nif (apiName && apiName.startsWith('proxy')) {
293
- // apiName = apiName.replace('proxy', 'page');
294
- // }`;
295
- // amend(file, entryPointText, appendText);
296
237
  }
297
238
 
298
239
  function stackTrace(projectRoot) {
299
240
  const file = join(
300
241
  projectRoot,
301
- // "node_modules/playwright-core/lib/utils/stackTrace.js"
302
242
  "node_modules/playwright-core/lib/utils/isomorphic/stackTrace.js"
303
243
  );
304
244
  if (!doesFileExist(file)) {
@@ -311,8 +251,6 @@ function stackTrace(projectRoot) {
311
251
  replaceContent(file, originalContent, newContent);
312
252
  }
313
253
 
314
- // -------- [Run] -------- //
315
-
316
254
  const isRuntime = true || process.env.RUNTIME === "true";
317
255
 
318
256
  function run(projectPath) {
@@ -328,11 +266,9 @@ function run(projectPath) {
328
266
  stackTrace(projectPath);
329
267
  indexContent(projectPath);
330
268
  }
331
- } else {
332
- // console.warn("Project path not found", projectPath);
333
269
  }
334
270
  } catch (e) {
335
- // ignore
271
+ // Patching is best-effort: a failure here must not block the install.
336
272
  }
337
273
  }
338
274