forked from Xotabu4/cyborg-pw-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreporter.ts
66 lines (58 loc) · 1.74 KB
/
reporter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import fs from "fs/promises";
import path from "path";
import { request } from "@playwright/test";
import type {
FullConfig,
FullResult,
Reporter,
Suite,
} from "@playwright/test/reporter";
class PwReportsServerReporter implements Reporter {
config: FullConfig;
onBegin(config: FullConfig, suite: Suite) {
this.config = config;
}
async onEnd(result: FullResult) {
const blobReporterConfig = this.config.reporter.find(
(r) => r[0] === "blob"
);
if (blobReporterConfig === undefined) {
console.error(
"Blob reporter config not found, blob reporter is required for this reporter to work. Results will not be uploaded."
);
return;
}
const testResults = blobReporterConfig[1];
const testResultPath = path.join(
process.cwd(),
testResults.outputDir,
testResults.fileName
);
const buffer = await fs.readFile(testResultPath);
const ctx = await request.newContext();
const resp = await ctx.put("http://localhost:3000/api/result/upload", {
multipart: {
file: {
name: testResults.fileName,
mimeType: "application/zip",
buffer: buffer,
},
testRunName: "regression-run-v1.11",
reporter: "okhotemskyi",
},
});
const { data } = await resp.json();
console.log("[PW_reports_server] result uploaded: ", data);
// const report = await (
// await ctx.post("http://localhost:3000/api/report/generate", {
// data: {
// resultsIds: [data.resultID],
// },
// })
// ).json();
// console.log(
// `[PW_reports_server] 🎭 HTML Report is available at: http://localhost:3000${report.reportUrl}`
// );
}
}
export default PwReportsServerReporter;