New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@empiricalrun/reporter

Package Overview
Dependencies
Maintainers
0
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@empiricalrun/reporter - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

dist/sources/base.d.ts

6

CHANGELOG.md
# @empiricalrun/reporter
## 0.2.0
### Minor Changes
- f99fa2a: feat: introduce reporter sources to enable appium support
## 0.1.2

@@ -4,0 +10,0 @@

137

dist/bin/index.js
#!/usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const PLAYWRIGHT_JSON_REPORT = path_1.default.join(process.cwd(), "test-results", "summary.json");
const playwright_1 = require("../sources/playwright");
const utils_1 = require("../utils");
const color = {

@@ -15,61 +11,6 @@ warning: "dcab07",

};
function reportLink(repoName, runId, filter) {
const base = `https://reports.empirical.run/${repoName}/${runId}/index.html`;
if (filter && "status" in filter) {
return `${base}#?q=s:${filter.status}`;
}
else if (filter && "testId" in filter) {
return `${base}#?testId=${filter.testId}`;
}
else {
return base;
}
function slackLinkForRun(repoName, runId) {
const runLink = `https://github.com/empirical-run/${repoName}-tests/actions/runs/${runId}`;
return (0, utils_1.buildSlackLink)(runLink, runId);
}
function testSummaryLink(previewText, repoName, runId, filter) {
const link = filter
? reportLink(repoName, runId, { status: filter })
: reportLink(repoName, runId);
return `<${link}|${previewText}>`;
}
function testDirectLink(previewText, repoName, runId, testId) {
const link = reportLink(repoName, runId, { testId });
return `<${link}|${previewText}>`;
}
function humanReadable(duration) {
const totalSecs = duration / 1000;
const minutes = Math.floor(totalSecs / 60);
const secs = Math.round(totalSecs - minutes * 60);
return minutes === 0 ? `${secs} secs` : `${minutes} mins ${secs} secs`;
}
function failedTestsFromSuite(rootSuite) {
const { title, specs, suites } = rootSuite;
let failedAtDeeperLevels = [];
if (suites && suites.length > 0) {
suites
.map((suite) => ({ ...suite, title: `${title} › ${suite.title}` }))
.forEach((suite) => {
failedAtDeeperLevels.push(...failedTestsFromSuite(suite));
});
}
const failedAtThisLevel = specs
.map((spec) => ({ ...spec, title: `${title} › ${spec.title}` }))
.filter(({ ok }) => !ok);
return [...failedAtThisLevel, ...failedAtDeeperLevels];
}
function failedTests(results, repoName, runId) {
const { suites } = results;
const failedSpecs = [];
suites.map((fileLevelSuite) => {
const { specs, suites } = fileLevelSuite;
failedSpecs.push(...specs.filter(({ ok }) => !ok));
if (suites) {
suites.forEach((suite) => {
failedSpecs.push(...failedTestsFromSuite(suite));
});
}
});
return failedSpecs.map(({ title, id }) => {
return `${title} (${testDirectLink("view", repoName, runId, id)})`;
});
}
function messageForMissingResults(repoName, runId) {

@@ -90,3 +31,3 @@ return {

short: true,
value: `<https://github.com/empirical-run/${repoName}-tests/actions/runs/${runId}|${runId}>`,
value: slackLinkForRun(repoName, runId),
},

@@ -98,8 +39,4 @@ ],

}
function endMessage(repoName, runId) {
if (!fs_1.default.existsSync(PLAYWRIGHT_JSON_REPORT)) {
return messageForMissingResults(repoName, runId);
}
const results = JSON.parse(fs_1.default.readFileSync(PLAYWRIGHT_JSON_REPORT, { encoding: "utf-8" }));
const hasPassed = results.stats.unexpected === 0;
function endMessage(repoName, runId, source) {
const results = source.resultsSummary();
const slackMessage = {

@@ -109,5 +46,5 @@ text: "Tests completed",

{
color: hasPassed ? color.success : color.error,
color: results.hasPassed ? color.success : color.error,
title: "Open test report",
title_link: reportLink(repoName, runId),
title_link: source.reportLink(),
fields: [

@@ -117,3 +54,3 @@ {

short: true,
value: hasPassed ? "Passed" : "Failed",
value: results.hasPassed ? "Passed" : "Failed",
},

@@ -123,3 +60,3 @@ {

short: true,
value: `<https://github.com/empirical-run/${repoName}-tests/actions/runs/${runId}|${runId}>`,
value: slackLinkForRun(repoName, runId),
},

@@ -129,3 +66,3 @@ {

short: true,
value: `${results.stats.expected + results.stats.unexpected + results.stats.flaky} (${testSummaryLink("view", repoName, runId)})`,
value: `${results.totalTests} (${(0, utils_1.buildSlackLink)(source.reportLink(), "view")})`,
},

@@ -135,3 +72,3 @@ {

short: true,
value: humanReadable(results.stats.duration),
value: (0, utils_1.humanReadable)(results.runDuration),
},

@@ -142,12 +79,13 @@ ],

};
if (results.stats.flaky > 0) {
if (results.flakyTests > 0) {
const reportLink = source.reportLink({ status: "flaky" });
slackMessage.attachments[0].fields.push({
title: "Flaky tests",
short: true,
value: `${results.stats.flaky} (${testSummaryLink("view", repoName, runId, "flaky")})`,
value: `${results.flakyTests} (${(0, utils_1.buildSlackLink)(reportLink, "view")})`,
});
}
if (!hasPassed) {
const failures = failedTests(results, repoName, runId);
const numFailed = results.stats.unexpected;
if (!results.hasPassed) {
const numFailed = results.failedTests;
const failures = source.failedTests(repoName, runId);
let messageStr;

@@ -163,3 +101,6 @@ const previewSizeLimit = 4;

.join("\n");
messageStr = `${testsStr}\n${testSummaryLink("View all", repoName, runId, "failed")}`;
// TODO: if Appium reporter does not have direct test links, we will need to show
// "view all" even if there are fewer than `previewSizeLimit` failed tests.
const reportLink = source.reportLink({ status: "failed" });
messageStr = `${testsStr}\n${(0, utils_1.buildSlackLink)(reportLink, "View all")}`;
}

@@ -189,3 +130,3 @@ slackMessage.attachments[0].fields.push({

short: true,
value: `<https://github.com/empirical-run/${repoName}-tests/actions/runs/${runId}|${runId}>`,
value: slackLinkForRun(repoName, runId),
},

@@ -198,14 +139,26 @@ ],

(async function main() {
if (process.argv.length != 5) {
console.log("Expected args not found: npx @empiricalrun/reporter $MESSAGE $CUSTOMERNAME $RUNID");
if (process.argv.length != 6) {
console.log("Expected args not found: npx @empiricalrun/reporter $MESSAGE_TYPE $CUSTOMER_NAME $RUN_ID $REPORT_TYPE");
process.exit(1);
}
const [messageType, repoName, runId] = process.argv.slice(2);
const [messageType, repoName, runId, reportType] = process.argv.slice(2);
let reportSource = undefined;
if (reportType == "playwright") {
reportSource = new playwright_1.PlaywrightReportSource(repoName, runId);
}
else {
console.log(`report type (fourth arg) must be "playwright".`);
process.exit(1);
}
let slackMessage;
if (messageType === "start") {
console.log(JSON.stringify(startMessage(repoName, runId)));
return;
slackMessage = startMessage(repoName, runId);
}
else if (messageType === "end") {
console.log(JSON.stringify(endMessage(repoName, runId)));
return;
if (!reportSource.reportExists()) {
slackMessage = messageForMissingResults(repoName, runId);
}
else {
slackMessage = endMessage(repoName, runId, reportSource);
}
}

@@ -216,2 +169,4 @@ else {

}
console.log(JSON.stringify(slackMessage));
return;
})();
{
"name": "@empiricalrun/reporter",
"version": "0.1.2",
"version": "0.2.0",
"publishConfig": {

@@ -5,0 +5,0 @@ "registry": "https://registry.npmjs.org/",

@@ -11,3 +11,3 @@ # reporter

```sh
npx @empiricalrun/reporter $MESSAGE $CUSTOMERNAME $RUNID
npx @empiricalrun/reporter $MESSAGE_TYPE $CUSTOMER_NAME $RUN_ID $REPORT_TYPE
```

@@ -17,7 +17,8 @@

- `$MESSAGE`: can be `start` (message for tests started) or `end` (message for tests completed)
- `$CUSTOMERNAME`: name of the customer (e.g. leap-wallet) which resolves to _both_ github and r2
- `$MESSAGE_TYPE`: can be `start` (message for tests started) or `end` (message for tests completed)
- `$CUSTOMER_NAME`: name of the customer (e.g. leap-wallet) which resolves to _both_ github and r2
- expected github: `github.com/empirical-run/$CUSTOMERNAME-tests`
- expected r2 location: `reports.empirical.run/$CUSTOMERNAME/...`
- `$RUNID`: github actions run id
- `$RUN_ID`: github actions run id
- `$REPORT_TYPE`: can be `playwright` or other supported report sources

@@ -24,0 +25,0 @@ ## Development

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc