@empiricalrun/test-gen 0.41.2 → 0.41.6
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 +25 -0
- package/dist/agent/codegen/repo-edit.d.ts.map +1 -1
- package/dist/agent/codegen/repo-edit.js +5 -32
- package/dist/agent/codegen/utils.d.ts +30 -0
- package/dist/agent/codegen/utils.d.ts.map +1 -1
- package/dist/agent/codegen/utils.js +85 -18
- package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
- package/dist/bin/utils/platform/web/index.js +34 -12
- package/dist/reporter/index.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @empiricalrun/test-gen
|
|
2
2
|
|
|
3
|
+
## 0.41.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cee101c: fix: search and replace code for repo edit agent
|
|
8
|
+
|
|
9
|
+
## 0.41.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- da4d7f1: fix: added strict check for project repo name
|
|
14
|
+
|
|
15
|
+
## 0.41.4
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 399f968: test: fix eslint mock test output
|
|
20
|
+
- 4c35992: fix: import statements with alias were getting removed from file
|
|
21
|
+
|
|
22
|
+
## 0.41.3
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- 1d39892: fix: repo edit exception
|
|
27
|
+
|
|
3
28
|
## 0.41.2
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repo-edit.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/repo-edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"repo-edit.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/repo-edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAexE,wBAAsB,0BAA0B,CAAC,EAC/C,IAAI,EACJ,KAAK,EACL,SAAS,GACV,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE;QACX,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;QAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;KAC5B,EAAE,CAAC;CACL,CAAC,CA6GD;AAED,wBAAsB,aAAa,CAAC,EAClC,KAAK,EACL,IAAI,GACL,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE;QACX,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;QAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;KAC5B,EAAE,CAAC;CACL,CAAC,CAiED"}
|
|
@@ -1,34 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
6
|
exports.repoEditAgent = exports.generateCodeUsingRepoAgent = void 0;
|
|
30
7
|
const llm_1 = require("@empiricalrun/llm");
|
|
31
|
-
const fsSync = __importStar(require("fs"));
|
|
32
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
33
9
|
const path_1 = require("path");
|
|
34
10
|
const context_1 = require("../../bin/utils/context");
|
|
@@ -147,7 +123,6 @@ Task: ${task}
|
|
|
147
123
|
}
|
|
148
124
|
exports.generateCodeUsingRepoAgent = generateCodeUsingRepoAgent;
|
|
149
125
|
async function repoEditAgent({ trace, task, }) {
|
|
150
|
-
console.log("mock test", fs_extra_1.default.readdir(""));
|
|
151
126
|
const testgenUpdatesReporter = new reporter_1.TestGenUpdatesReporter();
|
|
152
127
|
void testgenUpdatesReporter.sendMessage(`Updating test code as per the task. \n View [trace](${trace?.getTraceUrl()})`);
|
|
153
128
|
const { prompt: repoFiles } = await (0, context_1.generateTxtForRepository)();
|
|
@@ -157,10 +132,9 @@ async function repoEditAgent({ trace, task, }) {
|
|
|
157
132
|
repoFiles,
|
|
158
133
|
});
|
|
159
134
|
const updates = repoAgentOutput.fileChanges;
|
|
160
|
-
const fileUpdateResponses = await (0, utils_1.
|
|
135
|
+
const fileUpdateResponses = await (0, utils_1.applyFileChangesForRepoEdit)({
|
|
161
136
|
trace,
|
|
162
|
-
|
|
163
|
-
fileChanges: updates.filter((f) => f.filePath && fsSync.existsSync(f.filePath)),
|
|
137
|
+
fileChanges: updates.filter((f) => f.filePath && fs_extra_1.default.existsSync(f.filePath)),
|
|
164
138
|
});
|
|
165
139
|
const errorResponses = fileUpdateResponses.filter((f) => f?.error);
|
|
166
140
|
if (errorResponses.length > 0) {
|
|
@@ -173,13 +147,12 @@ async function repoEditAgent({ trace, task, }) {
|
|
|
173
147
|
errorMessage: e?.errorMessage,
|
|
174
148
|
})),
|
|
175
149
|
});
|
|
176
|
-
await (0, utils_1.
|
|
150
|
+
await (0, utils_1.applyFileChangesForRepoEdit)({
|
|
177
151
|
trace,
|
|
178
|
-
testCase: {},
|
|
179
152
|
fileChanges: updatedFileChanges,
|
|
180
153
|
});
|
|
181
154
|
}
|
|
182
|
-
const newFileUpdates = updates.filter((f) => !
|
|
155
|
+
const newFileUpdates = updates.filter((f) => !fs_extra_1.default.existsSync(f.filePath));
|
|
183
156
|
await Promise.all(newFileUpdates.map((f) => {
|
|
184
157
|
return (async () => {
|
|
185
158
|
await fs_extra_1.default.mkdir((0, path_1.dirname)(f.filePath), { recursive: true });
|
|
@@ -194,7 +167,7 @@ async function repoEditAgent({ trace, task, }) {
|
|
|
194
167
|
});
|
|
195
168
|
await Promise.all(updates.map((f) => {
|
|
196
169
|
return (async () => {
|
|
197
|
-
if (
|
|
170
|
+
if (fs_extra_1.default.existsSync(f.filePath)) {
|
|
198
171
|
await (0, web_1.lintErrors)(f.filePath);
|
|
199
172
|
}
|
|
200
173
|
})();
|
|
@@ -88,4 +88,34 @@ export declare function getTaskForCreateTest({ testCase, file, }: {
|
|
|
88
88
|
testCase: TestCase;
|
|
89
89
|
file: string;
|
|
90
90
|
}): string;
|
|
91
|
+
export declare function applyFileChangesForRepoEdit({ trace, fileChanges, logger, }: {
|
|
92
|
+
trace?: TraceClient;
|
|
93
|
+
fileChanges: {
|
|
94
|
+
filePath: string | undefined;
|
|
95
|
+
oldCode: string | undefined;
|
|
96
|
+
newCode: string | undefined;
|
|
97
|
+
reason: string | undefined;
|
|
98
|
+
}[];
|
|
99
|
+
logger?: CustomLogger;
|
|
100
|
+
}): Promise<{
|
|
101
|
+
error: boolean;
|
|
102
|
+
errorMessage: string;
|
|
103
|
+
filePath: string;
|
|
104
|
+
}[]>;
|
|
105
|
+
export declare function searchAndReplaceCode({ logger, fileChange, }: {
|
|
106
|
+
fileChange: {
|
|
107
|
+
filePath: string | undefined;
|
|
108
|
+
oldCode: string | undefined;
|
|
109
|
+
newCode: string | undefined;
|
|
110
|
+
reason: string | undefined;
|
|
111
|
+
};
|
|
112
|
+
logger?: CustomLogger;
|
|
113
|
+
}): Promise<{
|
|
114
|
+
result: {
|
|
115
|
+
error: boolean;
|
|
116
|
+
errorMessage: string;
|
|
117
|
+
filePath: string;
|
|
118
|
+
};
|
|
119
|
+
updatedContent: string;
|
|
120
|
+
}>;
|
|
91
121
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIh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E,MAAM,GAAG,SAAS,CAAC;QAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;KAC5B,CAAC;IACF,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC,CA6BD"}
|
|
@@ -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.getTaskForCreateTest = exports.validateTypesAndFormatCode = exports.applyFileChanges = exports.extractTestStepsSuggestions = exports.extractAppendTestUpdates = exports.extractTestUpdates = void 0;
|
|
6
|
+
exports.searchAndReplaceCode = exports.applyFileChangesForRepoEdit = exports.getTaskForCreateTest = exports.validateTypesAndFormatCode = exports.applyFileChanges = exports.extractTestStepsSuggestions = exports.extractAppendTestUpdates = exports.extractTestUpdates = void 0;
|
|
7
7
|
const llm_1 = require("@empiricalrun/llm");
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const ts_morph_1 = require("ts-morph");
|
|
@@ -162,30 +162,27 @@ async function applyFileChanges({ trace, testCase, fileChanges, logger, }) {
|
|
|
162
162
|
contents = originalSource.getFullText();
|
|
163
163
|
}
|
|
164
164
|
else {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
165
|
+
const { result, updatedContent } = await searchAndReplaceCode({
|
|
166
|
+
logger,
|
|
167
|
+
fileChange,
|
|
168
|
+
});
|
|
169
|
+
if (result.error) {
|
|
172
170
|
logger?.error(`Unable to find the code to update in ${fileChange.filePath}`);
|
|
173
|
-
results.push(
|
|
174
|
-
filePath: fileChange.filePath,
|
|
175
|
-
error: true,
|
|
176
|
-
errorMessage: `The content of "old_code_block" corresponding to file path "${fileChange.filePath}" did not match the current content of the file "${fileChange.filePath}"`,
|
|
177
|
-
});
|
|
171
|
+
results.push(result);
|
|
178
172
|
continue;
|
|
179
173
|
}
|
|
174
|
+
else {
|
|
175
|
+
contents = updatedContent;
|
|
176
|
+
}
|
|
180
177
|
}
|
|
181
178
|
await fs_extra_1.default.writeFile(fileChange.filePath, contents, "utf-8");
|
|
182
179
|
readWriteFileSpan?.end({ output: { contents } });
|
|
180
|
+
results.push({
|
|
181
|
+
filePath: fileChange.filePath,
|
|
182
|
+
error: false,
|
|
183
|
+
errorMessage: "",
|
|
184
|
+
});
|
|
183
185
|
}
|
|
184
|
-
results.push({
|
|
185
|
-
filePath: fileChange.filePath,
|
|
186
|
-
error: false,
|
|
187
|
-
errorMessage: "",
|
|
188
|
-
});
|
|
189
186
|
}
|
|
190
187
|
catch (e) {
|
|
191
188
|
trace?.event({
|
|
@@ -242,3 +239,73 @@ ${testCase.steps.join("\n")}
|
|
|
242
239
|
`;
|
|
243
240
|
}
|
|
244
241
|
exports.getTaskForCreateTest = getTaskForCreateTest;
|
|
242
|
+
async function applyFileChangesForRepoEdit({ trace, fileChanges, logger, }) {
|
|
243
|
+
const repoEditFileChangesSpan = trace?.span({
|
|
244
|
+
name: "repo-edit-file-changes",
|
|
245
|
+
});
|
|
246
|
+
const results = [];
|
|
247
|
+
for (const fileChange of fileChanges) {
|
|
248
|
+
if (!fileChange.filePath) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
const readWriteFileSpan = repoEditFileChangesSpan?.span({
|
|
253
|
+
name: "write-to-file",
|
|
254
|
+
input: {
|
|
255
|
+
fileChange,
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
const { result, updatedContent } = await searchAndReplaceCode({
|
|
259
|
+
logger,
|
|
260
|
+
fileChange,
|
|
261
|
+
});
|
|
262
|
+
if (result.error) {
|
|
263
|
+
logger?.error(`Unable to find the code to update in ${result.filePath}`);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
await fs_extra_1.default.writeFile(fileChange.filePath, updatedContent, "utf-8");
|
|
267
|
+
readWriteFileSpan?.end({ output: { updatedContent } });
|
|
268
|
+
}
|
|
269
|
+
results.push(result);
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
trace?.event({
|
|
273
|
+
name: "repo-edit-file-changes-error",
|
|
274
|
+
output: {
|
|
275
|
+
filePath: fileChange.filePath,
|
|
276
|
+
error: e,
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
console.error(`Error while applying changes to file ${fileChange.filePath}`, e);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return results;
|
|
283
|
+
}
|
|
284
|
+
exports.applyFileChangesForRepoEdit = applyFileChangesForRepoEdit;
|
|
285
|
+
async function searchAndReplaceCode({ logger, fileChange, }) {
|
|
286
|
+
let contents = await fs_extra_1.default.readFile(fileChange.filePath, "utf-8");
|
|
287
|
+
// since we dont know what is getting updated,
|
|
288
|
+
// we believe that the patch is correct and contains few before and after lines
|
|
289
|
+
// to make the change unique for search & replace
|
|
290
|
+
if (contents.includes(fileChange.oldCode)) {
|
|
291
|
+
const updatedContent = contents.replace(fileChange.oldCode, `\n\n${fileChange.newCode}`);
|
|
292
|
+
return {
|
|
293
|
+
result: {
|
|
294
|
+
error: false,
|
|
295
|
+
errorMessage: "",
|
|
296
|
+
filePath: fileChange.filePath,
|
|
297
|
+
},
|
|
298
|
+
updatedContent,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
logger?.error(`Unable to find the code to update in ${fileChange.filePath}`);
|
|
302
|
+
return {
|
|
303
|
+
result: {
|
|
304
|
+
error: true,
|
|
305
|
+
errorMessage: `The content of "old_code_block" corresponding to file path "${fileChange.filePath}" did not match the current content of the file "${fileChange.filePath}"`,
|
|
306
|
+
filePath: fileChange.filePath,
|
|
307
|
+
},
|
|
308
|
+
updatedContent: contents,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
exports.searchAndReplaceCode = searchAndReplaceCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhD,OAAO,EAGL,IAAI,EAEJ,UAAU,EAEX,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,eAAO,MAAM,gCAAgC,eAC/B,UAAU,KACrB,MAgBF,CAAC;AAEF;;;;;;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;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB,CA2CA;AAwBD,wBAAsB,0CAA0C,CAC9D,QAAQ,EAAE,MAAM,oBA+BjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,IAAI,GAAG,SAAS,GACrB,IAAI,GAAG,SAAS,CA4BlB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,E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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;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQnD"}
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.isSyntaxValid = exports.getVariableDeclarationsFromCode = exports.buildTestNamePrompt = exports.isTestPresent = exports.appendScopeToCreateTest = exports.addUserContextFixture = exports.importAllExportsStmtFromFilePaths = 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.hasTopLevelDescribeConfigureWithSerialMode = exports.getTypescriptTestBlock = exports.getTestModuleAliasFromSourceFile = void 0;
|
|
7
7
|
const parser_1 = require("@babel/parser");
|
|
8
8
|
const eslint_1 = require("eslint");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
10
|
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
12
11
|
const path_1 = __importDefault(require("path"));
|
|
@@ -177,7 +176,7 @@ exports.appendToTestBlock = appendToTestBlock;
|
|
|
177
176
|
function validateTypescript(filePath) {
|
|
178
177
|
// Create a compiler host to read files
|
|
179
178
|
const compilerHost = typescript_1.default.createCompilerHost({});
|
|
180
|
-
compilerHost.readFile = (file) =>
|
|
179
|
+
compilerHost.readFile = (file) => fs_extra_1.default.readFileSync(file, "utf8");
|
|
181
180
|
// Create a program with a single source file
|
|
182
181
|
const program = typescript_1.default.createProgram([filePath], {
|
|
183
182
|
esModuleInterop: true,
|
|
@@ -301,6 +300,34 @@ async function getPageVariableNameFromCreateTest(filePath) {
|
|
|
301
300
|
return pageVariableName?.split(" ")[0];
|
|
302
301
|
}
|
|
303
302
|
exports.getPageVariableNameFromCreateTest = getPageVariableNameFromCreateTest;
|
|
303
|
+
function resolveImportsFromFixtures({ fixtureImportNode, testAlias, filePath, updatedTestFile, }) {
|
|
304
|
+
const imports = {};
|
|
305
|
+
const importClause = fixtureImportNode.getImportClause();
|
|
306
|
+
if (!importClause) {
|
|
307
|
+
return updatedTestFile;
|
|
308
|
+
}
|
|
309
|
+
const namedImports = importClause.getNamedImports().map((imp) => {
|
|
310
|
+
// aliasNode is truthy if the import is aliased (e.g. import { test as setup } ...)
|
|
311
|
+
const aliasNode = imp.getAliasNode();
|
|
312
|
+
const originalImportName = imp.getName();
|
|
313
|
+
const aliasImportName = aliasNode?.getText();
|
|
314
|
+
const importName = aliasImportName || originalImportName;
|
|
315
|
+
imports[originalImportName] = imp.getText();
|
|
316
|
+
return importName;
|
|
317
|
+
});
|
|
318
|
+
const isComplete = namedImports.includes(testAlias) && namedImports.includes("expect");
|
|
319
|
+
if (!isComplete) {
|
|
320
|
+
if (!Object.keys(imports).includes("test")) {
|
|
321
|
+
imports["test"] = "test";
|
|
322
|
+
}
|
|
323
|
+
if (!Object.keys(imports).includes("expect")) {
|
|
324
|
+
imports["expect"] = "expect";
|
|
325
|
+
}
|
|
326
|
+
const expectedImports = `import { ${Object.values(imports).join(", ")} } from "${getFixtureImportPath(filePath)}";`;
|
|
327
|
+
updatedTestFile = updatedTestFile.replace(fixtureImportNode.getText(), expectedImports);
|
|
328
|
+
}
|
|
329
|
+
return updatedTestFile;
|
|
330
|
+
}
|
|
304
331
|
function replaceCreateTestWithNewCode(filePath, contents, generatedCode) {
|
|
305
332
|
const project = new ts_morph_1.Project();
|
|
306
333
|
const sourceFile = project.createSourceFile("test.ts", contents);
|
|
@@ -317,17 +344,12 @@ function replaceCreateTestWithNewCode(filePath, contents, generatedCode) {
|
|
|
317
344
|
const fixtureImportNode = sourceFile.getFirstDescendant((node) => !!(node.isKind(ts_morph_1.SyntaxKind.ImportDeclaration) &&
|
|
318
345
|
node.getText().includes("fixtures")));
|
|
319
346
|
if (fixtureImportNode) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
347
|
+
updatedTestFile = resolveImportsFromFixtures({
|
|
348
|
+
fixtureImportNode,
|
|
349
|
+
testAlias,
|
|
350
|
+
filePath,
|
|
351
|
+
updatedTestFile,
|
|
325
352
|
});
|
|
326
|
-
const isComplete = namedImports.includes(testAlias) && namedImports.includes("expect");
|
|
327
|
-
if (!isComplete) {
|
|
328
|
-
const expectedImports = `import { test, expect } from "${getFixtureImportPath(filePath)}";`;
|
|
329
|
-
updatedTestFile = updatedTestFile.replace(fixtureImportNode.getText(), expectedImports);
|
|
330
|
-
}
|
|
331
353
|
}
|
|
332
354
|
return updatedTestFile;
|
|
333
355
|
}
|
package/dist/reporter/index.js
CHANGED
|
@@ -95,7 +95,7 @@ class TestGenUpdatesReporter {
|
|
|
95
95
|
logger.log("Skipped uploading current view screenshot");
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
|
-
if (!reporterConfig) {
|
|
98
|
+
if (!reporterConfig?.projectRepoName) {
|
|
99
99
|
logger.log("Reporter config is not set skipping screenshot uploads.");
|
|
100
100
|
return;
|
|
101
101
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/test-gen",
|
|
3
|
-
"version": "0.41.
|
|
3
|
+
"version": "0.41.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"tsx": "^4.16.2",
|
|
73
73
|
"typescript": "^5.3.3",
|
|
74
74
|
"@empiricalrun/llm": "^0.9.29",
|
|
75
|
-
"@empiricalrun/
|
|
76
|
-
"@empiricalrun/
|
|
75
|
+
"@empiricalrun/r2-uploader": "^0.3.8",
|
|
76
|
+
"@empiricalrun/reporter": "^0.22.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@playwright/test": "1.49.1",
|