Skip to content

Commit

Permalink
write to file
Browse files Browse the repository at this point in the history
  • Loading branch information
midleman committed Nov 9, 2024
1 parent ab2782c commit 79b5d7c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 35 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,27 @@ jobs:
- name: Run Playwright tests
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
continue-on-error: true

- name: Upload summary artifact
uses: actions/upload-artifact@v2
with:
name: playwright-summary-${{ matrix.shardIndex }}
path: playwright-summary-${{ matrix.shardIndex }}.md

e2e-report:
runs-on: ubuntu-latest
needs: [testing-matrix]
steps:
- name: Download all summaries
uses: actions/download-artifact@v4
with:
name: playwright-summary-*
path: combined-summaries

- name: Combine summaries
run: |
cat combined-summaries/playwright-summary-shard-*.md > combined-summaries/combined-summary.md
- name: Post combined summary to GitHub
run: |
cat combined-summaries/combined-summary.md >> $GITHUB_STEP_SUMMARY
64 changes: 29 additions & 35 deletions src/utils/processResults.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as core from "@actions/core";
import { SUMMARY_ENV_VAR } from "@actions/core/lib/summary";
import { Suite } from "@playwright/test/reporter";
import { existsSync, unlinkSync, writeFileSync } from "fs";
import { basename, join } from "path";
Expand All @@ -16,36 +14,32 @@ export const processResults = async (
suite: Suite | undefined,
options: GitHubActionOptions
) => {
if (process.env.NODE_ENV === "development") {
const summaryFile = join(__dirname, "../../summary.html");
if (existsSync(summaryFile)) {
unlinkSync(summaryFile);
}
writeFileSync(summaryFile, "", "utf-8");
process.env[SUMMARY_ENV_VAR] = summaryFile;
process.env.GITHUB_ACTIONS = "true";
}

if (process.env.GITHUB_ACTIONS && suite) {
const os = process.platform;
const summary = core.summary;

// Generate a unique summary file path using matrix.shardIndex
const shardIndex = process.env.SHARD_INDEX || "default";
const summaryFilePath = join(
process.cwd(),
`playwright-summary-${shardIndex}.md`
);

if (existsSync(summaryFilePath)) {
unlinkSync(summaryFilePath);
}

let summaryContent = "";

const summaryTitle = getSummaryTitle(options.title);
if (summaryTitle) {
summary.addHeading(summaryTitle, 1);
summaryContent += `# ${summaryTitle}\n\n`;
}
console.log(summaryTitle);

const headerText = getSummaryDetails(suite);
summary.addRaw(headerText.join(`  |  `));

// if (options.useDetails) {
// summary.addSeparator();
// }
summaryContent += headerText.join(`  |  `) + "\n\n";

for (const crntSuite of suite?.suites) {
for (const crntSuite of suite.suites) {
const project = crntSuite.project();

const tests = getTestsPerFile(crntSuite);

for (const filePath of Object.keys(tests)) {
Expand All @@ -60,17 +54,14 @@ export const processResults = async (
options.includeResults as DisplayLevel[]
);

if (!content) {
continue;
if (content) {
const testStatusIcon = getSuiteStatusIcon(tests[filePath]);
summaryContent += `<details><summary>${testStatusIcon} ${getTestHeading(
fileName,
os,
project
)}</summary>\n\n${content}\n\n</details>\n\n`;
}

// Check if there are any failed tests
const testStatusIcon = getSuiteStatusIcon(tests[filePath]);

summary.addDetails(
`${testStatusIcon} ${getTestHeading(fileName, os, project)}`,
content
);
} else {
const tableRows = await getTableRows(
tests[filePath],
Expand All @@ -81,13 +72,16 @@ export const processResults = async (
);

if (tableRows.length !== 0) {
summary.addHeading(getTestHeading(fileName, os, project), 2);
summary.addTable(tableRows);
summaryContent += `## ${getTestHeading(fileName, os, project)}\n\n`;
summaryContent +=
"| Test | Result | Details |\n| --- | --- | --- |\n";
summaryContent +=
tableRows.map((row) => row.join(" | ")).join("\n") + "\n\n";
}
}
}
}

await summary.write();
writeFileSync(summaryFilePath, summaryContent, "utf-8");
}
};

0 comments on commit 79b5d7c

Please sign in to comment.