@empiricalrun/test-gen 0.29.3 → 0.30.2
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 +24 -0
- package/dist/agent/browsing/utils.d.ts.map +1 -1
- package/dist/agent/browsing/utils.js +6 -0
- package/dist/agent/codegen/run.d.ts.map +1 -1
- package/dist/agent/codegen/run.js +7 -2
- package/dist/agent/codegen/update-flow.d.ts.map +1 -1
- package/dist/agent/codegen/update-flow.js +1 -1
- package/dist/bin/utils/platform/web/index.d.ts +6 -1
- package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
- package/dist/bin/utils/platform/web/index.js +47 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @empiricalrun/test-gen
|
|
2
2
|
|
|
3
|
+
## 0.30.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [0541f38]
|
|
8
|
+
- @empiricalrun/reporter@0.19.0
|
|
9
|
+
|
|
10
|
+
## 0.30.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- e07dd51: fix: remove redundant suites arg from stripAndPrependImports util
|
|
15
|
+
- 69f3aa9: fix: add test for injectCodeSnippetBySuiteChain util
|
|
16
|
+
|
|
17
|
+
## 0.30.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- c367dcb: feat: support nested new test-block creation via master agent
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 56f3d2f: feat: support nested new test-block creation via coding agent
|
|
26
|
+
|
|
3
27
|
## 0.29.3
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAYvD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AAsDD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,aAAa,GACvB,OAAO,CAAC,MAAM,CAAC,CA2CjB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBAiBxD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,QA6BjD;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAM1E;AAWD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,oBAAoB,GACrC,OAAO,CAAC,MAAM,CAAC,CA8CjB;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,YAAiB,EACjB,IAAS,EACT,eAAoB,EACpB,gBAAqB,EACrB,UAAyC,GAC1C,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,8EASA"}
|
|
@@ -92,6 +92,12 @@ async function prepareFileForMasterAgent(genConfig) {
|
|
|
92
92
|
options: genConfig.options,
|
|
93
93
|
});
|
|
94
94
|
await fs_extra_1.default.writeFile(specPath, `${existingContents} \n\n ${newTestBlock}`, "utf-8");
|
|
95
|
+
const updatedContent = (0, web_1.injectCodeSnippetBySuiteChain)({
|
|
96
|
+
testFileContent: existingContents,
|
|
97
|
+
suites: testCase.suites,
|
|
98
|
+
codeSnippet: `\n\n${newTestBlock}`,
|
|
99
|
+
});
|
|
100
|
+
await fs_extra_1.default.writeFile(specPath, updatedContent, "utf-8");
|
|
95
101
|
}
|
|
96
102
|
await prepareFileForUpdateScenario(genConfig);
|
|
97
103
|
return specPath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/run.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAI7D,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,EAAE,CAAC,CAuGrB"}
|
|
@@ -77,8 +77,13 @@ async function generateTest(testCase, file, options) {
|
|
|
77
77
|
logger.success("Test generated successfully!");
|
|
78
78
|
const readWriteFileSpan = trace.span({ name: "write-to-file" });
|
|
79
79
|
let contents = fs_extra_1.default.readFileSync(file, "utf-8");
|
|
80
|
-
const [prependContent, strippedContent] = await (0, web_1.stripAndPrependImports)(response, testCase?.name
|
|
81
|
-
let updatedContent = prependContent +
|
|
80
|
+
const [prependContent, strippedContent] = await (0, web_1.stripAndPrependImports)(response, testCase?.name);
|
|
81
|
+
let updatedContent = prependContent +
|
|
82
|
+
(0, web_1.injectCodeSnippetBySuiteChain)({
|
|
83
|
+
testFileContent: contents,
|
|
84
|
+
suites: testCase?.suites,
|
|
85
|
+
codeSnippet: `\n\n${strippedContent}`,
|
|
86
|
+
});
|
|
82
87
|
await fs_extra_1.default.writeFile(file, updatedContent, "utf-8");
|
|
83
88
|
readWriteFileSpan.end({ output: { updatedContent } });
|
|
84
89
|
logger.log("Linting generated code...");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-flow.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/update-flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAmB3B,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAI7D,KAAK,eAAe,GAAG,QAAQ,GAAG;IAChC,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;
|
|
1
|
+
{"version":3,"file":"update-flow.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/update-flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAmB3B,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAI7D,KAAK,eAAe,GAAG,QAAQ,GAAG;IAChC,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAkHF,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,GAAG,SAAS,EACzC,OAAO,GAAE,OAAc,EACvB,QAAQ,GAAE,OAAc,GACvB,OAAO,CAAC,eAAe,EAAE,CAAC,CAuF5B;AAED,wBAAsB,qBAAqB,CAAC,EAC1C,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,KAAK,EACL,aAAoB,GACrB,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAiE7B"}
|
|
@@ -30,7 +30,7 @@ async function applyFileChanges({ validateTypes = true, trace, testCase, fileCha
|
|
|
30
30
|
// maintaining the previous accuracy of the test case update
|
|
31
31
|
const readWriteFileSpan = trace.span({ name: "write-to-file" });
|
|
32
32
|
let contents = await fs_extra_1.default.readFile(fileChange.filePath, "utf-8");
|
|
33
|
-
const [prependContent, strippedContent] = await (0, web_1.stripAndPrependImports)(fileChange.newCode, testCase?.name
|
|
33
|
+
const [prependContent, strippedContent] = await (0, web_1.stripAndPrependImports)(fileChange.newCode, testCase?.name);
|
|
34
34
|
let updatedContent = prependContent + contents + `\n\n${strippedContent}`;
|
|
35
35
|
const { testBlock } = (0, web_1.getTypescriptTestBlock)({
|
|
36
36
|
scenarioName: testCase?.name,
|
|
@@ -40,7 +40,7 @@ export declare function getTypescriptTestBlock({ scenarioName, suites, content,
|
|
|
40
40
|
export declare function findFirstSerialDescribeBlock(node: Node | undefined): Node | undefined;
|
|
41
41
|
export declare function appendToTestBlock(testBlock: string, content: string): string;
|
|
42
42
|
export declare function validateTypescript(filePath: string): string[];
|
|
43
|
-
export declare function stripAndPrependImports(content: string, testName: string
|
|
43
|
+
export declare function stripAndPrependImports(content: string, testName: string): Promise<(string | undefined)[]>;
|
|
44
44
|
export declare function lintErrors(filePath: string): Promise<void>;
|
|
45
45
|
export declare function formatCode(filePath: string): Promise<void>;
|
|
46
46
|
export declare function addNewImport(contents: string, modules: string[], pkg: string): string;
|
|
@@ -48,4 +48,9 @@ export declare function removeTestOnly(filePath: string): Promise<void>;
|
|
|
48
48
|
export declare function getFixtureImportPath(filePath: string): string;
|
|
49
49
|
export declare function getPageVariableNameFromCreateTest(filePath: string): Promise<string | undefined>;
|
|
50
50
|
export declare function replaceCreateTestWithNewCode(filePath: string, contents: string, generatedCode: string): string;
|
|
51
|
+
export declare const injectCodeSnippetBySuiteChain: ({ testFileContent, codeSnippet, suites, }: {
|
|
52
|
+
testFileContent: string;
|
|
53
|
+
codeSnippet: string;
|
|
54
|
+
suites: string[];
|
|
55
|
+
}) => string;
|
|
51
56
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,IAAI,EAIL,MAAM,UAAU,CAAC;AAGlB;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,YAAY,EACZ,MAAM,EACN,OAAO,GACR,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG;IACF,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,QAAQ,EAAE,IAAI,GAAG,SAAS,CAAC;CAC5B,CAuCA;AAwBD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,IAAI,GAAG,SAAS,GACrB,IAAI,GAAG,SAAS,CA4BlB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CA8C7D;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,mCAWjB;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAShD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAQhD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,UAE5E;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,iBAMpD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,UAcpD;AAED,wBAAsB,iCAAiC,CAAC,QAAQ,EAAE,MAAM,+BAmBvE;AAED,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,UA0CtB;AAED,eAAO,MAAM,6BAA6B;qBAKvB,MAAM;iBACV,MAAM;YACX,MAAM,EAAE;YA2DjB,CAAC"}
|
|
@@ -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.replaceCreateTestWithNewCode = exports.getPageVariableNameFromCreateTest = exports.getFixtureImportPath = exports.removeTestOnly = exports.addNewImport = exports.formatCode = exports.lintErrors = exports.stripAndPrependImports = exports.validateTypescript = exports.appendToTestBlock = exports.findFirstSerialDescribeBlock = exports.getTypescriptTestBlock = void 0;
|
|
6
|
+
exports.injectCodeSnippetBySuiteChain = exports.replaceCreateTestWithNewCode = exports.getPageVariableNameFromCreateTest = exports.getFixtureImportPath = exports.removeTestOnly = exports.addNewImport = exports.formatCode = exports.lintErrors = exports.stripAndPrependImports = exports.validateTypescript = exports.appendToTestBlock = exports.findFirstSerialDescribeBlock = exports.getTypescriptTestBlock = void 0;
|
|
7
7
|
const eslint_1 = require("eslint");
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
@@ -166,13 +166,13 @@ function validateTypescript(filePath) {
|
|
|
166
166
|
return errors;
|
|
167
167
|
}
|
|
168
168
|
exports.validateTypescript = validateTypescript;
|
|
169
|
-
async function stripAndPrependImports(content, testName
|
|
169
|
+
async function stripAndPrependImports(content, testName) {
|
|
170
170
|
const importRegexp = /import\s+\{[^}]*\}\s+from\s+["'][^"']+["'];?/g;
|
|
171
171
|
const imports = content.match(importRegexp);
|
|
172
172
|
const { testBlock: strippedContent } = getTypescriptTestBlock({
|
|
173
173
|
scenarioName: testName,
|
|
174
174
|
content,
|
|
175
|
-
suites,
|
|
175
|
+
suites: [], // since this method is called on the generated content, not the whole file
|
|
176
176
|
});
|
|
177
177
|
const prependContent = (imports?.join("\n") || "") + "\n\n";
|
|
178
178
|
return [prependContent, strippedContent];
|
|
@@ -272,3 +272,47 @@ function replaceCreateTestWithNewCode(filePath, contents, generatedCode) {
|
|
|
272
272
|
return updatedTestFile;
|
|
273
273
|
}
|
|
274
274
|
exports.replaceCreateTestWithNewCode = replaceCreateTestWithNewCode;
|
|
275
|
+
const injectCodeSnippetBySuiteChain = ({ testFileContent, codeSnippet, suites, }) => {
|
|
276
|
+
const project = new ts_morph_1.Project();
|
|
277
|
+
// Add the source file content directly into memory
|
|
278
|
+
const sourceFile = project.createSourceFile("test-file.ts", testFileContent);
|
|
279
|
+
// Function to insert the test into the appropriate describe block
|
|
280
|
+
let parentNode = sourceFile;
|
|
281
|
+
if (!suites.length) {
|
|
282
|
+
parentNode.addStatements(codeSnippet);
|
|
283
|
+
return sourceFile.getFullText();
|
|
284
|
+
}
|
|
285
|
+
suites.forEach((suiteName, index) => {
|
|
286
|
+
// Try to find the describe block with the given name
|
|
287
|
+
let describeBlock = parentNode
|
|
288
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
|
|
289
|
+
.find((callExpr) => {
|
|
290
|
+
const expression = callExpr.getExpression();
|
|
291
|
+
const firstArg = callExpr?.getArguments()?.[0];
|
|
292
|
+
return (expression?.getText() === "test.describe" &&
|
|
293
|
+
firstArg?.getLiteralText() === suiteName);
|
|
294
|
+
});
|
|
295
|
+
// If the describe block doesn't exist, create it
|
|
296
|
+
if (!describeBlock) {
|
|
297
|
+
const newDescribe = `\n\ntest.describe("${suiteName}", () => {});`;
|
|
298
|
+
parentNode.addStatements(newDescribe);
|
|
299
|
+
describeBlock = parentNode
|
|
300
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
|
|
301
|
+
.find((callExpr) => {
|
|
302
|
+
const expression = callExpr.getExpression();
|
|
303
|
+
const firstArg = callExpr?.getArguments()?.[0];
|
|
304
|
+
return (expression?.getText() === "test.describe" &&
|
|
305
|
+
firstArg?.getLiteralText() === suiteName);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
// If it's the last in the chain, add the test block inside this describe
|
|
309
|
+
if (index === suites.length - 1) {
|
|
310
|
+
const block = describeBlock?.getArguments()[1];
|
|
311
|
+
block.addStatements(codeSnippet);
|
|
312
|
+
}
|
|
313
|
+
// Update parentNode to navigate deeper into nested describe blocks
|
|
314
|
+
parentNode = describeBlock.getArguments()[1];
|
|
315
|
+
});
|
|
316
|
+
return sourceFile.getFullText();
|
|
317
|
+
};
|
|
318
|
+
exports.injectCodeSnippetBySuiteChain = injectCodeSnippetBySuiteChain;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/test-gen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"typescript": "^5.3.3",
|
|
47
47
|
"@empiricalrun/llm": "^0.9.2",
|
|
48
48
|
"@empiricalrun/r2-uploader": "^0.3.1",
|
|
49
|
-
"@empiricalrun/reporter": "^0.
|
|
49
|
+
"@empiricalrun/reporter": "^0.19.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/detect-port": "^1.3.5",
|