@dev-blinq/cucumber_client 1.0.1421-dev → 1.0.1423-dev
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/bin/client/code_gen/page_reflection.js +815 -1003
- package/bin/client/cucumber_selector.js +4 -0
- package/bin/client/project.js +186 -202
- package/bin/logger.js +3 -2
- package/bin/min/consoleApi.min.cjs +2 -3
- package/bin/min/injectedScript.min.cjs +16 -16
- package/package.json +14 -6
- package/bin/assets/bundled_scripts/recorder.js +0 -220
|
@@ -117,6 +117,10 @@ if (deleteMjsFiles) {
|
|
|
117
117
|
const utilsPath = path.join(__dirname, "../assets/templates/utils_template.txt");
|
|
118
118
|
const utilsContent = fs.readFileSync(utilsPath, "utf8");
|
|
119
119
|
const utilsFileName = stepsPath + "/utils.mjs";
|
|
120
|
+
// if stepsPath directory doesn't exist create it
|
|
121
|
+
if (!fs.existsSync(stepsPath)) {
|
|
122
|
+
fs.mkdirSync(stepsPath, { recursive: true });
|
|
123
|
+
}
|
|
120
124
|
fs.writeFileSync(utilsFileName, utilsContent, "utf8");
|
|
121
125
|
// copy hooks file to the steps directory
|
|
122
126
|
const hooksTemplateFilePath = path.join(__dirname, "../assets/templates/_hooks_template.txt");
|
package/bin/client/project.js
CHANGED
|
@@ -1,220 +1,204 @@
|
|
|
1
|
+
// project.ts
|
|
1
2
|
import { writeFileSync, readFileSync, readdirSync, existsSync, mkdirSync } from "fs";
|
|
2
|
-
import { CodePage } from "./code_gen/page_reflection.js";
|
|
3
|
-
|
|
4
|
-
import logger from "../logger.js";
|
|
5
3
|
import path from "path";
|
|
6
4
|
import { fileURLToPath } from "url";
|
|
5
|
+
// Keep the .js extensions because the compiled runtime modules are ESM .js files.
|
|
6
|
+
import { CodePage } from "./code_gen/page_reflection.js";
|
|
7
|
+
import logger from "../logger.js";
|
|
7
8
|
import { findFilesWithExtension } from "./cucumber/steps_definitions.js";
|
|
8
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
10
|
const __dirname = path.dirname(__filename);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
async load() {
|
|
20
|
-
this.pages = [];
|
|
21
|
-
// load env.json from the project root folder
|
|
22
|
-
let envFile = "";
|
|
23
|
-
const envArgVal = checkForEnvArg();
|
|
24
|
-
if (envArgVal) {
|
|
25
|
-
envFile = envArgVal;
|
|
26
|
-
} else if (process.env["BLINQ_ENV"]) {
|
|
27
|
-
envFile = process.env["BLINQ_ENV"];
|
|
28
|
-
} else if (existsSync(path.join(this.rootFolder, "env.json"))) {
|
|
29
|
-
envFile = path.join(this.rootFolder, "env.json");
|
|
30
|
-
} else {
|
|
31
|
-
//list all the files in the environments directory use the first json file
|
|
32
|
-
let files = readdirSync(path.join(this.rootFolder, "environments"));
|
|
33
|
-
for (let i = 0; i < files.length; i++) {
|
|
34
|
-
let file = files[i];
|
|
35
|
-
if (file.endsWith(".json")) {
|
|
36
|
-
envFile = path.join(this.rootFolder, "environments", file);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// const envFile = path.join(this.rootFolder, "env.json");
|
|
42
|
-
if (!existsSync(envFile) || envFile === "") {
|
|
43
|
-
throw new Error(
|
|
44
|
-
`
|
|
45
|
-
======================================================
|
|
46
|
-
env.json file not found in the project root folder
|
|
47
|
-
or in the environments folder
|
|
48
|
-
======================================================
|
|
49
|
-
`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
let envFileContent = readFileSync(envFile, "utf8");
|
|
53
|
-
try {
|
|
54
|
-
this.environment = JSON.parse(envFileContent);
|
|
55
|
-
} catch (e) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
`
|
|
58
|
-
======================================================
|
|
59
|
-
unable to parse environment file
|
|
60
|
-
${e}
|
|
61
|
-
======================================================
|
|
62
|
-
`
|
|
63
|
-
);
|
|
11
|
+
function checkForEnvArg() {
|
|
12
|
+
for (const arg of process.argv.slice(2)) {
|
|
13
|
+
if (arg.startsWith("--")) {
|
|
14
|
+
const [key, value] = arg.split("=");
|
|
15
|
+
if (key.slice(2) === "env") {
|
|
16
|
+
return value ?? null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
64
19
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
`
|
|
73
|
-
);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
function generatePrompt(promptFile, parameters, chat = true) {
|
|
23
|
+
let promptFileContent = readFileSync(promptFile, "utf8");
|
|
24
|
+
for (const key in parameters) {
|
|
25
|
+
const value = parameters[key];
|
|
26
|
+
promptFileContent = promptFileContent.replaceAll(`{${key}}`, value);
|
|
74
27
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
28
|
+
if (!chat)
|
|
29
|
+
return { promptFileContent };
|
|
30
|
+
const messages = [];
|
|
31
|
+
const parts = promptFileContent.split("####");
|
|
32
|
+
for (let i = 0; i < parts.length; i++) {
|
|
33
|
+
if (!parts[i].trim())
|
|
34
|
+
continue;
|
|
35
|
+
const role = parts[i];
|
|
36
|
+
const prompt = parts[i + 1];
|
|
37
|
+
messages.push({ role, content: (prompt ?? "").trim() });
|
|
38
|
+
i++;
|
|
78
39
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
writeFileSync(hooksFilePath, hooksContent, "utf8");
|
|
90
|
-
}
|
|
91
|
-
} catch (e) {
|
|
92
|
-
logger.error("Error loading utils_template");
|
|
40
|
+
return { messages, promptFileContent };
|
|
41
|
+
}
|
|
42
|
+
class Project {
|
|
43
|
+
rootFolder;
|
|
44
|
+
stepsFolder;
|
|
45
|
+
environment = null;
|
|
46
|
+
pages = [];
|
|
47
|
+
constructor(rootFolder) {
|
|
48
|
+
this.rootFolder = rootFolder;
|
|
49
|
+
this.stepsFolder = path.join(rootFolder, "features", "step_definitions");
|
|
93
50
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
51
|
+
async load() {
|
|
52
|
+
this.pages = [];
|
|
53
|
+
// Resolve env file path
|
|
54
|
+
let envFile = "";
|
|
55
|
+
const envArgVal = checkForEnvArg();
|
|
56
|
+
if (envArgVal) {
|
|
57
|
+
envFile = envArgVal;
|
|
58
|
+
}
|
|
59
|
+
else if (process.env["BLINQ_ENV"]) {
|
|
60
|
+
envFile = process.env["BLINQ_ENV"];
|
|
61
|
+
}
|
|
62
|
+
else if (existsSync(path.join(this.rootFolder, "env.json"))) {
|
|
63
|
+
envFile = path.join(this.rootFolder, "env.json");
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// pick the first .json from environments/
|
|
67
|
+
const envDir = path.join(this.rootFolder, "environments");
|
|
68
|
+
const files = existsSync(envDir) ? readdirSync(envDir) : [];
|
|
69
|
+
for (let i = 0; i < files.length; i++) {
|
|
70
|
+
const file = files[i];
|
|
71
|
+
if (file.endsWith(".json")) {
|
|
72
|
+
envFile = path.join(envDir, file);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!existsSync(envFile) || envFile === "") {
|
|
78
|
+
throw new Error(`
|
|
79
|
+
======================================================
|
|
80
|
+
env.json file not found in the project root folder
|
|
81
|
+
or in the environments folder
|
|
82
|
+
======================================================
|
|
83
|
+
`);
|
|
84
|
+
}
|
|
85
|
+
const envFileContent = readFileSync(envFile, "utf8");
|
|
86
|
+
try {
|
|
87
|
+
this.environment = JSON.parse(envFileContent);
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
throw new Error(`
|
|
91
|
+
======================================================
|
|
92
|
+
unable to parse environment file
|
|
93
|
+
${e}
|
|
94
|
+
======================================================
|
|
95
|
+
`);
|
|
96
|
+
}
|
|
97
|
+
if (!this.environment.baseUrl) {
|
|
98
|
+
throw new Error(`
|
|
99
|
+
======================================================
|
|
100
|
+
baseUrl not found in env.json file
|
|
101
|
+
or in the environments folder
|
|
102
|
+
======================================================
|
|
103
|
+
`);
|
|
104
|
+
}
|
|
105
|
+
// Prepare step_definitions utilities
|
|
106
|
+
if (!existsSync(this.stepsFolder)) {
|
|
107
|
+
return this.environment.name;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
const utilsPath = path.join(__dirname, "../assets/templates/utils_template.txt");
|
|
111
|
+
const utilsContent = readFileSync(utilsPath, "utf8");
|
|
112
|
+
const utilsFileName = path.join(this.stepsFolder, "utils.mjs");
|
|
113
|
+
writeFileSync(utilsFileName, utilsContent, "utf8");
|
|
114
|
+
const hooksTemplateFilePath = path.join(__dirname, "../assets", "templates", "_hooks_template.txt");
|
|
115
|
+
if (existsSync(hooksTemplateFilePath)) {
|
|
116
|
+
const hooksFilePath = path.join(this.stepsFolder, "_hooks.mjs");
|
|
117
|
+
const hooksContent = readFileSync(hooksTemplateFilePath, "utf8");
|
|
118
|
+
writeFileSync(hooksFilePath, hooksContent, "utf8");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
logger.error("Error loading utils_template");
|
|
123
|
+
}
|
|
124
|
+
const files = findFilesWithExtension(this.stepsFolder, "mjs");
|
|
125
|
+
for (let i = 0; i < files.length; i++) {
|
|
126
|
+
const file = files[i];
|
|
127
|
+
if (file.startsWith("_"))
|
|
128
|
+
continue;
|
|
129
|
+
if (file.endsWith(".mjs")) {
|
|
130
|
+
const fullFileName = path.join(this.rootFolder, "features", "step_definitions", file);
|
|
131
|
+
const page = new CodePage(fullFileName);
|
|
132
|
+
page.generateModel();
|
|
133
|
+
this.pages.push(page);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return this.environment.name;
|
|
112
137
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
this.pages.forEach((page) => {
|
|
118
|
-
result.push(page.getName());
|
|
119
|
-
});
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
findMethodInPages(methodName) {
|
|
123
|
-
for (const page of this.pages) {
|
|
124
|
-
for (const method of page.methods) {
|
|
125
|
-
if (method.name === methodName) {
|
|
126
|
-
return { page, method };
|
|
127
|
-
}
|
|
128
|
-
}
|
|
138
|
+
getPagesNames() {
|
|
139
|
+
const result = [];
|
|
140
|
+
this.pages.forEach((page) => result.push(page.getName()));
|
|
141
|
+
return result;
|
|
129
142
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
getPage(pageName, createEmpty = false) {
|
|
143
|
-
for (let i = 0; i < this.pages.length; i++) {
|
|
144
|
-
if (this.pages[i].getName().toLowerCase() === pageName.toLowerCase()) {
|
|
145
|
-
return this.pages[i];
|
|
146
|
-
}
|
|
143
|
+
findMethodInPages(methodName) {
|
|
144
|
+
for (const page of this.pages) {
|
|
145
|
+
for (const method of page.methods) {
|
|
146
|
+
if (method.name === methodName) {
|
|
147
|
+
return { page, method };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { page: null, method: null };
|
|
147
152
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
getProjectSignature() {
|
|
154
|
+
const result = [];
|
|
155
|
+
this.pages.forEach((page) => {
|
|
156
|
+
page.getMethodsNames().forEach((methodName) => {
|
|
157
|
+
result.push(page.getMethodInCommandFormat(methodName));
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
return result;
|
|
154
161
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
+
getPage(pageName, createEmpty = false) {
|
|
163
|
+
for (let i = 0; i < this.pages.length; i++) {
|
|
164
|
+
if (this.pages[i].getName().toLowerCase() === pageName.toLowerCase()) {
|
|
165
|
+
return this.pages[i];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (createEmpty) {
|
|
169
|
+
const distFileName = path.join(this.stepsFolder, `${pageName}_page.mjs`);
|
|
170
|
+
const page = new CodePage(distFileName);
|
|
171
|
+
page.generateModel();
|
|
172
|
+
this.setPage(pageName, page);
|
|
173
|
+
return page;
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
162
176
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
177
|
+
setPage(pageName, page) {
|
|
178
|
+
for (let i = 0; i < this.pages.length; i++) {
|
|
179
|
+
if (this.pages[i].getName().toLowerCase() === pageName.toLowerCase()) {
|
|
180
|
+
this.pages[i] = page;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
169
183
|
}
|
|
170
|
-
|
|
171
|
-
|
|
184
|
+
createNewPage(name, _path) {
|
|
185
|
+
const distFileName = path.join(this.stepsFolder, `${name}_page.mjs`);
|
|
186
|
+
if (existsSync(distFileName)) {
|
|
187
|
+
logger.error("Page already exists: " + distFileName);
|
|
188
|
+
throw new Error(`Page already exists: ${name} - ${name}_page.mjs`);
|
|
189
|
+
}
|
|
190
|
+
if (!existsSync(this.stepsFolder)) {
|
|
191
|
+
mkdirSync(this.stepsFolder, { recursive: true });
|
|
192
|
+
}
|
|
193
|
+
const map = {
|
|
194
|
+
name,
|
|
195
|
+
path: _path ? `"${_path}"` : "null",
|
|
196
|
+
name_upper: name.charAt(0).toUpperCase() + name.slice(1),
|
|
197
|
+
};
|
|
198
|
+
const { promptFileContent } = generatePrompt(path.join(__dirname, "../assets/templates/page_template.txt"), map, false);
|
|
199
|
+
writeFileSync(distFileName, promptFileContent, "utf8");
|
|
200
|
+
// refresh pages list
|
|
201
|
+
void this.load();
|
|
172
202
|
}
|
|
173
|
-
let map = {
|
|
174
|
-
name,
|
|
175
|
-
path: _path ? `"${_path}"` : "null",
|
|
176
|
-
name_upper: name.charAt(0).toUpperCase() + name.slice(1),
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
let content = generatePrompt(
|
|
180
|
-
path.join(__dirname, "../assets/templates/page_template.txt"),
|
|
181
|
-
map,
|
|
182
|
-
false
|
|
183
|
-
).promptFileContent;
|
|
184
|
-
writeFileSync(distFileName, content, "utf8");
|
|
185
|
-
this.load();
|
|
186
|
-
}
|
|
187
203
|
}
|
|
188
|
-
|
|
189
|
-
let promptFileContent = readFileSync(promptFile, "utf8");
|
|
190
|
-
for (const key in parameters) {
|
|
191
|
-
const value = parameters[key];
|
|
192
|
-
promptFileContent = promptFileContent.replaceAll(`{${key}}`, value);
|
|
193
|
-
}
|
|
194
|
-
if (!chat) return { promptFileContent };
|
|
195
|
-
const messages = [];
|
|
196
|
-
const parts = promptFileContent.split("####");
|
|
197
|
-
for (let i = 0; i < parts.length; i++) {
|
|
198
|
-
if (!parts[i].trim()) continue;
|
|
199
|
-
const role = parts[i];
|
|
200
|
-
const prompt = parts[i + 1];
|
|
201
|
-
messages.push({ role, content: prompt.trim() });
|
|
202
|
-
// console.error("####prompt####", `role ${role}ֿֿ`);
|
|
203
|
-
// console.error(prompt.trim());
|
|
204
|
-
i++;
|
|
205
|
-
}
|
|
206
|
-
return { messages, promptFileContent };
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const checkForEnvArg = () => {
|
|
210
|
-
for (let arg of process.argv.slice(2)) {
|
|
211
|
-
if (arg.startsWith("--")) {
|
|
212
|
-
const [key, value] = arg.split("=");
|
|
213
|
-
if (key.slice(2) === "env") {
|
|
214
|
-
return value;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return null;
|
|
219
|
-
};
|
|
220
|
-
export { Project };
|
|
204
|
+
export { Project, generatePrompt, checkForEnvArg };
|
package/bin/logger.js
CHANGED
|
@@ -17,8 +17,8 @@ function formatWithInspect(val) {
|
|
|
17
17
|
let alignColorsAndTime = null;
|
|
18
18
|
let fileRotateTransport = null;
|
|
19
19
|
let errorFileRotateTransport = null;
|
|
20
|
-
export let logger = null;
|
|
21
20
|
function initLogger() {
|
|
21
|
+
let logger = null;
|
|
22
22
|
try {
|
|
23
23
|
alignColorsAndTime = format.combine(
|
|
24
24
|
format.timestamp({
|
|
@@ -59,9 +59,10 @@ function initLogger() {
|
|
|
59
59
|
console.log(error);
|
|
60
60
|
logger = console;
|
|
61
61
|
}
|
|
62
|
+
return logger;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
initLogger();
|
|
65
|
+
export const logger = initLogger();
|
|
65
66
|
const changeToTaskLogger = (logFile) => {
|
|
66
67
|
logger.remove(fileRotateTransport);
|
|
67
68
|
fileRotateTransport.filename = logFile;
|