@checksum-ai/runtime 1.0.85 → 1.0.87

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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@checksum-ai/runtime",
3
- "version": "1.0.85",
3
+ "version": "1.0.87",
4
4
  "description": "Checksum.ai test runtime",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "@playwright/test": "1.41.2",
8
8
  "ts-node": "^10.9.1",
9
9
  "jsdom": "^22.1.0",
10
+ "puppeteer-extra-plugin-stealth": "^2.11.2",
10
11
  "request": "^2.88.2"
11
12
  },
12
13
  "repository": {
package/scripts/patch.js CHANGED
@@ -3,14 +3,13 @@ const { join } = require("path");
3
3
 
4
4
  // Args
5
5
  const on = process.argv[2] !== "off";
6
- const fromRoot = process.argv[3] === "root";
7
- const projectRoot = process.env.PROJECT_ROOT ?? "";
6
+
7
+ // -------- [Modifiers] -------- //
8
8
 
9
9
  // Amends the file with the given entry point text and append text
10
10
  // When "on" is true, the append text is added to the entry point,
11
11
  // otherwise the append text is completely removed from the file
12
12
  function amend(filePath, entryPointText, appendText) {
13
- filePath = fromRoot ? `backend/${filePath}` : filePath;
14
13
  const data = fs.readFileSync(filePath, "utf8");
15
14
  if (!data.includes(entryPointText)) {
16
15
  throw new Error("Entry point not found!", entryPointText);
@@ -85,12 +84,25 @@ function replaceContent(filePath, originalContent, newContent) {
85
84
  fs.writeFileSync(filePath, updatedContent, "utf8");
86
85
  }
87
86
 
87
+ function doesFileExist(filePath) {
88
+ if (!fs.existsSync(filePath)) {
89
+ console.warn("File not found", filePath);
90
+ return false;
91
+ }
92
+ return true;
93
+ }
94
+
95
+ // -------- [Modifications] -------- //
96
+
88
97
  // Remove conditions for injecting Playwright scripts
89
- function alwaysInjectScripts() {
98
+ function alwaysInjectScripts(projectRoot) {
90
99
  const file = join(
91
100
  projectRoot,
92
101
  "node_modules/playwright-core/lib/server/browserContext.js"
93
102
  );
103
+ if (!doesFileExist(file)) {
104
+ return;
105
+ }
94
106
  const originalContent =
95
107
  "if ((0, _utils.debugMode)() === 'console') await this.extendInjectedScript(consoleApiSource.source);";
96
108
 
@@ -101,12 +113,14 @@ function alwaysInjectScripts() {
101
113
  }
102
114
 
103
115
  // Add implementation for generateSelectorAndLocator and inject to Playwright console API
104
- function addGenerateSelectorAndLocator() {
116
+ function addGenerateSelectorAndLocator(projectRoot) {
105
117
  const file = join(
106
118
  projectRoot,
107
119
  "node_modules/playwright-core/lib/generated/consoleApiSource.js"
108
120
  );
109
-
121
+ if (!doesFileExist(file)) {
122
+ return;
123
+ }
110
124
  const entryPointText1 = "this._generateLocator(element, language),\\n ";
111
125
  const appendText1 =
112
126
  "generateSelectorAndLocator: (element, language) => this._generateSelectorAndLocator(element, language),\\n asLocator,\\n ";
@@ -119,8 +133,25 @@ function addGenerateSelectorAndLocator() {
119
133
  amend(file, entryPointText2, appendText2);
120
134
  }
121
135
 
122
- alwaysInjectScripts();
123
- addGenerateSelectorAndLocator();
136
+ // -------- [Run] -------- //
137
+
138
+ const projectRootFromEnv = process.env.PROJECT_ROOT;
139
+ const projectPaths = projectRootFromEnv
140
+ ? [projectRootFromEnv]
141
+ : ["backend", "lib", "frontend"].map((project) =>
142
+ join(__dirname, "..", project)
143
+ );
144
+
145
+ for (const projectPath of projectPaths) {
146
+ try {
147
+ if (fs.existsSync(projectPath)) {
148
+ alwaysInjectScripts(projectPath);
149
+ addGenerateSelectorAndLocator(projectPath);
150
+ }
151
+ } catch (e) {
152
+ console.warn("Unable to patch playwright", projectPath, e);
153
+ }
154
+ }
124
155
 
125
156
  // function alwaysInjectScriptsOld() {
126
157
  // const file = "node_modules/playwright-core/lib/server/browserContext.js";