@checksum-ai/runtime 1.0.65 → 1.0.66

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/patch.js +50 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksum-ai/runtime",
3
- "version": "1.0.65",
3
+ "version": "1.0.66",
4
4
  "description": "Checksum.ai test runtime",
5
5
  "main": "index.js",
6
6
  "dependencies": {
package/scripts/patch.js CHANGED
@@ -51,15 +51,48 @@ function replaceLine(filePath, lineNumber, originalLine, newLine) {
51
51
  fs.writeFileSync(filePath, updatedContent, "utf8");
52
52
  }
53
53
 
54
+ // Replaces the content of the specified line in the file.
55
+ // When "on" is true, the new line is written to the file,
56
+ // otherwise the original line is restored.
57
+ function replaceContent(filePath, originalContent, newContent) {
58
+ // Read the file content
59
+ const fileContent = fs.readFileSync(filePath, "utf8");
60
+
61
+ // add a marker for newContent that can be later recognized for "off" state
62
+ newContent = `/* checksumai */ ${newContent}`;
63
+
64
+ // Split the content into an array of lines
65
+ const lines = fileContent.split(/\r?\n/);
66
+
67
+ lines.forEach((line, index) => {
68
+ if (on) {
69
+ if (line.includes(originalContent)) {
70
+ lines[index] = line.replace(originalContent, newContent);
71
+ }
72
+ } else {
73
+ if (line.includes(newContent)) {
74
+ lines[index] = line.replace(newContent, originalContent);
75
+ }
76
+ }
77
+ });
78
+
79
+ // Join the lines back into a single string
80
+ const updatedContent = lines.join("\n");
81
+
82
+ // Write the modified content back to the file
83
+ fs.writeFileSync(filePath, updatedContent, "utf8");
84
+ }
85
+
54
86
  // Remove conditions for injecting Playwright scripts
55
87
  function alwaysInjectScripts() {
56
88
  const file = "node_modules/playwright-core/lib/server/browserContext.js";
57
- const lineNumber = 108;
58
- const originalLine =
59
- " if ((0, _utils.debugMode)() === 'console') await this.extendInjectedScript(consoleApiSource.source);";
60
- const newLine =
61
- " await this.extendInjectedScript(consoleApiSource.source);";
62
- replaceLine(file, lineNumber, originalLine, newLine);
89
+ const originalContent =
90
+ "if ((0, _utils.debugMode)() === 'console') await this.extendInjectedScript(consoleApiSource.source);";
91
+
92
+ const newContent =
93
+ "await this.extendInjectedScript(consoleApiSource.source);";
94
+
95
+ replaceContent(file, originalContent, newContent);
63
96
  }
64
97
 
65
98
  // Add implementation for generateSelectorAndLocator and inject to Playwright console API
@@ -68,7 +101,7 @@ function addGenerateSelectorAndLocator() {
68
101
 
69
102
  const entryPointText1 = "this._generateLocator(element, language),\\n ";
70
103
  const appendText1 =
71
- "generateSelectorAndLocator: (element, language) => this._generateSelectorAndLocator(element, language),\\n ";
104
+ "generateSelectorAndLocator: (element, language) => this._generateSelectorAndLocator(element, language),\\n asLocator,\\n ";
72
105
  amend(file, entryPointText1, appendText1);
73
106
 
74
107
  const entryPointText2 =
@@ -80,3 +113,13 @@ function addGenerateSelectorAndLocator() {
80
113
 
81
114
  alwaysInjectScripts();
82
115
  addGenerateSelectorAndLocator();
116
+
117
+ // function alwaysInjectScriptsOld() {
118
+ // const file = "node_modules/playwright-core/lib/server/browserContext.js";
119
+ // const lineNumber = 108;
120
+ // const originalLine =
121
+ // " if ((0, _utils.debugMode)() === 'console') await this.extendInjectedScript(consoleApiSource.source);";
122
+ // const newLine =
123
+ // " await this.extendInjectedScript(consoleApiSource.source);";
124
+ // replaceLine(file, lineNumber, originalLine, newLine);
125
+ // }