Skip to content

Commit

Permalink
Fix GH actions issue when the CLI app would falls over if the Playwri…
Browse files Browse the repository at this point in the history
…ght config does not have retries defined. (#77)

* Fix GH actions issue

* Update playwright-slack-report command to use merged_tests_results.json
  • Loading branch information
ryanrosello-og authored Dec 13, 2023
1 parent 29c4e69 commit 9ef6570
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 👎🥺
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/ResultsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9ef6570

Please sign in to comment.