@checksum-ai/runtime 4.16.2 → 4.16.4

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.
@@ -2,29 +2,22 @@ const fs = require("fs");
2
2
  const crypto = require("crypto");
3
3
  const { join } = require("path");
4
4
 
5
- // Args
6
5
  const on = process.argv[2] !== "off";
7
6
 
8
- // -------- [Modifiers] -------- //
9
-
10
- // Amends the file with the given entry point text and append text
11
- // When "on" is true, the append text is added to the entry point,
12
- // otherwise the append text is completely removed from the file
7
+ // When `on`, appendText is spliced in after entryPointText; when off, it is
8
+ // stripped back out. Leaves no marker, so an amend cannot be detected later.
13
9
  function amend(filePath, entryPointText, appendText) {
14
10
  const data = fs.readFileSync(filePath, "utf8");
15
11
  if (!data.includes(entryPointText)) {
16
12
  throw new Error("Entry point not found!", entryPointText);
17
13
  }
18
- // Ignore if the append text is already present
19
14
  if (on && data.includes(appendText)) {
20
15
  return;
21
16
  }
22
- // Add or clear according to on state
23
17
  const result = on
24
18
  ? data.replace(entryPointText, entryPointText + appendText)
25
19
  : data.replace(appendText, "");
26
20
 
27
- // Write
28
21
  fs.writeFileSync(filePath, result, "utf8");
29
22
  }
30
23
 
@@ -34,6 +27,9 @@ function amend(filePath, entryPointText, appendText) {
34
27
  // (whose newContent collapses to the bare marker) to clobber the FIRST
35
28
  // `/* checksumai */ ` it found, corrupting whichever patch happened to live
36
29
  // at the lowest line number.
30
+ // When `on`, newContent replaces originalContent; when off, the original is
31
+ // restored. The `/* checksumai */` prefix is the marker that makes the off
32
+ // direction findable.
37
33
  function replaceContent(filePath, originalContent, newContent) {
38
34
  const fileContent = fs.readFileSync(filePath, "utf8");
39
35
 
@@ -89,9 +85,6 @@ function doesFileExist(filePath) {
89
85
  return true;
90
86
  }
91
87
 
92
- // -------- [Modifications] -------- //
93
-
94
- // Remove conditions for injecting Playwright scripts
95
88
  function alwaysInjectScripts(projectRoot) {
96
89
  const file = join(
97
90
  projectRoot,
@@ -100,11 +93,6 @@ function alwaysInjectScripts(projectRoot) {
100
93
  if (!doesFileExist(file)) {
101
94
  return;
102
95
  }
103
- // const originalContent =
104
- // "if ((0, _debug.debugMode)() === 'console') await this.extendInjectedScript(consoleApiSource.source);";
105
-
106
- // const newContent =
107
- // "await this.extendInjectedScript(consoleApiSource.source);";
108
96
 
109
97
  const originalContent = 'if ((0, import_debug.debugMode)() === "console")';
110
98
 
@@ -113,7 +101,6 @@ function alwaysInjectScripts(projectRoot) {
113
101
  replaceContent(file, originalContent, newContent);
114
102
  }
115
103
 
116
- // Add implementation for generateSelectorAndLocator and inject to Playwright console API
117
104
  function addGenerateSelectorAndLocator(projectRoot) {
118
105
  const file = join(
119
106
  projectRoot,
@@ -133,8 +120,6 @@ function addGenerateSelectorAndLocator(projectRoot) {
133
120
  amend(file, entryPointText2, appendText2);
134
121
  }
135
122
 
136
- // -------- [Runtime modifications] -------- //
137
-
138
123
  function expect(projectRoot) {
139
124
  const file = join(
140
125
  projectRoot,
@@ -144,30 +129,6 @@ function expect(projectRoot) {
144
129
  return;
145
130
  }
146
131
  let originalContent, newContent;
147
-
148
- // originalContent = `return (...args) => {
149
- // const testInfo = (0, _globals.currentTestInfo)();`;
150
- // newContent = `return (...args) => {
151
- // let noSoft = false;
152
- // if (args.find(arg=>arg==='no-soft')){
153
- // noSoft = true;
154
- // args.pop();
155
- // }
156
- // const testInfo = (0, _globals.currentTestInfo)();`;
157
- // replaceContent(file, originalContent, newContent);
158
-
159
- // originalContent = `step.complete({
160
- // error
161
- // })`;
162
- // newContent = `step.complete({
163
- // error,
164
- // noSoft
165
- // })`;
166
- // replaceContent(file, originalContent, newContent);
167
-
168
- // originalContent = `if (this._info.isSoft) testInfo._failWithError(error);else throw error;`;
169
- // newContent = `if (this._info.isSoft && !noSoft) testInfo._failWithError(error);else throw error;`;
170
- // replaceContent(file, originalContent, newContent);
171
132
  }
172
133
 
173
134
  function testInfo(projectRoot) {
@@ -181,10 +142,6 @@ function testInfo(projectRoot) {
181
142
  let originalContent, newContent;
182
143
  let entryPointText, appendText;
183
144
 
184
- // originalContent = `const filteredStack = (0, _util.filteredStackTrace)((0, _utils.captureRawStack)());`;
185
- // newContent = `const filteredStack = (0, _util.filteredStackTrace)((0, _utils.captureRawStack)().filter(s=>!s.includes('@checksum-ai/runtime')));`;
186
- // replaceContent(file, originalContent, newContent);
187
-
188
145
  entryPointText = `data.location = data.location || filteredStack[0];`;
189
146
  appendText = `\nif (this._checksumInternal) {
190
147
  data.location = undefined;
@@ -222,7 +179,6 @@ function testType(projectRoot) {
222
179
  }
223
180
 
224
181
  entryPointText = `return await (0, import_utils.currentZone)().with("stepZone", step).run(async () => {`;
225
- // entryPointText = `return await _utils.zones.run('stepZone', step, async () => {`;
226
182
  appendText = `\nif (options.obtainStep){
227
183
  options.obtainStep(step);
228
184
  }`;
@@ -280,7 +236,6 @@ function channelOwner(projectRoot) {
280
236
  let entryPointText, appendText;
281
237
 
282
238
  entryPointText = `async _wrapApiCall(func, isInternal) {`;
283
- // entryPointText = `async _wrapApiCall(func, isInternal = false) {`;
284
239
 
285
240
  appendText = `\nif (this._checksumInternal){
286
241
  isInternal = true;
@@ -366,8 +321,6 @@ function reportTraceFile(projectRoot) {
366
321
  replaceContent(file, originalContent, newContent);
367
322
  }
368
323
 
369
- // -------- [Run] -------- //
370
-
371
324
  const isRuntime = true || process.env.RUNTIME === "true";
372
325
 
373
326
  function run(projectPath) {
@@ -394,7 +347,6 @@ function run(projectPath) {
394
347
  console.warn("Project path not found", projectPath);
395
348
  }
396
349
  } catch (e) {
397
- // ignore
398
350
  console.error(e);
399
351
  }
400
352
  }
@@ -2,29 +2,22 @@ const fs = require("fs");
2
2
  const crypto = require("crypto");
3
3
  const { join } = require("path");
4
4
 
5
- // Args
6
5
  const on = process.argv[2] !== "off";
7
6
 
8
- // -------- [Modifiers] -------- //
9
-
10
- // Amends the file with the given entry point text and append text
11
- // When "on" is true, the append text is added to the entry point,
12
- // otherwise the append text is completely removed from the file
7
+ // When `on`, appendText is spliced in after entryPointText; when off, it is
8
+ // stripped back out. Leaves no marker, so an amend cannot be detected later.
13
9
  function amend(filePath, entryPointText, appendText) {
14
10
  const data = fs.readFileSync(filePath, "utf8");
15
11
  if (!data.includes(entryPointText)) {
16
12
  throw new Error("Entry point not found!", entryPointText);
17
13
  }
18
- // Ignore if the append text is already present
19
14
  if (on && data.includes(appendText)) {
20
15
  return;
21
16
  }
22
- // Add or clear according to on state
23
17
  const result = on
24
18
  ? data.replace(entryPointText, entryPointText + appendText)
25
19
  : data.replace(appendText, "");
26
20
 
27
- // Write
28
21
  fs.writeFileSync(filePath, result, "utf8");
29
22
  }
30
23
 
@@ -34,6 +27,9 @@ function amend(filePath, entryPointText, appendText) {
34
27
  // (whose newContent collapses to the bare marker) to clobber the FIRST
35
28
  // `/* checksumai */ ` it found, corrupting whichever patch happened to live
36
29
  // at the lowest line number.
30
+ // When `on`, newContent replaces originalContent; when off, the original is
31
+ // restored. The `/* checksumai */` prefix is the marker that makes the off
32
+ // direction findable.
37
33
  function replaceContent(filePath, originalContent, newContent) {
38
34
  const fileContent = fs.readFileSync(filePath, "utf8");
39
35
 
@@ -89,9 +85,6 @@ function doesFileExist(filePath) {
89
85
  return true;
90
86
  }
91
87
 
92
- // -------- [Modifications] -------- //
93
-
94
- // Remove conditions for injecting Playwright scripts
95
88
  function alwaysInjectScripts(projectRoot) {
96
89
  const file = join(
97
90
  projectRoot,
@@ -108,7 +101,6 @@ function alwaysInjectScripts(projectRoot) {
108
101
  replaceContent(file, originalContent, newContent);
109
102
  }
110
103
 
111
- // Add implementation for generateSelectorAndLocator and inject to Playwright console API
112
104
  function addGenerateSelectorAndLocator(projectRoot) {
113
105
  const file = join(
114
106
  projectRoot,
@@ -128,8 +120,6 @@ function addGenerateSelectorAndLocator(projectRoot) {
128
120
  amend(file, entryPointText2, appendText2);
129
121
  }
130
122
 
131
- // -------- [Runtime modifications] -------- //
132
-
133
123
  function expect(projectRoot) {
134
124
  const file = join(
135
125
  projectRoot,
@@ -139,30 +129,6 @@ function expect(projectRoot) {
139
129
  return;
140
130
  }
141
131
  let originalContent, newContent;
142
-
143
- // originalContent = `return (...args) => {
144
- // const testInfo = (0, _globals.currentTestInfo)();`;
145
- // newContent = `return (...args) => {
146
- // let noSoft = false;
147
- // if (args.find(arg=>arg==='no-soft')){
148
- // noSoft = true;
149
- // args.pop();
150
- // }
151
- // const testInfo = (0, _globals.currentTestInfo)();`;
152
- // replaceContent(file, originalContent, newContent);
153
-
154
- // originalContent = `step.complete({
155
- // error
156
- // })`;
157
- // newContent = `step.complete({
158
- // error,
159
- // noSoft
160
- // })`;
161
- // replaceContent(file, originalContent, newContent);
162
-
163
- // originalContent = `if (this._info.isSoft) testInfo._failWithError(error);else throw error;`;
164
- // newContent = `if (this._info.isSoft && !noSoft) testInfo._failWithError(error);else throw error;`;
165
- // replaceContent(file, originalContent, newContent);
166
132
  }
167
133
 
168
134
  function testInfo(projectRoot) {
@@ -176,10 +142,6 @@ function testInfo(projectRoot) {
176
142
  let originalContent, newContent;
177
143
  let entryPointText, appendText;
178
144
 
179
- // originalContent = `const filteredStack = (0, _util.filteredStackTrace)((0, _utils.captureRawStack)());`;
180
- // newContent = `const filteredStack = (0, _util.filteredStackTrace)((0, _utils.captureRawStack)().filter(s=>!s.includes('@checksum-ai/runtime')));`;
181
- // replaceContent(file, originalContent, newContent);
182
-
183
145
  entryPointText = `location = location || filteredStack[0];`;
184
146
  appendText = `\nif (this._checksumInternal) {
185
147
  location = undefined;
@@ -217,7 +179,6 @@ function testType(projectRoot) {
217
179
  }
218
180
 
219
181
  entryPointText = `return await (0, import_utils.currentZone)().with("stepZone", step).run(async () => {`;
220
- // entryPointText = `return await _utils.zones.run('stepZone', step, async () => {`;
221
182
  appendText = `\nif (options.obtainStep){
222
183
  options.obtainStep(step);
223
184
  }`;
@@ -502,8 +463,6 @@ function htmlReporter(projectRoot) {
502
463
  replaceContent(file, originalContent, newContent);
503
464
  }
504
465
 
505
- // -------- [Run] -------- //
506
-
507
466
  const isRuntime = true || process.env.RUNTIME === "true";
508
467
 
509
468
  function run(projectPath) {
@@ -531,7 +490,6 @@ function run(projectPath) {
531
490
  console.warn("Project path not found", projectPath);
532
491
  }
533
492
  } catch (e) {
534
- // ignore
535
493
  console.error(e);
536
494
  }
537
495
  }
@@ -2,29 +2,22 @@ const fs = require("fs");
2
2
  const crypto = require("crypto");
3
3
  const { join } = require("path");
4
4
 
5
- // Args
6
5
  const on = process.argv[2] !== "off";
7
6
 
8
- // -------- [Modifiers] -------- //
9
-
10
- // Amends the file with the given entry point text and append text
11
- // When "on" is true, the append text is added to the entry point,
12
- // otherwise the append text is completely removed from the file
7
+ // When `on`, appendText is spliced in after entryPointText; when off, it is
8
+ // stripped back out. Leaves no marker, so an amend cannot be detected later.
13
9
  function amend(filePath, entryPointText, appendText) {
14
10
  const data = fs.readFileSync(filePath, "utf8");
15
11
  if (!data.includes(entryPointText)) {
16
12
  throw new Error("Entry point not found!", entryPointText);
17
13
  }
18
- // Ignore if the append text is already present
19
14
  if (on && data.includes(appendText)) {
20
15
  return;
21
16
  }
22
- // Add or clear according to on state
23
17
  const result = on
24
18
  ? data.replace(entryPointText, entryPointText + appendText)
25
19
  : data.replace(appendText, "");
26
20
 
27
- // Write
28
21
  fs.writeFileSync(filePath, result, "utf8");
29
22
  }
30
23
 
@@ -34,6 +27,9 @@ function amend(filePath, entryPointText, appendText) {
34
27
  // (whose newContent collapses to the bare marker) to clobber the FIRST
35
28
  // `/* checksumai */ ` it found, corrupting whichever patch happened to live
36
29
  // at the lowest line number.
30
+ // When `on`, newContent replaces originalContent; when off, the original is
31
+ // restored. The `/* checksumai */` prefix is the marker that makes the off
32
+ // direction findable.
37
33
  function replaceContent(filePath, originalContent, newContent) {
38
34
  const fileContent = fs.readFileSync(filePath, "utf8");
39
35
 
@@ -89,9 +85,6 @@ function doesFileExist(filePath) {
89
85
  return true;
90
86
  }
91
87
 
92
- // -------- [Modifications] -------- //
93
-
94
- // Remove conditions for injecting Playwright scripts
95
88
  function alwaysInjectScripts(projectRoot) {
96
89
  const file = join(
97
90
  projectRoot,
@@ -108,7 +101,6 @@ function alwaysInjectScripts(projectRoot) {
108
101
  replaceContent(file, originalContent, newContent);
109
102
  }
110
103
 
111
- // Add implementation for generateSelectorAndLocator and inject to Playwright console API
112
104
  function addGenerateSelectorAndLocator(projectRoot) {
113
105
  const file = join(
114
106
  projectRoot,
@@ -128,8 +120,6 @@ function addGenerateSelectorAndLocator(projectRoot) {
128
120
  amend(file, entryPointText2, appendText2);
129
121
  }
130
122
 
131
- // -------- [Runtime modifications] -------- //
132
-
133
123
  function expect(projectRoot) {
134
124
  const file = join(
135
125
  projectRoot,
@@ -139,30 +129,6 @@ function expect(projectRoot) {
139
129
  return;
140
130
  }
141
131
  let originalContent, newContent;
142
-
143
- // originalContent = `return (...args) => {
144
- // const testInfo = (0, _globals.currentTestInfo)();`;
145
- // newContent = `return (...args) => {
146
- // let noSoft = false;
147
- // if (args.find(arg=>arg==='no-soft')){
148
- // noSoft = true;
149
- // args.pop();
150
- // }
151
- // const testInfo = (0, _globals.currentTestInfo)();`;
152
- // replaceContent(file, originalContent, newContent);
153
-
154
- // originalContent = `step.complete({
155
- // error
156
- // })`;
157
- // newContent = `step.complete({
158
- // error,
159
- // noSoft
160
- // })`;
161
- // replaceContent(file, originalContent, newContent);
162
-
163
- // originalContent = `if (this._info.isSoft) testInfo._failWithError(error);else throw error;`;
164
- // newContent = `if (this._info.isSoft && !noSoft) testInfo._failWithError(error);else throw error;`;
165
- // replaceContent(file, originalContent, newContent);
166
132
  }
167
133
 
168
134
  function testInfo(projectRoot) {
@@ -176,10 +142,6 @@ function testInfo(projectRoot) {
176
142
  let originalContent, newContent;
177
143
  let entryPointText, appendText;
178
144
 
179
- // originalContent = `const filteredStack = (0, _util.filteredStackTrace)((0, _utils.captureRawStack)());`;
180
- // newContent = `const filteredStack = (0, _util.filteredStackTrace)((0, _utils.captureRawStack)().filter(s=>!s.includes('@checksum-ai/runtime')));`;
181
- // replaceContent(file, originalContent, newContent);
182
-
183
145
  entryPointText = `location = location || filteredStack[0];`;
184
146
  appendText = `\nif (this._checksumInternal) {
185
147
  location = undefined;
@@ -217,7 +179,6 @@ function testType(projectRoot) {
217
179
  }
218
180
 
219
181
  entryPointText = `return await (0, import_utils.currentZone)().with("stepZone", step).run(async () => {`;
220
- // entryPointText = `return await _utils.zones.run('stepZone', step, async () => {`;
221
182
  appendText = `\nif (options.obtainStep){
222
183
  options.obtainStep(step);
223
184
  }`;
@@ -502,8 +463,6 @@ function htmlReporter(projectRoot) {
502
463
  replaceContent(file, originalContent, newContent);
503
464
  }
504
465
 
505
- // -------- [Run] -------- //
506
-
507
466
  const isRuntime = true || process.env.RUNTIME === "true";
508
467
 
509
468
  function run(projectPath) {
@@ -531,7 +490,6 @@ function run(projectPath) {
531
490
  console.warn("Project path not found", projectPath);
532
491
  }
533
492
  } catch (e) {
534
- // ignore
535
493
  console.error(e);
536
494
  }
537
495
  }