@empiricalrun/test-gen 0.38.10 → 0.38.13
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/CHANGELOG.md +20 -0
- package/browser-injected-scripts/annotate-elements.js +23 -17
- package/dist/actions/skill.d.ts.map +1 -1
- package/dist/actions/skill.js +8 -4
- package/dist/agent/browsing/utils.js +5 -5
- package/dist/agent/codegen/fix-ts-errors.d.ts +2 -2
- package/dist/agent/codegen/fix-ts-errors.d.ts.map +1 -1
- package/dist/agent/codegen/fix-ts-errors.js +4 -4
- package/dist/agent/codegen/run.js +2 -2
- package/dist/agent/codegen/update-flow.js +6 -6
- package/dist/bin/utils/context.d.ts +1 -0
- package/dist/bin/utils/context.d.ts.map +1 -1
- package/dist/bin/utils/context.js +1 -0
- package/dist/bin/utils/fs/index.d.ts +1 -0
- package/dist/bin/utils/fs/index.d.ts.map +1 -1
- package/dist/bin/utils/fs/index.js +18 -1
- package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
- package/dist/bin/utils/platform/web/index.js +14 -18
- package/dist/browser-injected-scripts/annotate-elements.js +23 -17
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @empiricalrun/test-gen
|
|
2
2
|
|
|
3
|
+
## 0.38.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- babf00a: fix: updated check for instance element
|
|
8
|
+
|
|
9
|
+
## 0.38.12
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 3739ba6: fix: userContext not getting imported in case of edit test
|
|
14
|
+
- 368a859: fix: skill wasn't used in case task didn't contain next action details
|
|
15
|
+
- 3d0185e: fix: reduce payload for fix ts error call
|
|
16
|
+
|
|
17
|
+
## 0.38.11
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- fb4c866: fix: parent and child elements getting highlighted
|
|
22
|
+
|
|
3
23
|
## 0.38.10
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -103,8 +103,8 @@ function annotateClickableElements(options = {}) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
// Check if an element is clickable
|
|
106
|
-
function isElementClickable(element) {
|
|
107
|
-
|
|
106
|
+
function isElementClickable(element, windowToAnnotate) {
|
|
107
|
+
if (!(element instanceof windowToAnnotate.Element)) return false;
|
|
108
108
|
|
|
109
109
|
const tagName = element.tagName.toLowerCase();
|
|
110
110
|
let isClickable = false;
|
|
@@ -157,10 +157,27 @@ function annotateClickableElements(options = {}) {
|
|
|
157
157
|
isClickable = true;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
// Tag-specific clickability
|
|
161
|
+
const focusableTags = [
|
|
162
|
+
"a",
|
|
163
|
+
"button",
|
|
164
|
+
"input",
|
|
165
|
+
"select",
|
|
166
|
+
"textarea",
|
|
167
|
+
"object",
|
|
168
|
+
"embed",
|
|
169
|
+
"label",
|
|
170
|
+
"details",
|
|
171
|
+
];
|
|
172
|
+
|
|
160
173
|
// Check for onclick attribute or listener
|
|
161
174
|
if (
|
|
162
|
-
element.hasAttribute("onclick") ||
|
|
163
|
-
typeof element.onclick === "function"
|
|
175
|
+
(element.hasAttribute("onclick") ||
|
|
176
|
+
typeof element.onclick === "function")
|
|
177
|
+
// check for parent element having same on click
|
|
178
|
+
&& element.parentNode.onclick !== element.onclick
|
|
179
|
+
// parent element should not be a focusable tag like button
|
|
180
|
+
&& focusableTags.indexOf(element.parentNode.tagName.toLowerCase()) === -1
|
|
164
181
|
) {
|
|
165
182
|
isClickable = true;
|
|
166
183
|
}
|
|
@@ -210,18 +227,7 @@ function annotateClickableElements(options = {}) {
|
|
|
210
227
|
}
|
|
211
228
|
}
|
|
212
229
|
|
|
213
|
-
|
|
214
|
-
const focusableTags = [
|
|
215
|
-
"a",
|
|
216
|
-
"button",
|
|
217
|
-
"input",
|
|
218
|
-
"select",
|
|
219
|
-
"textarea",
|
|
220
|
-
"object",
|
|
221
|
-
"embed",
|
|
222
|
-
"label",
|
|
223
|
-
"details",
|
|
224
|
-
];
|
|
230
|
+
|
|
225
231
|
if (focusableTags.includes(tagName)) {
|
|
226
232
|
switch (tagName) {
|
|
227
233
|
case "a":
|
|
@@ -374,7 +380,7 @@ function annotateClickableElements(options = {}) {
|
|
|
374
380
|
|
|
375
381
|
// Filter for clickable elements
|
|
376
382
|
const clickableElements = Array.from(windowToAnnotate.document.querySelectorAll("*")).filter((el) => {
|
|
377
|
-
const isClickable = isElementClickable(el);
|
|
383
|
+
const isClickable = isElementClickable(el, windowToAnnotate);
|
|
378
384
|
const isClickNotBlocked = isElementClickNotBlocked(el, windowToAnnotate);
|
|
379
385
|
return isClickable && isClickNotBlocked;
|
|
380
386
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/actions/skill.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,cAAc;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,KAAK,EAAE;IAEnC,kBAAkB;IAIlB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE;CAG7B;AAED,eAAO,MAAM,cAAc,gBAAyB,CAAC;AAErD,eAAO,MAAM,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/actions/skill.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,cAAc;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,KAAK,EAAE;IAEnC,kBAAkB;IAIlB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE;CAG7B;AAED,eAAO,MAAM,cAAc,gBAAyB,CAAC;AAErD,eAAO,MAAM,oBAAoB,EAAE,yBAmHlC,CAAC"}
|
package/dist/actions/skill.js
CHANGED
|
@@ -27,7 +27,7 @@ const skillActionGenerator = (page, options) => {
|
|
|
27
27
|
const availableSkills = exports.testCaseSkills.getAvailableSkills();
|
|
28
28
|
return {
|
|
29
29
|
execute: async ({ args, trace }) => {
|
|
30
|
-
const skill = args
|
|
30
|
+
const { skill, action } = args;
|
|
31
31
|
const [skillDetails] = availableSkills.filter((skillDetails) => skillDetails.testStep === skill);
|
|
32
32
|
if (!skillDetails) {
|
|
33
33
|
throw new Error(`No skill found for skill: ${skill}`);
|
|
@@ -39,7 +39,7 @@ const skillActionGenerator = (page, options) => {
|
|
|
39
39
|
const skillFile = await promises_1.default.readFile(skillFilePath, "utf-8");
|
|
40
40
|
const imports = Object.keys(module);
|
|
41
41
|
const code = await (0, use_skill_1.generateSkillUsageCode)({
|
|
42
|
-
task:
|
|
42
|
+
task: action,
|
|
43
43
|
sampleUsageMethod: skillDetails.usageExample,
|
|
44
44
|
scopeVariablesMapStr: JSON.stringify(options.stateVariables || {}, null, 2),
|
|
45
45
|
pageVariableName: (0, utils_1.getPageVarName)(),
|
|
@@ -97,7 +97,11 @@ const skillActionGenerator = (page, options) => {
|
|
|
97
97
|
properties: {
|
|
98
98
|
reason: {
|
|
99
99
|
type: "string",
|
|
100
|
-
description: "
|
|
100
|
+
description: "Explain how this action will help to complete the task. The reason should align with the task provided",
|
|
101
|
+
},
|
|
102
|
+
action: {
|
|
103
|
+
type: "string",
|
|
104
|
+
description: "Explain the action for which this skill needs to be used. Mention all details about the action so that it could be used by the skill",
|
|
101
105
|
},
|
|
102
106
|
skill: {
|
|
103
107
|
type: "string",
|
|
@@ -107,7 +111,7 @@ const skillActionGenerator = (page, options) => {
|
|
|
107
111
|
.join(", ")}`,
|
|
108
112
|
},
|
|
109
113
|
},
|
|
110
|
-
required: ["reason", "skill"],
|
|
114
|
+
required: ["reason", "action", "skill"],
|
|
111
115
|
},
|
|
112
116
|
},
|
|
113
117
|
},
|
|
@@ -79,12 +79,12 @@ async function prepareFileForUpdateScenario(genConfig, trace) {
|
|
|
79
79
|
});
|
|
80
80
|
await fs_extra_1.default.writeFile(createTestFilePath, (0, web_1.addNewImport)(await fs_extra_1.default.readFile(createTestFilePath, "utf-8"), ["createTest"], "@empiricalrun/test-gen"));
|
|
81
81
|
updateFileSpan?.end();
|
|
82
|
-
const {
|
|
82
|
+
const { pomPrompt, nonSpecFilePrompt } = await (0, context_1.contextForGeneration)(createTestFilePath);
|
|
83
83
|
await (0, fix_ts_errors_1.validateAndFixTypescriptErrors)({
|
|
84
84
|
trace,
|
|
85
85
|
file: createTestFilePath,
|
|
86
|
-
testCode: codePrompt,
|
|
87
86
|
pomCode: pomPrompt,
|
|
87
|
+
nonSpecFileCode: nonSpecFilePrompt,
|
|
88
88
|
testCase: testCase,
|
|
89
89
|
options: genConfig.options,
|
|
90
90
|
});
|
|
@@ -196,7 +196,7 @@ async function injectPwLocatorGenerator(page) {
|
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
198
|
catch (e) {
|
|
199
|
-
console.warn("Error injecting script in iframe
|
|
199
|
+
console.warn("Error injecting script in iframe.");
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
202
|
const iframes = document.getElementsByTagName("iframe");
|
|
@@ -235,7 +235,7 @@ async function injectPwLocatorGenerator(page) {
|
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
237
|
catch (e) {
|
|
238
|
-
console.warn("Error injecting script in iframe:"
|
|
238
|
+
console.warn("Error injecting script in iframe:");
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
const iframes = document.getElementsByTagName("iframe");
|
|
@@ -254,7 +254,7 @@ async function injectPwLocatorGenerator(page) {
|
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
256
|
catch (e) {
|
|
257
|
-
console.warn("Error injecting script in iframe:"
|
|
257
|
+
console.warn("Error injecting script in iframe:");
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
exports.injectPwLocatorGenerator = injectPwLocatorGenerator;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { TraceClient } from "@empiricalrun/llm";
|
|
2
2
|
import { CustomLogger } from "../../bin/logger";
|
|
3
3
|
import { TestCase, TestGenConfigOptions } from "../../types";
|
|
4
|
-
export declare function validateAndFixTypescriptErrors({ trace, logger, file,
|
|
4
|
+
export declare function validateAndFixTypescriptErrors({ trace, logger, file, pomCode, nonSpecFileCode, testCase, options, }: {
|
|
5
5
|
trace?: TraceClient;
|
|
6
6
|
logger?: CustomLogger;
|
|
7
7
|
file: string;
|
|
8
|
-
testCode: string;
|
|
9
8
|
pomCode: string;
|
|
9
|
+
nonSpecFileCode: string;
|
|
10
10
|
testCase: TestCase;
|
|
11
11
|
options?: TestGenConfigOptions;
|
|
12
12
|
}): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix-ts-errors.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/fix-ts-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAQhD,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAAsB,8BAA8B,CAAC,EACnD,KAAK,EACL,MAA2B,EAC3B,IAAI,EACJ,
|
|
1
|
+
{"version":3,"file":"fix-ts-errors.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/fix-ts-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAQhD,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAAsB,8BAA8B,CAAC,EACnD,KAAK,EACL,MAA2B,EAC3B,IAAI,EACJ,OAAO,EACP,eAAe,EACf,QAAQ,EACR,OAAO,GACR,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,iBAwEA"}
|
|
@@ -9,7 +9,7 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
9
9
|
const logger_1 = require("../../bin/logger");
|
|
10
10
|
const web_1 = require("../../bin/utils/platform/web");
|
|
11
11
|
const constants_1 = require("../../constants");
|
|
12
|
-
async function validateAndFixTypescriptErrors({ trace, logger = new logger_1.CustomLogger(), file,
|
|
12
|
+
async function validateAndFixTypescriptErrors({ trace, logger = new logger_1.CustomLogger(), file, pomCode, nonSpecFileCode, testCase, options, }) {
|
|
13
13
|
const validateTypesSpan = trace?.span({ name: "detect-type-errors-in-file" });
|
|
14
14
|
logger.log("Validating types...");
|
|
15
15
|
let errors = (0, web_1.validateTypescript)(file);
|
|
@@ -35,13 +35,13 @@ async function validateAndFixTypescriptErrors({ trace, logger = new logger_1.Cus
|
|
|
35
35
|
errors.forEach((e) => console.warn(e));
|
|
36
36
|
const promptSpan = trace?.span({ name: "fix-type-errors-prompt" });
|
|
37
37
|
const instruction = await (0, llm_1.getPrompt)("fix-file-errors-ts", {
|
|
38
|
-
testFiles: testCode || "",
|
|
39
38
|
pageFiles: pomCode || "",
|
|
39
|
+
fixtureFiles: nonSpecFileCode || "",
|
|
40
40
|
scenarioFile: file,
|
|
41
41
|
errors: errors,
|
|
42
42
|
fileContent: fileContent,
|
|
43
|
-
|
|
44
|
-
});
|
|
43
|
+
scenarioName: testCase.name,
|
|
44
|
+
}, 10);
|
|
45
45
|
promptSpan?.end({ output: { instruction } });
|
|
46
46
|
const llm = new llm_1.LLM({
|
|
47
47
|
trace,
|
|
@@ -48,7 +48,7 @@ async function generateTest(testCase, file, options, trace) {
|
|
|
48
48
|
fs_extra_1.default.createFileSync(file);
|
|
49
49
|
}
|
|
50
50
|
const context = await (0, context_1.contextForGeneration)(file);
|
|
51
|
-
const { codePrompt, pomPrompt, testFileContent } = context;
|
|
51
|
+
const { codePrompt, pomPrompt, nonSpecFilePrompt, testFileContent } = context;
|
|
52
52
|
const { testBlock } = (0, web_1.getTypescriptTestBlock)({
|
|
53
53
|
scenarioName: testCase?.name,
|
|
54
54
|
content: testFileContent,
|
|
@@ -96,8 +96,8 @@ async function generateTest(testCase, file, options, trace) {
|
|
|
96
96
|
trace,
|
|
97
97
|
logger,
|
|
98
98
|
file,
|
|
99
|
-
testCode: codePrompt,
|
|
100
99
|
pomCode: pomPrompt,
|
|
100
|
+
nonSpecFileCode: nonSpecFilePrompt,
|
|
101
101
|
testCase: testCase,
|
|
102
102
|
options,
|
|
103
103
|
});
|
|
@@ -16,7 +16,7 @@ const constants_1 = require("../../constants");
|
|
|
16
16
|
const session_1 = require("../../session");
|
|
17
17
|
const fix_ts_errors_1 = require("./fix-ts-errors");
|
|
18
18
|
const utils_1 = require("./utils");
|
|
19
|
-
async function applyFileChanges({ validateTypes = true, trace, testCase, fileChanges, logger, testGenOptions, pomPrompt,
|
|
19
|
+
async function applyFileChanges({ validateTypes = true, trace, testCase, fileChanges, logger, testGenOptions, pomPrompt, nonSpecFilePrompt, }) {
|
|
20
20
|
await Promise.allSettled(fileChanges.map(async (fileChange) => {
|
|
21
21
|
if (!fileChange.filePath) {
|
|
22
22
|
return;
|
|
@@ -92,8 +92,8 @@ async function applyFileChanges({ validateTypes = true, trace, testCase, fileCha
|
|
|
92
92
|
trace,
|
|
93
93
|
logger,
|
|
94
94
|
file: fileChange.filePath,
|
|
95
|
-
testCode: codePrompt,
|
|
96
95
|
pomCode: pomPrompt,
|
|
96
|
+
nonSpecFileCode: nonSpecFilePrompt,
|
|
97
97
|
testCase: testCase,
|
|
98
98
|
options: testGenOptions,
|
|
99
99
|
});
|
|
@@ -149,7 +149,7 @@ exports.getUpdateTestCodeCompletion = getUpdateTestCodeCompletion;
|
|
|
149
149
|
async function updateTest(testCase, file, options, logging = true, validate = true, trace) {
|
|
150
150
|
const logger = new logger_1.CustomLogger({ useReporter: logging });
|
|
151
151
|
const context = await (0, context_1.contextForGeneration)(file);
|
|
152
|
-
const { codePrompt, pomPrompt, testFileContent } = context;
|
|
152
|
+
const { codePrompt, pomPrompt, nonSpecFilePrompt, testFileContent } = context;
|
|
153
153
|
const generatedTestCases = [];
|
|
154
154
|
logger.logEmptyLine();
|
|
155
155
|
const session = (0, session_1.getSessionDetails)();
|
|
@@ -190,7 +190,7 @@ async function updateTest(testCase, file, options, logging = true, validate = tr
|
|
|
190
190
|
logger,
|
|
191
191
|
testGenOptions: options,
|
|
192
192
|
pomPrompt: pomPrompt,
|
|
193
|
-
|
|
193
|
+
nonSpecFilePrompt: nonSpecFilePrompt,
|
|
194
194
|
});
|
|
195
195
|
if (trace) {
|
|
196
196
|
logger.log(`Trace: ${trace?.getTraceUrl()}`);
|
|
@@ -273,7 +273,7 @@ async function appendCreateTestBlock({ testCase, file, options, trace, validateT
|
|
|
273
273
|
content: scenarioFileContent,
|
|
274
274
|
},
|
|
275
275
|
]);
|
|
276
|
-
const {
|
|
276
|
+
const { pomPrompt, nonSpecFilePrompt } = context;
|
|
277
277
|
const generatedTestCases = [];
|
|
278
278
|
const appendCreateTestResp = await getAppendCreateTestBlockCompletion({
|
|
279
279
|
testCase,
|
|
@@ -291,7 +291,7 @@ async function appendCreateTestBlock({ testCase, file, options, trace, validateT
|
|
|
291
291
|
logger,
|
|
292
292
|
testGenOptions: options,
|
|
293
293
|
pomPrompt: pomPrompt,
|
|
294
|
-
|
|
294
|
+
nonSpecFilePrompt: nonSpecFilePrompt,
|
|
295
295
|
validateTypes,
|
|
296
296
|
});
|
|
297
297
|
if (trace) {
|
|
@@ -2,6 +2,7 @@ export declare function createGitIgnoreFileFilter(): Promise<(pathname: string)
|
|
|
2
2
|
export declare function contextForGeneration(file?: string): Promise<{
|
|
3
3
|
codePrompt: string | undefined;
|
|
4
4
|
pomPrompt: string | undefined;
|
|
5
|
+
nonSpecFilePrompt: string | undefined;
|
|
5
6
|
testFileContent: string;
|
|
6
7
|
}>;
|
|
7
8
|
export declare function fetchAppKnowledge(): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/bin/utils/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/bin/utils/context.ts"],"names":[],"mappings":"AAQA,wBAAsB,yBAAyB,2CAS9C;AAED,wBAAsB,oBAAoB,CAAC,IAAI,CAAC,EAAE,MAAM;;;;;GAQvD;AAED,wBAAsB,iBAAiB,oBAYtC"}
|
|
@@ -23,6 +23,7 @@ async function contextForGeneration(file) {
|
|
|
23
23
|
return {
|
|
24
24
|
codePrompt: await (0, fs_1.generatePromptFromDirectory)("./tests", filter),
|
|
25
25
|
pomPrompt: await (0, fs_1.generatePromptFromDirectory)("./pages", filter),
|
|
26
|
+
nonSpecFilePrompt: await (0, fs_1.generatePromptFromNonSpecFiles)("./tests", filter),
|
|
26
27
|
testFileContent: file ? await fs_extra_1.default.readFile(file, "utf-8") : "",
|
|
27
28
|
};
|
|
28
29
|
}
|
|
@@ -2,4 +2,5 @@ import { FileContent } from "../../../types";
|
|
|
2
2
|
export declare function readFilesInDirectory(dir: string | undefined, filterFunc: (file: string) => boolean): Promise<FileContent[]>;
|
|
3
3
|
export declare function convertFileContentsToString(files?: FileContent[]): string;
|
|
4
4
|
export declare function generatePromptFromDirectory(dir: string | undefined, filterFunc: (file: string) => boolean): Promise<string | undefined>;
|
|
5
|
+
export declare function generatePromptFromNonSpecFiles(dir: string | undefined, filterFunc: (file: string) => boolean): Promise<string | undefined>;
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/bin/utils/fs/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,wBAAsB,oBAAoB,CACxC,GAAG,oBAAa,EAChB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,0BAgBtC;AAED,wBAAgB,2BAA2B,CAAC,KAAK,GAAE,WAAW,EAAO,UAQpE;AAED,wBAAsB,2BAA2B,CAC/C,GAAG,oBAAK,EACR,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,+BAStC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/bin/utils/fs/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,wBAAsB,oBAAoB,CACxC,GAAG,oBAAa,EAChB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,0BAgBtC;AAED,wBAAgB,2BAA2B,CAAC,KAAK,GAAE,WAAW,EAAO,UAQpE;AAED,wBAAsB,2BAA2B,CAC/C,GAAG,oBAAK,EACR,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,+BAStC;AAED,wBAAsB,8BAA8B,CAClD,GAAG,oBAAa,EAChB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,+BAgBtC"}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generatePromptFromDirectory = exports.convertFileContentsToString = exports.readFilesInDirectory = void 0;
|
|
6
|
+
exports.generatePromptFromNonSpecFiles = exports.generatePromptFromDirectory = exports.convertFileContentsToString = exports.readFilesInDirectory = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
async function readFilesInDirectory(dir = "", filterFunc) {
|
|
@@ -44,3 +44,20 @@ async function generatePromptFromDirectory(dir = "", filterFunc) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
exports.generatePromptFromDirectory = generatePromptFromDirectory;
|
|
47
|
+
async function generatePromptFromNonSpecFiles(dir = "", filterFunc) {
|
|
48
|
+
try {
|
|
49
|
+
let nonSpecFiles = [];
|
|
50
|
+
const files = await readFilesInDirectory(dir, filterFunc);
|
|
51
|
+
for (const file of files) {
|
|
52
|
+
if (!file.filePath.endsWith(".spec.ts")) {
|
|
53
|
+
nonSpecFiles.push(file);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const prompt = convertFileContentsToString(nonSpecFiles);
|
|
57
|
+
return prompt;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error("Error reading directory:", error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.generatePromptFromNonSpecFiles = generatePromptFromNonSpecFiles;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL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a,CAAC,EAC5B,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;CACpB,WAYA;AAED,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,UAOA;AAED,wBAAgB,+BAA+B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CA4B5E"}
|
|
@@ -404,29 +404,25 @@ async function addUserContextFixture({ scenarioName, filePath, suites, }) {
|
|
|
404
404
|
return;
|
|
405
405
|
}
|
|
406
406
|
const fileContent = await fs_extra_1.default.readFile(filePath, "utf-8");
|
|
407
|
-
const { testNode
|
|
407
|
+
const { testNode } = getTypescriptTestBlock({
|
|
408
408
|
scenarioName,
|
|
409
409
|
content: fileContent,
|
|
410
410
|
suites,
|
|
411
411
|
});
|
|
412
412
|
const currentBlock = testNode?.getText();
|
|
413
|
-
const
|
|
414
|
-
if (
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
.replace("}", ", userContext }");
|
|
427
|
-
destructuringParam.replaceWithText(updatedImport);
|
|
428
|
-
await fs_extra_1.default.writeFile(filePath, fileContent.replace(currentBlock, testNode.getText()), "utf-8");
|
|
429
|
-
}
|
|
413
|
+
const arrowFunction = testNode?.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ArrowFunction);
|
|
414
|
+
if (arrowFunction) {
|
|
415
|
+
const param = arrowFunction.getParameters()[0]; // Get the first parameter
|
|
416
|
+
const destructuringParam = param?.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ObjectBindingPattern);
|
|
417
|
+
if (destructuringParam) {
|
|
418
|
+
const elements = destructuringParam.getElements();
|
|
419
|
+
const userContextExists = elements.some((e) => e.getText().includes("userContext"));
|
|
420
|
+
if (!userContextExists) {
|
|
421
|
+
const updatedImport = destructuringParam
|
|
422
|
+
.getText()
|
|
423
|
+
.replace("}", ", userContext }");
|
|
424
|
+
destructuringParam.replaceWithText(updatedImport);
|
|
425
|
+
await fs_extra_1.default.writeFile(filePath, fileContent.replace(currentBlock, testNode.getText()), "utf-8");
|
|
430
426
|
}
|
|
431
427
|
}
|
|
432
428
|
}
|
|
@@ -103,8 +103,8 @@ function annotateClickableElements(options = {}) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
// Check if an element is clickable
|
|
106
|
-
function isElementClickable(element) {
|
|
107
|
-
|
|
106
|
+
function isElementClickable(element, windowToAnnotate) {
|
|
107
|
+
if (!(element instanceof windowToAnnotate.Element)) return false;
|
|
108
108
|
|
|
109
109
|
const tagName = element.tagName.toLowerCase();
|
|
110
110
|
let isClickable = false;
|
|
@@ -157,10 +157,27 @@ function annotateClickableElements(options = {}) {
|
|
|
157
157
|
isClickable = true;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
// Tag-specific clickability
|
|
161
|
+
const focusableTags = [
|
|
162
|
+
"a",
|
|
163
|
+
"button",
|
|
164
|
+
"input",
|
|
165
|
+
"select",
|
|
166
|
+
"textarea",
|
|
167
|
+
"object",
|
|
168
|
+
"embed",
|
|
169
|
+
"label",
|
|
170
|
+
"details",
|
|
171
|
+
];
|
|
172
|
+
|
|
160
173
|
// Check for onclick attribute or listener
|
|
161
174
|
if (
|
|
162
|
-
element.hasAttribute("onclick") ||
|
|
163
|
-
typeof element.onclick === "function"
|
|
175
|
+
(element.hasAttribute("onclick") ||
|
|
176
|
+
typeof element.onclick === "function")
|
|
177
|
+
// check for parent element having same on click
|
|
178
|
+
&& element.parentNode.onclick !== element.onclick
|
|
179
|
+
// parent element should not be a focusable tag like button
|
|
180
|
+
&& focusableTags.indexOf(element.parentNode.tagName.toLowerCase()) === -1
|
|
164
181
|
) {
|
|
165
182
|
isClickable = true;
|
|
166
183
|
}
|
|
@@ -210,18 +227,7 @@ function annotateClickableElements(options = {}) {
|
|
|
210
227
|
}
|
|
211
228
|
}
|
|
212
229
|
|
|
213
|
-
|
|
214
|
-
const focusableTags = [
|
|
215
|
-
"a",
|
|
216
|
-
"button",
|
|
217
|
-
"input",
|
|
218
|
-
"select",
|
|
219
|
-
"textarea",
|
|
220
|
-
"object",
|
|
221
|
-
"embed",
|
|
222
|
-
"label",
|
|
223
|
-
"details",
|
|
224
|
-
];
|
|
230
|
+
|
|
225
231
|
if (focusableTags.includes(tagName)) {
|
|
226
232
|
switch (tagName) {
|
|
227
233
|
case "a":
|
|
@@ -374,7 +380,7 @@ function annotateClickableElements(options = {}) {
|
|
|
374
380
|
|
|
375
381
|
// Filter for clickable elements
|
|
376
382
|
const clickableElements = Array.from(windowToAnnotate.document.querySelectorAll("*")).filter((el) => {
|
|
377
|
-
const isClickable = isElementClickable(el);
|
|
383
|
+
const isClickable = isElementClickable(el, windowToAnnotate);
|
|
378
384
|
const isClickNotBlocked = isElementClickNotBlocked(el, windowToAnnotate);
|
|
379
385
|
return isClickable && isClickNotBlocked;
|
|
380
386
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/test-gen",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.13",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
"remove-markdown": "^0.5.5",
|
|
56
56
|
"sanitize-html": "^2.13.0",
|
|
57
57
|
"slugify": "^1.6.6",
|
|
58
|
-
"ts-morph": "^
|
|
58
|
+
"ts-morph": "^24.0.0",
|
|
59
59
|
"tsx": "^4.16.2",
|
|
60
60
|
"typescript": "^5.3.3",
|
|
61
|
+
"@empiricalrun/llm": "^0.9.25",
|
|
61
62
|
"@empiricalrun/r2-uploader": "^0.3.6",
|
|
62
|
-
"@empiricalrun/reporter": "^0.21.3"
|
|
63
|
-
"@empiricalrun/llm": "^0.9.25"
|
|
63
|
+
"@empiricalrun/reporter": "^0.21.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@types/detect-port": "^1.3.5",
|