Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test results output #949

Closed
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9104c25
Test summary output
mihaisee Jun 13, 2023
86ba246
Removed debug logs
mihaisee Jun 15, 2023
212e2ff
Added some documentation for the testResultsObject output
mihaisee Jun 15, 2023
1e424a0
Test cypress testResultsObject output in example-recording.yml
mihaisee Jun 15, 2023
8188a63
Test cypress testResultsObject output in example-recording.yml
mihaisee Jun 15, 2023
63fc380
Skip parsing testResultsObject if empty
mihaisee Jun 16, 2023
3c0abeb
Update example-recording.yml
mihaisee Jun 21, 2023
53a3e26
Merge branch 'cypress-io:master' into feat/add-test-reults-output
mihaisee Jun 21, 2023
f9794b0
Update .gitignore
mihaisee Jun 26, 2023
06567f7
Merge branch 'master' into feat/add-test-reults-output
mihaisee Aug 1, 2023
b116a60
Merge branch 'master' into feat/add-test-reults-output
mihaisee Oct 4, 2023
ab2c53e
Removed the calculated success status from testResultsObject
mihaisee Oct 5, 2023
087d18b
Update docs and workflow to reflect removal of success property from …
mihaisee Oct 5, 2023
3a8d645
Updated testResultsObject to testResults default
mihaisee Oct 11, 2023
9624c3f
Merge branch 'master' into feat/add-test-reults-output
mihaisee Oct 11, 2023
4d47501
Updated testResultsObject to testResults default - update workflow
mihaisee Oct 11, 2023
f4402c5
Merge branch 'feat/add-test-reults-output' of github.com:mihaisee/git…
mihaisee Oct 11, 2023
7421400
Updated testResultsObject to testResults default - update workflow
mihaisee Oct 11, 2023
84f0d2a
Update .github/workflows/example-recording.yml
mihaisee Oct 12, 2023
18af1c0
Merge branch 'master' into feat/add-test-reults-output
mihaisee Oct 12, 2023
185d2ef
Update README.md
mihaisee Oct 12, 2023
7b06979
Merge branch 'master' into feat/add-test-reults-output
mihaisee Oct 20, 2023
4f33b71
Update action.yml
mihaisee Oct 20, 2023
d144906
updating to runResults
mschile Oct 23, 2023
6f3e59e
updating to runResults
mschile Oct 23, 2023
efff8c9
Merge branch 'master' into feat/add-test-reults-output
emilyrohrbough Oct 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/example-recording.yml
Expand Up @@ -73,6 +73,29 @@ jobs:
echo Cypress finished with: ${{ steps.cypress.outcome }}
echo See results at ${{ steps.cypress.outputs.resultsUrl }}

# print the `testResults` output directly as string
- name: Print Cypress test results output
run: |
echo Cypress test results: ${{ steps.cypress.outputs.testResults }}

# parse the `testResults` output as JSON.
# Note that the output is a string and empty if there is a custom command passed to the action and the command runs through CLI
- name: Parse the Cypress test results output
uses: actions/github-script@v6.4.1
mihaisee marked this conversation as resolved.
Show resolved Hide resolved
with:
script: |
if (${{ steps.cypress.outputs.testResults }} == "") {
console.log('No test results found')
return
}

const testResults = JSON.parse('${{ steps.cypress.outputs.testResults }}')
console.log("TotalPassed: " + testResults.totalPassed)
console.log("TotalFailed: " + testResults.totalFailed)
console.log("TotalPending: " + testResults.totalPending)
console.log("TotalSkipped: " + testResults.totalSkipped)
console.log("TotalDuration: " + testResults.totalDuration)

group:
runs-on: ubuntu-22.04
needs: [check-record-key]
Expand Down
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -1374,6 +1374,22 @@ The GitHub step output `dashboardUrl` is deprecated. Cypress Dashboard is now [C

**Note:** every GitHub workflow step can have `outcome` and `conclusion` properties. See the GitHub [Contexts](https://docs.github.com/en/actions/learn-github-actions/contexts) documentation section [steps context](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context). In particular, the `outcome` or `conclusion` value can be `success`, `failure`, `cancelled`, or `skipped` which you can use in any following steps.

It also sets a step output `testResults` which contains a stringified test results JSON object.
In order to use it you should parse the string into an object.
Ex:
```yaml
...
steps:
- name: Parse results
uses: actions/github-script@v6.4.1
mihaisee marked this conversation as resolved.
Show resolved Hide resolved
with:
script: |
const testResults = JSON.parse('${{ steps.cypress-run.outputs.testResults }}')
console.log(testResults.totalPassed)
...
```
Structure of the test results object can be found [here](https://docs.cypress.io/guides/guides/module-api#Results).

### Print Cypress info

Sometimes you might want to print Cypress and OS information, like the list of detected browsers. You can use the [`cypress info`](https://on.cypress.io/command-line#cypress-info) command for this.
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Expand Up @@ -96,6 +96,8 @@ outputs:
description: 'Cypress Cloud URL if the run was recorded (deprecated)'
resultsUrl:
description: 'Cypress Cloud URL if the run was recorded'
testResults:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this some more, we should probably name this runResults.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mschile

The documentation currently uses the term "test results"
https://docs.cypress.io/guides/guides/module-api#Results

image

so if the term is changed here, it should be changed in the Module API documentation as well.

description: 'Cypress test results stringifyed JSON object'
mihaisee marked this conversation as resolved.
Show resolved Hide resolved
runs:
using: 'node20'
main: 'dist/index.js'
Expand Down