@empiricalrun/test-gen 0.70.2 → 0.71.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 +34 -0
- package/dist/actions/index.d.ts.map +1 -1
- package/dist/actions/index.js +0 -6
- package/dist/agent/browsing/index.d.ts.map +1 -1
- package/dist/agent/browsing/index.js +6 -14
- package/dist/agent/chat/agent-loop.d.ts +3 -2
- package/dist/agent/chat/agent-loop.d.ts.map +1 -1
- package/dist/agent/chat/agent-loop.js +5 -3
- package/dist/agent/chat/state.d.ts +3 -1
- package/dist/agent/chat/state.d.ts.map +1 -1
- package/dist/agent/chat/state.js +17 -14
- package/dist/agent/codegen/repo-edit.d.ts.map +1 -1
- package/dist/agent/codegen/repo-edit.js +0 -4
- package/dist/agent/codegen/run.d.ts.map +1 -1
- package/dist/agent/codegen/run.js +0 -4
- package/dist/agent/codegen/utils.d.ts +1 -3
- package/dist/agent/codegen/utils.d.ts.map +1 -1
- package/dist/agent/codegen/utils.js +1 -2
- package/dist/agent/cua/index.d.ts +2 -1
- package/dist/agent/cua/index.d.ts.map +1 -1
- package/dist/agent/cua/index.js +4 -4
- package/dist/agent/master/execute-browser-action.d.ts.map +1 -1
- package/dist/agent/master/execute-browser-action.js +1 -4
- package/dist/agent/master/run.d.ts.map +1 -1
- package/dist/agent/master/run.js +0 -19
- package/dist/agent/master/scroller.d.ts.map +1 -1
- package/dist/agent/master/scroller.js +0 -4
- package/dist/bin/environments.d.ts.map +1 -1
- package/dist/bin/environments.js +1 -0
- package/dist/bin/index.js +36 -36
- package/dist/bin/logger/index.d.ts +0 -1
- package/dist/bin/logger/index.d.ts.map +1 -1
- package/dist/bin/logger/index.js +0 -16
- package/dist/bin/setup.d.ts.map +1 -1
- package/dist/bin/setup.js +42 -1
- package/dist/bin/utils/index.d.ts +2 -0
- package/dist/bin/utils/index.d.ts.map +1 -1
- package/dist/bin/utils/index.js +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -6
- package/dist/recorder/request.js +2 -0
- package/dist/tool-call-service/index.d.ts +1 -1
- package/dist/tool-call-service/index.d.ts.map +1 -1
- package/dist/tool-call-service/index.js +3 -7
- package/dist/tool-call-service/utils.js +2 -2
- package/dist/tools/{test-run.d.ts → run-test.d.ts} +1 -1
- package/dist/tools/run-test.d.ts.map +1 -0
- package/dist/tools/{test-run.js → run-test.js} +3 -1
- package/dist/tools/upgrade-packages/index.js +1 -1
- package/package.json +6 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/reporter/index.d.ts +0 -26
- package/dist/reporter/index.d.ts.map +0 -1
- package/dist/reporter/index.js +0 -149
- package/dist/reporter/lib.d.ts +0 -31
- package/dist/reporter/lib.d.ts.map +0 -1
- package/dist/reporter/lib.js +0 -71
- package/dist/tools/test-run.d.ts.map +0 -1
- package/dist/uploader/index.d.ts +0 -26
- package/dist/uploader/index.d.ts.map +0 -1
- package/dist/uploader/index.js +0 -103
- package/dist/uploader/utils.d.ts +0 -8
- package/dist/uploader/utils.d.ts.map +0 -1
- package/dist/uploader/utils.js +0 -35
package/dist/reporter/index.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TestGenUpdatesReporter = void 0;
|
|
7
|
-
exports.getReporter = getReporter;
|
|
8
|
-
exports.setReporterConfig = setReporterConfig;
|
|
9
|
-
const r2_uploader_1 = require("@empiricalrun/r2-uploader");
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const logger_1 = require("../bin/logger");
|
|
13
|
-
const uploader_1 = require("../uploader");
|
|
14
|
-
const lib_1 = require("./lib");
|
|
15
|
-
let reporterInstance = undefined;
|
|
16
|
-
let reporterConfig = undefined;
|
|
17
|
-
function getReporter() {
|
|
18
|
-
// if no config is set, return undefined
|
|
19
|
-
if (!reporterConfig) {
|
|
20
|
-
console.warn("initialising reporter without any config");
|
|
21
|
-
}
|
|
22
|
-
// initialise once config is set
|
|
23
|
-
if (!reporterInstance && reporterConfig) {
|
|
24
|
-
reporterInstance = new lib_1.Reporter(reporterConfig);
|
|
25
|
-
}
|
|
26
|
-
return reporterInstance;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* function will upload videos and json summary of test results to r2 and report them to reporter.
|
|
30
|
-
* method won't throw error if it fails to report
|
|
31
|
-
*/
|
|
32
|
-
function setReporterConfig(config) {
|
|
33
|
-
reporterConfig = config;
|
|
34
|
-
}
|
|
35
|
-
class TestGenUpdatesReporter {
|
|
36
|
-
repoDir;
|
|
37
|
-
constructor() {
|
|
38
|
-
this.repoDir = process.cwd();
|
|
39
|
-
}
|
|
40
|
-
async reportGenAssets({ projectRepoName, testName, }) {
|
|
41
|
-
const logger = new logger_1.CustomLogger();
|
|
42
|
-
try {
|
|
43
|
-
if (!(0, uploader_1.checkIfResultsUploadAllowed)()) {
|
|
44
|
-
logger.log("Skipped uploading generated test video");
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
console.log("Uploading assets for the test genearation");
|
|
48
|
-
const { videoUrls, traceFiles } = await (0, uploader_1.uploadTestResultsUsingPrjRepo)({
|
|
49
|
-
projectRepoName,
|
|
50
|
-
testName,
|
|
51
|
-
repoDir: this.repoDir,
|
|
52
|
-
});
|
|
53
|
-
const reporter = getReporter();
|
|
54
|
-
await Promise.allSettled([
|
|
55
|
-
...(videoUrls.length
|
|
56
|
-
? [
|
|
57
|
-
reporter?.report(new lib_1.MessageBuilder({
|
|
58
|
-
type: "video",
|
|
59
|
-
message: JSON.stringify({
|
|
60
|
-
type: "video",
|
|
61
|
-
videoUrls,
|
|
62
|
-
}),
|
|
63
|
-
})),
|
|
64
|
-
]
|
|
65
|
-
: []),
|
|
66
|
-
...(traceFiles.length
|
|
67
|
-
? [
|
|
68
|
-
reporter?.report(new lib_1.MessageBuilder({
|
|
69
|
-
type: "pw-trace",
|
|
70
|
-
message: JSON.stringify({
|
|
71
|
-
type: "trace",
|
|
72
|
-
traceFiles,
|
|
73
|
-
}),
|
|
74
|
-
})),
|
|
75
|
-
]
|
|
76
|
-
: []),
|
|
77
|
-
]);
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
logger.error("Failed to report test results");
|
|
81
|
-
console.error(err);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
async sendCurrentView(buffer) {
|
|
85
|
-
const logger = new logger_1.CustomLogger();
|
|
86
|
-
if (!(0, uploader_1.checkIfResultsUploadAllowed)()) {
|
|
87
|
-
logger.log("Skipped uploading current view screenshot");
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (!reporterConfig?.projectRepoName) {
|
|
91
|
-
logger.log("Reporter config is not set skipping screenshot uploads.");
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
// upload current screenshot to r2 and report it to reporter
|
|
96
|
-
if (!fs_1.default.existsSync(path_1.default.join(this.repoDir, "gen-assets"))) {
|
|
97
|
-
fs_1.default.mkdirSync(path_1.default.join(this.repoDir, "gen-assets"));
|
|
98
|
-
}
|
|
99
|
-
fs_1.default.writeFileSync(path_1.default.join(this.repoDir, "gen-assets", `current-view-${Date.now()}.png`), buffer);
|
|
100
|
-
const uploadDir = (0, uploader_1.getUploadPathForRun)(reporterConfig?.projectRepoName);
|
|
101
|
-
const files = await (0, r2_uploader_1.uploadDirectory)({
|
|
102
|
-
sourceDir: path_1.default.join(this.repoDir, "gen-assets"),
|
|
103
|
-
destinationDir: uploadDir,
|
|
104
|
-
uploadBucket: uploader_1.UPLOAD_BUCKET,
|
|
105
|
-
});
|
|
106
|
-
const filePath = Object.keys(files)[0];
|
|
107
|
-
const relativeFilePath = filePath.replace(path_1.default.join(this.repoDir, "gen-assets"), "");
|
|
108
|
-
const url = `${uploader_1.UPLOAD_DOMAIN}/${uploadDir}${relativeFilePath}`;
|
|
109
|
-
await getReporter()?.report(new lib_1.MessageBuilder({
|
|
110
|
-
type: "current-snapshot",
|
|
111
|
-
message: JSON.stringify({ type: "current-view", url }),
|
|
112
|
-
}));
|
|
113
|
-
fs_1.default.rmdirSync(path_1.default.join(this.repoDir, "gen-assets"), {
|
|
114
|
-
recursive: true,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
console.warn("Failed to upload current view screenshot", e);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
async sendMessage(message) {
|
|
122
|
-
const reporter = getReporter();
|
|
123
|
-
if (reporter) {
|
|
124
|
-
await reporter.report(new lib_1.MessageBuilder({
|
|
125
|
-
type: "message",
|
|
126
|
-
message,
|
|
127
|
-
}));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async sendLogUrl(message) {
|
|
131
|
-
const reporter = getReporter();
|
|
132
|
-
if (reporter) {
|
|
133
|
-
await reporter.report(new lib_1.MessageBuilder({
|
|
134
|
-
type: "log-url",
|
|
135
|
-
message,
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
async sendAgentTraceUrl(message) {
|
|
140
|
-
const reporter = getReporter();
|
|
141
|
-
if (reporter) {
|
|
142
|
-
await reporter.report(new lib_1.MessageBuilder({
|
|
143
|
-
type: "agent-trace",
|
|
144
|
-
message,
|
|
145
|
-
}));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
exports.TestGenUpdatesReporter = TestGenUpdatesReporter;
|
package/dist/reporter/lib.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
type DashboardMessagePayload = {
|
|
2
|
-
message: string;
|
|
3
|
-
messageType: "message" | "agent-trace" | "current-snapshot" | "video" | "pw-trace" | "log-url" | "commit-id";
|
|
4
|
-
pull_request?: string;
|
|
5
|
-
testCaseName?: string;
|
|
6
|
-
testCaseId?: number;
|
|
7
|
-
projectRepoName?: string;
|
|
8
|
-
testSessionId?: number;
|
|
9
|
-
generationId?: number;
|
|
10
|
-
};
|
|
11
|
-
export declare class MessageBuilder {
|
|
12
|
-
private props;
|
|
13
|
-
constructor(props: {
|
|
14
|
-
message: string;
|
|
15
|
-
type: DashboardMessagePayload["messageType"];
|
|
16
|
-
});
|
|
17
|
-
buildMessage(dashboardOptions?: {
|
|
18
|
-
override?: Partial<DashboardMessagePayload>;
|
|
19
|
-
}): DashboardMessagePayload;
|
|
20
|
-
}
|
|
21
|
-
export declare class Reporter {
|
|
22
|
-
private config;
|
|
23
|
-
constructor(config: {
|
|
24
|
-
testSessionId: number;
|
|
25
|
-
generationId: number;
|
|
26
|
-
});
|
|
27
|
-
report(messageBuilder: MessageBuilder): Promise<void>;
|
|
28
|
-
private sendMessageToDashboard;
|
|
29
|
-
}
|
|
30
|
-
export {};
|
|
31
|
-
//# sourceMappingURL=lib.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/reporter/lib.ts"],"names":[],"mappings":"AAMA,KAAK,uBAAuB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EACP,SAAS,GACT,aAAa,GACb,kBAAkB,GAClB,OAAO,GACP,UAAU,GACV,SAAS,GACT,WAAW,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,qBAAa,cAAc;IAEvB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,uBAAuB,CAAC,aAAa,CAAC,CAAC;KAC9C;IAGH,YAAY,CAAC,gBAAgB,CAAC,EAAE;QAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;KAC7C,GAAG,uBAAuB;CAO5B;AAED,qBAAa,QAAQ;IAEjB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE;QACd,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;KACtB;IAGG,MAAM,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;YAc7C,sBAAsB;CAkCrC"}
|
package/dist/reporter/lib.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Reporter = exports.MessageBuilder = void 0;
|
|
7
|
-
const async_retry_1 = __importDefault(require("async-retry"));
|
|
8
|
-
const DASHBOARD_DOMAIN = process.env.DASHBOARD_DOMAIN ||
|
|
9
|
-
(process.env.CI === "true" ? "https://dash.empirical.run" : "");
|
|
10
|
-
class MessageBuilder {
|
|
11
|
-
props;
|
|
12
|
-
constructor(props) {
|
|
13
|
-
this.props = props;
|
|
14
|
-
}
|
|
15
|
-
buildMessage(dashboardOptions) {
|
|
16
|
-
return {
|
|
17
|
-
...dashboardOptions?.override,
|
|
18
|
-
message: this.props.message,
|
|
19
|
-
messageType: this.props.type,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.MessageBuilder = MessageBuilder;
|
|
24
|
-
class Reporter {
|
|
25
|
-
config;
|
|
26
|
-
constructor(config) {
|
|
27
|
-
this.config = config;
|
|
28
|
-
}
|
|
29
|
-
async report(messageBuilder) {
|
|
30
|
-
const message = messageBuilder.buildMessage({
|
|
31
|
-
override: {
|
|
32
|
-
testSessionId: this.config.testSessionId,
|
|
33
|
-
generationId: this.config.generationId,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
if (!message) {
|
|
37
|
-
console.info("No message found. Skipping sending message to dashboard");
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
await this.sendMessageToDashboard(message);
|
|
41
|
-
}
|
|
42
|
-
async sendMessageToDashboard(message) {
|
|
43
|
-
if (!DASHBOARD_DOMAIN) {
|
|
44
|
-
console.warn("No dashboard domain found. Skipping send message to dashboard");
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
await (0, async_retry_1.default)(async () => {
|
|
49
|
-
const body = JSON.stringify(message);
|
|
50
|
-
await fetch(`${DASHBOARD_DOMAIN}/api/github/updates`, {
|
|
51
|
-
method: "POST",
|
|
52
|
-
headers: {
|
|
53
|
-
"Content-Type": "application/json",
|
|
54
|
-
Authorization: `Bearer ${process.env.EMPIRICALRUN_API_KEY}`,
|
|
55
|
-
},
|
|
56
|
-
body,
|
|
57
|
-
});
|
|
58
|
-
}, {
|
|
59
|
-
retries: 3,
|
|
60
|
-
minTimeout: 1000,
|
|
61
|
-
maxTimeout: 60_000,
|
|
62
|
-
factor: 3,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
console.error(`Error sending message to Dashboard: ${e.code}`);
|
|
67
|
-
console.error(e.message);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.Reporter = Reporter;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-run.d.ts","sourceRoot":"","sources":["../../src/tools/test-run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,4BAA4B,CAAC;AAwDnE,eAAO,MAAM,WAAW,EAAE,IAqFzB,CAAC"}
|
package/dist/uploader/index.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export declare const UPLOAD_BUCKET = "test-report";
|
|
2
|
-
export declare const UPLOAD_DOMAIN = "https://reports.empirical.run";
|
|
3
|
-
export declare function getFullUploadPath(repoDir: string, filePath: string, uploadDir: string): string;
|
|
4
|
-
export declare function getRelativeUploadPath(filePath: string, repoDir: string): string;
|
|
5
|
-
/**
|
|
6
|
-
* Function to upload test results to R2 using the project repo name and test name.
|
|
7
|
-
* This function uploads both the JSON summary of test results and associated video files.
|
|
8
|
-
* @param {Object} params - The parameters for the function.
|
|
9
|
-
* @param {string} params.projectRepoName - Name of the project repository.
|
|
10
|
-
* @param {string} params.testName - Name of the testcase which called this test-gen.
|
|
11
|
-
* @returns {Promise<Object>} An object containing arrays of video URLs and the summary JSON URL.
|
|
12
|
-
* @returns {string[]} returns.videoUrls - URLs of the uploaded video files.
|
|
13
|
-
* @returns {string} returns.summaryUrl - URL of the uploaded summary JSON file.
|
|
14
|
-
*/
|
|
15
|
-
export declare function uploadTestResultsUsingPrjRepo({ projectRepoName, testName, repoDir, }: {
|
|
16
|
-
projectRepoName: string;
|
|
17
|
-
testName: string;
|
|
18
|
-
repoDir: string;
|
|
19
|
-
}): Promise<{
|
|
20
|
-
videoUrls: string[];
|
|
21
|
-
summaryUrl: string;
|
|
22
|
-
traceFiles: string[];
|
|
23
|
-
}>;
|
|
24
|
-
export declare function getUploadPathForRun(projectRepoName: string): string;
|
|
25
|
-
export declare function checkIfResultsUploadAllowed(): string | undefined;
|
|
26
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/uploader/index.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAC3C,eAAO,MAAM,aAAa,kCAAkC,CAAC;AAG7D,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,UAKlB;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAEtE;AAED;;;;;;;;;GASG;AACH,wBAAsB,6BAA6B,CAAC,EAClD,eAAe,EACf,QAAQ,EACR,OAAO,GACR,EAAE;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC;IACV,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC,CAiED;AAED,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,MAAM,UAM1D;AAED,wBAAgB,2BAA2B,uBAQ1C"}
|
package/dist/uploader/index.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.UPLOAD_DOMAIN = exports.UPLOAD_BUCKET = void 0;
|
|
7
|
-
exports.getFullUploadPath = getFullUploadPath;
|
|
8
|
-
exports.getRelativeUploadPath = getRelativeUploadPath;
|
|
9
|
-
exports.uploadTestResultsUsingPrjRepo = uploadTestResultsUsingPrjRepo;
|
|
10
|
-
exports.getUploadPathForRun = getUploadPathForRun;
|
|
11
|
-
exports.checkIfResultsUploadAllowed = checkIfResultsUploadAllowed;
|
|
12
|
-
const r2_uploader_1 = require("@empiricalrun/r2-uploader");
|
|
13
|
-
const path_1 = __importDefault(require("path"));
|
|
14
|
-
const utils_1 = require("./utils");
|
|
15
|
-
// json summary of test results
|
|
16
|
-
// originally we used to upload test results directory for this
|
|
17
|
-
// but now we have our test results (per testcase artifacts) inside playwright-report/data
|
|
18
|
-
// but we also have summary.json in playwright-report/
|
|
19
|
-
// we can avoid html report upload here if we don't want
|
|
20
|
-
const PLAYWRIGHT_REPORT_DATA = "playwright-report/data";
|
|
21
|
-
exports.UPLOAD_BUCKET = "test-report";
|
|
22
|
-
exports.UPLOAD_DOMAIN = "https://reports.empirical.run"; // domain based on bucket mentioned above
|
|
23
|
-
const uploadId = crypto.randomUUID();
|
|
24
|
-
function getFullUploadPath(repoDir, filePath, uploadDir) {
|
|
25
|
-
// remove the source dir from the file path - only keep the relative path
|
|
26
|
-
const relativeFilePath = getRelativeUploadPath(filePath, repoDir);
|
|
27
|
-
return `${exports.UPLOAD_DOMAIN}/${uploadDir}${relativeFilePath}`;
|
|
28
|
-
}
|
|
29
|
-
function getRelativeUploadPath(filePath, repoDir) {
|
|
30
|
-
return filePath.replace(path_1.default.join(repoDir, PLAYWRIGHT_REPORT_DATA), "");
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Function to upload test results to R2 using the project repo name and test name.
|
|
34
|
-
* This function uploads both the JSON summary of test results and associated video files.
|
|
35
|
-
* @param {Object} params - The parameters for the function.
|
|
36
|
-
* @param {string} params.projectRepoName - Name of the project repository.
|
|
37
|
-
* @param {string} params.testName - Name of the testcase which called this test-gen.
|
|
38
|
-
* @returns {Promise<Object>} An object containing arrays of video URLs and the summary JSON URL.
|
|
39
|
-
* @returns {string[]} returns.videoUrls - URLs of the uploaded video files.
|
|
40
|
-
* @returns {string} returns.summaryUrl - URL of the uploaded summary JSON file.
|
|
41
|
-
*/
|
|
42
|
-
async function uploadTestResultsUsingPrjRepo({ projectRepoName, testName, repoDir, }) {
|
|
43
|
-
const uploadDir = getUploadPathForRun(projectRepoName);
|
|
44
|
-
console.log("Current directory for assets upload", repoDir);
|
|
45
|
-
const files = await (0, r2_uploader_1.uploadDirectory)({
|
|
46
|
-
sourceDir: path_1.default.join(repoDir, PLAYWRIGHT_REPORT_DATA),
|
|
47
|
-
destinationDir: uploadDir,
|
|
48
|
-
uploadBucket: exports.UPLOAD_BUCKET,
|
|
49
|
-
});
|
|
50
|
-
// upload summary.json
|
|
51
|
-
await (0, r2_uploader_1.uploadDirectory)({
|
|
52
|
-
sourceDir: path_1.default.join(repoDir, "playwright-report"),
|
|
53
|
-
// TODO: this will only work for repos that use playwright 1.47.1
|
|
54
|
-
fileList: [path_1.default.join(repoDir, "playwright-report", "summary.json")],
|
|
55
|
-
destinationDir: uploadDir,
|
|
56
|
-
uploadBucket: exports.UPLOAD_BUCKET,
|
|
57
|
-
});
|
|
58
|
-
// fileNames are relative upload paths
|
|
59
|
-
const fileNames = Object.keys(files);
|
|
60
|
-
console.log("Uploaded files", fileNames.map((f) => getFullUploadPath(repoDir, f, uploadDir)));
|
|
61
|
-
const defaultLocation = path_1.default.join(repoDir, "playwright-report", "summary.json");
|
|
62
|
-
const results = (0, utils_1.parseJsonReport)(defaultLocation);
|
|
63
|
-
const flatTestsList = (0, utils_1.getFlattenedTestList)(results.suites);
|
|
64
|
-
const testAttachmentPaths = [];
|
|
65
|
-
for (const test of flatTestsList) {
|
|
66
|
-
if (test.title === testName) {
|
|
67
|
-
if (test.tests[0]) {
|
|
68
|
-
if (test.tests[0].results[0]) {
|
|
69
|
-
// results array is basically made by retries
|
|
70
|
-
for (const attachments of test.tests[0].results[0].attachments) {
|
|
71
|
-
if (attachments.path) {
|
|
72
|
-
testAttachmentPaths.push(getRelativeUploadPath(attachments.path, repoDir));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const videoFiles = fileNames.filter((fileName) => fileName.endsWith(".webm") && testAttachmentPaths.includes(fileName));
|
|
80
|
-
const traceFiles = fileNames.filter((fileName) => fileName.endsWith(".zip") && testAttachmentPaths.includes(fileName));
|
|
81
|
-
console.log("videoFiles", videoFiles);
|
|
82
|
-
console.log("traceFiles", traceFiles);
|
|
83
|
-
return {
|
|
84
|
-
videoUrls: videoFiles
|
|
85
|
-
.map((fileName) => getFullUploadPath(repoDir, fileName, uploadDir))
|
|
86
|
-
.filter((url) => !!url),
|
|
87
|
-
summaryUrl: `${exports.UPLOAD_DOMAIN}/${uploadDir}/summary.json`,
|
|
88
|
-
traceFiles: traceFiles
|
|
89
|
-
.map((fileName) => getFullUploadPath(repoDir, fileName, uploadDir))
|
|
90
|
-
.filter((url) => !!url),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function getUploadPathForRun(projectRepoName) {
|
|
94
|
-
const uploadDir = `test-generation/${projectRepoName.replace("-tests", "")}/${uploadId}`;
|
|
95
|
-
return uploadDir;
|
|
96
|
-
}
|
|
97
|
-
function checkIfResultsUploadAllowed() {
|
|
98
|
-
// TODO: check for valid R2 credentials
|
|
99
|
-
// check for project repo name, and r2 creds
|
|
100
|
-
return (process.env.R2_ACCOUNT_ID &&
|
|
101
|
-
process.env.R2_ACCESS_KEY_ID &&
|
|
102
|
-
process.env.R2_SECRET_ACCESS_KEY);
|
|
103
|
-
}
|
package/dist/uploader/utils.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { JSONReportSpec, JSONReportSuite } from "@playwright/test/reporter";
|
|
2
|
-
export declare function parseJsonReport<T>(srcFile: string): T;
|
|
3
|
-
export type flattenedSpecT = JSONReportSpec & {
|
|
4
|
-
nesting: string[];
|
|
5
|
-
suitesString: string;
|
|
6
|
-
};
|
|
7
|
-
export declare const getFlattenedTestList: (suites: JSONReportSuite[]) => flattenedSpecT[];
|
|
8
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/uploader/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EAChB,MAAM,2BAA2B,CAAC;AAGnC,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CAErD;AAMD,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG;IAC5C,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,eAAe,EAAE,KACxB,cAAc,EA4BhB,CAAC"}
|
package/dist/uploader/utils.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getFlattenedTestList = void 0;
|
|
7
|
-
exports.parseJsonReport = parseJsonReport;
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
function parseJsonReport(srcFile) {
|
|
10
|
-
return JSON.parse(fs_1.default.readFileSync(srcFile, { encoding: "utf-8" }));
|
|
11
|
-
}
|
|
12
|
-
const getFlattenedTestList = (suites) => {
|
|
13
|
-
let flattenedSpecs = [];
|
|
14
|
-
const traverseSuites = (suite, nesting = []) => {
|
|
15
|
-
nesting = [...nesting, suite.title];
|
|
16
|
-
flattenedSpecs.push(...suite.specs.map((spec) => {
|
|
17
|
-
const finalNesting = [...nesting, spec.title];
|
|
18
|
-
const suites = nesting.slice(1);
|
|
19
|
-
const suitesString = suites.length ? suites.join("~~") : "~~";
|
|
20
|
-
return {
|
|
21
|
-
...spec,
|
|
22
|
-
nesting: finalNesting,
|
|
23
|
-
suitesString,
|
|
24
|
-
};
|
|
25
|
-
}));
|
|
26
|
-
// Traverse nested suites recursively
|
|
27
|
-
if (suite.suites && suite.suites.length > 0) {
|
|
28
|
-
suite.suites.forEach((suite) => traverseSuites(suite, nesting));
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
// Start the traversal from the top-level suites
|
|
32
|
-
suites.forEach((suite) => traverseSuites(suite));
|
|
33
|
-
return flattenedSpecs;
|
|
34
|
-
};
|
|
35
|
-
exports.getFlattenedTestList = getFlattenedTestList;
|