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

@estruyf/github-actions-reporter

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@estruyf/github-actions-reporter - npm Package Compare versions

Comparing version

to
1.1.0-beta.5902595

dist/utils/checkForFailedTests.js

7

CHANGELOG.md

@@ -5,4 +5,11 @@ # Changelog

## [1.1.0]
- Update test suite logic
- Added OS name
- Added browser/project name
- Added retries count
## [1.0.0]
- Initial release

76

dist/index.js

@@ -39,54 +39,52 @@ "use strict";

const getTableRows_1 = require("./utils/getTableRows");
const checkForFailedTests_1 = require("./utils/checkForFailedTests");
class GitHubAction {
constructor(options = {}) {
this.options = options;
this.testDetails = {
total: undefined,
tests: {},
};
console.log(`Using GitHub Actions reporter`);
}
onBegin(config, suite) {
this.testDetails.total = suite.allTests().length;
}
onTestBegin(test, result) {
const fileName = (0, path_1.basename)(test.location.file);
if (!this.testDetails.tests[fileName]) {
this.testDetails.tests[fileName] = {};
}
if (!this.testDetails.tests[fileName][test.title]) {
this.testDetails.tests[fileName][test.title] = {
status: "pending",
duration: 0,
};
}
}
onTestEnd(test, result) {
const fileName = (0, path_1.basename)(test.location.file);
this.testDetails.tests[fileName][test.title] = {
status: result.status,
duration: result.duration,
};
}
onEnd(result) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (process.env.GITHUB_ACTIONS) {
if (process.env.GITHUB_ACTIONS && this.suite) {
const os = process.platform;
const summary = core.summary;
summary.addHeading(this.options.title || `Test results`, 1);
summary.addRaw(`Total tests: ${this.testDetails.total}`);
summary.addRaw(`Total tests: ${this.suite.allTests().length}`);
if (this.options.useDetails) {
summary.addSeparator();
}
for (const fileName of Object.keys(this.testDetails.tests)) {
if (this.options.useDetails) {
const content = (0, getHtmlTable_1.getHtmlTable)(this.testDetails.tests[fileName]);
// Check if there are any failed tests
const failedTests = Object.values(this.testDetails.tests[fileName]).filter((test) => test.status !== "passed");
summary.addDetails(`${failedTests.length === 0 ? "✅" : "❌"} ${fileName}`, content);
for (const suite of (_a = this.suite) === null || _a === void 0 ? void 0 : _a.suites) {
const project = suite.project();
// Get all the test files
const files = suite
.allTests()
.map((test) => test.location.file)
.reduce((acc, curr) => {
if (!acc.includes(curr)) {
acc.push(curr);
}
return acc;
}, []);
// Get all the tests per file
const tests = files.reduce((acc, curr) => {
acc[curr] = suite.allTests().filter((test) => {
return test.location.file === curr;
});
return acc;
}, {});
for (const filePath of Object.keys(tests)) {
const fileName = (0, path_1.basename)(filePath);
if (this.options.useDetails) {
const content = (0, getHtmlTable_1.getHtmlTable)(tests[filePath]);
// Check if there are any failed tests
const hasFailedTests = (0, checkForFailedTests_1.checkForFailedTests)(tests[filePath]);
summary.addDetails(`${hasFailedTests ? "❌" : "✅"} ${fileName} (${os}/${project})`, content);
}
else {
summary.addHeading(`${fileName} (${os}/${project})`, 2);
const tableRows = (0, getTableRows_1.getTableRows)(tests[filePath]);
summary.addTable(tableRows);
}
}
else {
summary.addHeading(fileName, 2);
const tableRows = (0, getTableRows_1.getTableRows)(this.testDetails.tests[fileName]);
summary.addTable(tableRows);
}
}

@@ -93,0 +91,0 @@ yield summary.write();

@@ -13,11 +13,14 @@ "use strict";

content.push(`<th>Duration</th>`);
content.push(`<th>Retries</th>`);
content.push(`</tr>`);
content.push(`</thead>`);
content.push(`<tbody>`);
for (const testName of Object.keys(tests)) {
const test = tests[testName];
for (const test of tests) {
// Get the last result
const result = test.results[test.results.length - 1];
content.push(`<tr>`);
content.push(`<td>${testName}</td>`);
content.push(`<td>${test.status === "passed" ? "✅ Pass" : "❌ Fail"}</td>`);
content.push(`<td>${test.duration / 1000}s</td>`);
content.push(`<td>${test.title}</td>`);
content.push(`<td>${result.status === "passed" ? "✅ Pass" : "❌ Fail"}</td>`);
content.push(`<td>${result.duration / 1000}s</td>`);
content.push(`<td>${result.retry}</td>`);
content.push(`</tr>`);

@@ -24,0 +27,0 @@ }

@@ -19,19 +19,28 @@ "use strict";

},
{
data: "Retries",
header: true,
},
],
];
for (const testName of Object.keys(tests)) {
const test = tests[testName];
for (const test of tests) {
// Get the last result
const result = test.results[test.results.length - 1];
tableRows.push([
{
data: testName,
data: test.title,
header: false,
},
{
data: test.status === "passed" ? "✅ Pass" : "❌ Fail",
data: result.status === "passed" ? "✅ Pass" : "❌ Fail",
header: false,
},
{
data: `${test.duration / 1000}s`,
data: `${result.duration / 1000}s`,
header: false,
},
{
data: `${result.retry}`,
header: false,
},
]);

@@ -38,0 +47,0 @@ }

{
"name": "@estruyf/github-actions-reporter",
"version": "1.0.0",
"version": "1.1.0-beta.5902595",
"description": "GitHub Actions reporter for Playwright",

@@ -42,2 +42,2 @@ "main": "dist/index.js",

}
}
}