@bigbinary/neeto-playwright-reporter 1.0.2 → 1.2.0
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/index.cjs.js +68 -32
- package/index.cjs.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +67 -31
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare class MyReporter implements Reporter {
|
|
|
13
13
|
constructor(options: ReporterOptionParams);
|
|
14
14
|
onBegin: (config: FullConfig, rootSuite: Suite) => Promise<void>;
|
|
15
15
|
onTestBegin: ({ id, title }: TestCase, { retry }: TestResult) => Promise<void>;
|
|
16
|
-
onTestEnd: ({ id, title }: TestCase, { status, duration, errors, retry }: TestResult) => Promise<void>;
|
|
16
|
+
onTestEnd: ({ id, title }: TestCase, { status, duration, errors, retry, attachments }: TestResult) => Promise<void>;
|
|
17
17
|
onEnd: ({ status, duration }: FullResult) => Promise<void>;
|
|
18
18
|
}
|
|
19
19
|
|
package/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import require$$6 from 'fs';
|
|
1
2
|
import require$$1, { TextEncoder } from 'util';
|
|
2
3
|
import stream, { Readable } from 'stream';
|
|
3
4
|
import require$$1$1 from 'path';
|
|
4
5
|
import require$$3 from 'http';
|
|
5
6
|
import require$$4 from 'https';
|
|
6
7
|
import require$$0$1 from 'url';
|
|
7
|
-
import require$$6 from 'fs';
|
|
8
8
|
import require$$4$1 from 'assert';
|
|
9
9
|
import require$$1$2 from 'tty';
|
|
10
10
|
import require$$0$2 from 'os';
|
|
@@ -18439,12 +18439,8 @@ const HEADERS_KEYS = {
|
|
|
18439
18439
|
};
|
|
18440
18440
|
const API_BASE_URL = "/api/v1";
|
|
18441
18441
|
|
|
18442
|
-
const create$2 = (ciBuildId, history_id, payload) => axios.post(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities/${history_id}/attempts`, {
|
|
18443
|
-
|
|
18444
|
-
});
|
|
18445
|
-
const update$1 = (ciBuildId, history_id, id, payload) => axios.put(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities/${history_id}/attempts/${id}`, {
|
|
18446
|
-
attempt: payload,
|
|
18447
|
-
});
|
|
18442
|
+
const create$2 = (ciBuildId, history_id, payload) => axios.post(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities/${history_id}/attempts`, payload, { headers: { "Content-Type": "multipart/form-data" } });
|
|
18443
|
+
const update$1 = (ciBuildId, history_id, id, payload) => axios.put(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities/${history_id}/attempts/${id}`, payload, { headers: { "Content-Type": "multipart/form-data" } });
|
|
18448
18444
|
const attemptsApi = { create: create$2, update: update$1 };
|
|
18449
18445
|
|
|
18450
18446
|
const ERRORS = {
|
|
@@ -18459,23 +18455,32 @@ const ERRORS = {
|
|
|
18459
18455
|
onEnd: {
|
|
18460
18456
|
failedToReportRunStatus: "Failed to report run status",
|
|
18461
18457
|
},
|
|
18458
|
+
heartbeat: {
|
|
18459
|
+
stopped: "Run was stopped at the reporter",
|
|
18460
|
+
},
|
|
18462
18461
|
};
|
|
18463
18462
|
|
|
18464
18463
|
const MESSAGES = {
|
|
18465
18464
|
onBegin: {
|
|
18466
|
-
testStarted: "
|
|
18465
|
+
testStarted: "Run has started reporting to neetoPlaywrightReporter",
|
|
18467
18466
|
ciBuildId: (currentCiBuildId) => `CI BUILD ID: ${currentCiBuildId}`,
|
|
18468
18467
|
totalShards: (totalShards) => `Total shards: ${totalShards}`,
|
|
18469
18468
|
currentShard: (currentShard) => `Current shard: ${currentShard}`,
|
|
18470
18469
|
},
|
|
18470
|
+
onTestBegin: {
|
|
18471
|
+
startingTest: (titlePath) => `Starting ${titlePath}`,
|
|
18472
|
+
},
|
|
18473
|
+
onTestEnd: {
|
|
18474
|
+
reportedTest: (title) => `Reported ${title} to neetoPlaywrightReporter`,
|
|
18475
|
+
},
|
|
18471
18476
|
};
|
|
18472
18477
|
|
|
18473
18478
|
const consoleLogFormatted = {
|
|
18474
|
-
bold: (message) => console.log(
|
|
18475
|
-
dim: (message) => console.log(
|
|
18476
|
-
underline: (message) => console.log(
|
|
18477
|
-
invertBackground: (message) => console.log(
|
|
18478
|
-
hidden: (message) => console.log(
|
|
18479
|
+
bold: (message) => console.log("\x1b[1m", message, "\x1b[0m"),
|
|
18480
|
+
dim: (message) => console.log("\x1b[2m", message, "\x1b[0m"),
|
|
18481
|
+
underline: (message) => console.log("\x1b[4m", message, "\x1b[0m"),
|
|
18482
|
+
invertBackground: (message) => console.log("\x1b[7m", message, "\x1b[0m"),
|
|
18483
|
+
hidden: (message) => console.log("\x1b[8m", message, "\x1b[0m"),
|
|
18479
18484
|
error: (message) => console.log("\u001b[31m", "\x1b[1m", message, "\x1b[0m", "\u001b[0m"),
|
|
18480
18485
|
warning: (message) => console.log("\u001b[33m", "\x1b[1m", message, "\x1b[0m", "\u001b[0m"),
|
|
18481
18486
|
};
|
|
@@ -18496,6 +18501,16 @@ const executeCommandLine = ({ command, messageOnError, shouldThrowError = false,
|
|
|
18496
18501
|
const createShardObject = ({ currentShard = 0, status = "running", duration = null, }) => ({
|
|
18497
18502
|
[currentShard]: { status, duration },
|
|
18498
18503
|
});
|
|
18504
|
+
const convertBufferToBlob = (buffer, contentType) => new Blob([buffer], { type: contentType });
|
|
18505
|
+
|
|
18506
|
+
const create$1 = (payload) => axios.post(`${API_BASE_URL}/reporter/runs`, {
|
|
18507
|
+
run: payload,
|
|
18508
|
+
});
|
|
18509
|
+
const update = (ciBuildId, payload) => axios.put(`${API_BASE_URL}/reporter/runs/${ciBuildId}`, {
|
|
18510
|
+
run: payload,
|
|
18511
|
+
});
|
|
18512
|
+
const heartbeat = (ciBuildId) => axios.get(`${API_BASE_URL}/reporter/runs/${ciBuildId}/heartbeat`);
|
|
18513
|
+
const runsApi = { create: create$1, update, heartbeat };
|
|
18499
18514
|
|
|
18500
18515
|
const getDescribePath = ({ titlePath, title, project, spec, }) => titlePath.filter((item, index) => index !== 0 && item !== title && item !== project && item !== spec);
|
|
18501
18516
|
const getCurrentCommitSha = () => executeCommandLine({
|
|
@@ -18515,6 +18530,15 @@ const getInitializerData = ({ rootDir }, rootSuite) => rootSuite.allTests().map(
|
|
|
18515
18530
|
const describe = getDescribePath({ titlePath, title, spec, project });
|
|
18516
18531
|
return { title, describe, project, spec, history_id };
|
|
18517
18532
|
});
|
|
18533
|
+
const sendHeartBeatSignal = async (ciBuildId) => {
|
|
18534
|
+
try {
|
|
18535
|
+
await runsApi.heartbeat(ciBuildId);
|
|
18536
|
+
}
|
|
18537
|
+
catch (error) {
|
|
18538
|
+
consoleLogFormatted.error(ERRORS.heartbeat.stopped);
|
|
18539
|
+
process.exit(1);
|
|
18540
|
+
}
|
|
18541
|
+
};
|
|
18518
18542
|
|
|
18519
18543
|
const setAuthHeaders = (projectKey) => {
|
|
18520
18544
|
var _a;
|
|
@@ -18531,14 +18555,6 @@ function initializeAxios({ projectKey, baseURL, }) {
|
|
|
18531
18555
|
setAuthHeaders(projectKey);
|
|
18532
18556
|
}
|
|
18533
18557
|
|
|
18534
|
-
const create$1 = (payload) => axios.post(`${API_BASE_URL}/reporter/runs`, {
|
|
18535
|
-
run: payload,
|
|
18536
|
-
});
|
|
18537
|
-
const update = (ciBuildId, payload) => axios.put(`${API_BASE_URL}/reporter/runs/${ciBuildId}`, {
|
|
18538
|
-
run: payload,
|
|
18539
|
-
});
|
|
18540
|
-
const runsApi = { create: create$1, update };
|
|
18541
|
-
|
|
18542
18558
|
const create = (ciBuildId, payload) => axios.post(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities`, {
|
|
18543
18559
|
test_entity: payload,
|
|
18544
18560
|
});
|
|
@@ -18562,7 +18578,8 @@ class MyReporter {
|
|
|
18562
18578
|
test_entities: getInitializerData(config, rootSuite),
|
|
18563
18579
|
}));
|
|
18564
18580
|
}
|
|
18565
|
-
catch (
|
|
18581
|
+
catch (error) {
|
|
18582
|
+
consoleLogFormatted.error(error.message);
|
|
18566
18583
|
throw new Error(ERRORS.onBegin.failedToInitializeRun);
|
|
18567
18584
|
}
|
|
18568
18585
|
consoleLogFormatted.underline(MESSAGES.onBegin.testStarted);
|
|
@@ -18571,33 +18588,51 @@ class MyReporter {
|
|
|
18571
18588
|
consoleLogFormatted.dim(MESSAGES.onBegin.totalShards(shard.total));
|
|
18572
18589
|
consoleLogFormatted.dim(MESSAGES.onBegin.currentShard(shard.current));
|
|
18573
18590
|
}
|
|
18591
|
+
await sendHeartBeatSignal(this.ciBuildId);
|
|
18592
|
+
setInterval(async () => await sendHeartBeatSignal(this.ciBuildId), 60000);
|
|
18574
18593
|
this.attempts = attempts;
|
|
18575
18594
|
this.config = config;
|
|
18576
18595
|
this.currentShard = shard === null || shard === void 0 ? void 0 : shard.current;
|
|
18577
18596
|
};
|
|
18578
18597
|
this.onTestBegin = async ({ id, title }, { retry }) => {
|
|
18598
|
+
consoleLogFormatted.invertBackground(MESSAGES.onTestBegin.startingTest(title));
|
|
18579
18599
|
try {
|
|
18600
|
+
const formData = new FormData();
|
|
18601
|
+
formData.append("attempt[status]", "running");
|
|
18580
18602
|
retry === 0 &&
|
|
18581
|
-
(await attemptsApi.update(this.ciBuildId, id, this.attempts[id],
|
|
18582
|
-
status: "running",
|
|
18583
|
-
}));
|
|
18603
|
+
(await attemptsApi.update(this.ciBuildId, id, this.attempts[id], formData));
|
|
18584
18604
|
}
|
|
18585
|
-
catch (
|
|
18605
|
+
catch (error) {
|
|
18606
|
+
consoleLogFormatted.error(error.message);
|
|
18586
18607
|
consoleLogFormatted.error(ERRORS.onTestBegin.failedToReportTest(title, id));
|
|
18587
18608
|
}
|
|
18588
18609
|
};
|
|
18589
|
-
this.onTestEnd = async ({ id, title }, { status, duration, errors, retry }) => {
|
|
18610
|
+
this.onTestEnd = async ({ id, title }, { status, duration, errors, retry, attachments }) => {
|
|
18590
18611
|
try {
|
|
18591
18612
|
const testResult = {
|
|
18592
18613
|
status,
|
|
18593
18614
|
duration,
|
|
18594
18615
|
log: errors.map(error => { var _a; return (_a = error.message) !== null && _a !== void 0 ? _a : ""; }).join("\n"),
|
|
18595
18616
|
};
|
|
18617
|
+
consoleLogFormatted.underline(title);
|
|
18618
|
+
const formData = new FormData();
|
|
18619
|
+
attachments.map(({ name, path, body, contentType }) => {
|
|
18620
|
+
consoleLogFormatted.dim(`${name}: ${path}`);
|
|
18621
|
+
if (["screenshot", "video", "trace"].includes(name)) {
|
|
18622
|
+
const buffer = path ? require$$6.readFileSync(path) : body;
|
|
18623
|
+
formData.append(`attempt[${name}s][]`, convertBufferToBlob(buffer, contentType));
|
|
18624
|
+
}
|
|
18625
|
+
});
|
|
18626
|
+
Object.entries(testResult).map(([resultKey, resultValue]) => {
|
|
18627
|
+
formData.append(`attempt[${resultKey}]`, resultValue.toString());
|
|
18628
|
+
});
|
|
18596
18629
|
retry === 0
|
|
18597
|
-
? await attemptsApi.update(this.ciBuildId, id, this.attempts[id],
|
|
18598
|
-
: await attemptsApi.create(this.ciBuildId, id,
|
|
18630
|
+
? await attemptsApi.update(this.ciBuildId, id, this.attempts[id], formData)
|
|
18631
|
+
: await attemptsApi.create(this.ciBuildId, id, formData);
|
|
18632
|
+
consoleLogFormatted.invertBackground(MESSAGES.onTestEnd.reportedTest(title));
|
|
18599
18633
|
}
|
|
18600
|
-
catch (
|
|
18634
|
+
catch (error) {
|
|
18635
|
+
consoleLogFormatted.error(error.message);
|
|
18601
18636
|
consoleLogFormatted.error(ERRORS.onTestBegin.failedToReportTest(title, id));
|
|
18602
18637
|
}
|
|
18603
18638
|
};
|
|
@@ -18611,7 +18646,8 @@ class MyReporter {
|
|
|
18611
18646
|
}),
|
|
18612
18647
|
});
|
|
18613
18648
|
}
|
|
18614
|
-
catch (
|
|
18649
|
+
catch (error) {
|
|
18650
|
+
consoleLogFormatted.error(error.message);
|
|
18615
18651
|
throw new Error(ERRORS.onEnd.failedToReportRunStatus);
|
|
18616
18652
|
}
|
|
18617
18653
|
};
|