From 9ef6570027d0d6f9946652eb3709bf92c1e58d40 Mon Sep 17 00:00:00 2001 From: ryanrosello-og <50574915+ryanrosello-og@users.noreply.github.com> Date: Wed, 13 Dec 2023 20:54:06 +1000 Subject: [PATCH] Fix GH actions issue when the CLI app would falls over if the Playwright config does not have retries defined. (#77) * Fix GH actions issue * Update playwright-slack-report command to use merged_tests_results.json --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++-- package.json | 2 +- src/ResultsParser.ts | 2 +- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0f5dfa4..e13d84e 100644 --- a/README.md +++ b/README.md @@ -184,9 +184,9 @@ The config file also supports the follow extra options: Once you have generated the JSON report and defined your config file, you can send it to Slack using the following command: -`SLACK_BOT_USER_OAUTH_TOKEN=[your Slack bot user OAUTH token] npx playwright-slack-report -c cli_config.json -j ./merged_tests_results.json` +`SLACK_BOT_USER_OAUTH_TOKEN=[your Slack bot user OAUTH token] npx playwright-slack-report -c cli_config.json -j > merged_tests_results.json` -Both the `-c` and `-j` options are required. The `-c` option is the path to your config file and the `-j` option is the path to your merged JSON report. +Both the `-c` and `-j` options are required. The `-c` option is the path to your config file and the `-j` option is the path to your merged JSON report. You will also need to pipe the output to a json file, using the `>` operator. ### Additional notes * The CLI currently does not support custom layouts 👎🥺 @@ -204,6 +204,45 @@ You will encounter the following error if the environment variable is not define This variable was found in the [meta] section of the config file, ensure the variable is set in your environment. ``` +### Sample Github Actions workflow + + +```yaml + ... + + merge-reports: + # Merge reports after playwright-tests, even if some shards have failed + if: always() + needs: [playwright-tests] + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Install dependencies + run: npm ci + + - name: Download blob reports from GitHub Actions Artifacts + uses: actions/download-artifact@v3 + with: + name: all-blob-reports + path: all-blob-reports + + - name: Merge into JSON Report + run: npx playwright merge-reports --reporter json ./all-blob-reports > merged_tests_results.json + + - name: View merged results + run: cat ${GITHUB_WORKSPACE}/merged_tests_results.json + + - name: Send report to Slack using CLI + env: + SLACK_BOT_USER_OAUTH_TOKEN: ${{ secrets.SLACK_BOT_USER_OAUTH_TOKEN }} + run: npx playwright-slack-report --config="${GITHUB_WORKSPACE}/cli_config.json" --json-results="${GITHUB_WORKSPACE}/merged_tests_results.json" + ... +``` + ```json { "sendResults": "always", diff --git a/package.json b/package.json index a38d64b..c13b66d 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "cli-debug": "yarn build && npx . -c ./cli_config.json -j ./tests/test_data/valid_test_results.json" }, "name": "playwright-slack-report", - "version": "1.1.55", + "version": "1.1.56", "bin": { "playwright-slack-report": "dist/cli.js" }, diff --git a/src/ResultsParser.ts b/src/ResultsParser.ts index fcff55e..6c91f1b 100644 --- a/src/ResultsParser.ts +++ b/src/ResultsParser.ts @@ -50,7 +50,7 @@ export default class ResultsParser { const data = fs.readFileSync(filePath, 'utf-8'); const parsedData: JSONResult = JSON.parse(data); - const { retries } = parsedData.config.projects[0]; + const retries = parsedData.config.projects[0]?.retries || 0; await this.parseTestSuite(parsedData.suites, retries); const failures = await this.getFailures();