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/summary folded #44

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/suite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: suite

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

jobs:
testing:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: npm install
- name: Build
run: npx tsc
- name: Test suite folded with filepath
run: node dist/index.js suite-folded ctrf-reports/ctrf-report.json --title "Suite folded"
- name: Test suite folded with suite
run: node dist/index.js suite-folded ctrf-reports/ctrf-report.json --title "Suite folded" --useSuite
- name: Test suite folded no fails and filepath
run: node dist/index.js suite-folded ctrf-reports/ctrf-report.json --title "Suite folded"
- name: Test suite folded no fails and suite
run: node dist/index.js suite-folded ctrf-reports/ctrf-report.json --title "Suite folded" --useSuite
- name: Test suite folded pull request
run: node dist/index.js suite-folded ctrf-reports/ctrf-report.json --title "Suite folded" --useSuite --pull-request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: ctrf-report
path: ctrf-reports/ctrf-report.json
- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: custom-artifact-name
path: ctrf-reports/ctrf-report-no-fails.json
68 changes: 11 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,6 @@ For a failed test details table, add the `failed` command to your workflow yaml:
if: always()
```

### Generating Failed Folded Test Details Table

For a failed test table with details folded, add the `failed-folded` command to your workflow yaml:

```yaml
- name: Publish CTRF Failed Test Summary Results
run: npx github-actions-ctrf failed-folded path-to-your-ctrf-report.json
if: always()
```

### Generating Failed Rate Test Details Table

To see the failed test rate over time, add the `failed-rate` command to your workflow yaml:
Expand Down Expand Up @@ -181,6 +171,16 @@ To see which tests were skipped or pending, add the `skipped` command to your wo
if: always()
```

### Generating Suite Folded Table

To see which tests grouped by suite with tests folkded, add the `suite-folded` command to your workflow yaml:

```yaml
- name: Publish CTRF Suite Folded Summary
run: npx github-actions-ctrf suite-folded path-to-your-ctrf-report.json
if: always()
```

### Generating Previous Tests Table

To see results from previous tests, add the `historical` command to your workflow yaml:
Expand Down Expand Up @@ -442,48 +442,6 @@ Overall Fail Rate across all tests is calculated by summing the fail counts and

Overall Fail Rate (%) = (Total Fail Counts of All Tests ÷ Total Runs of All Tests) × 100

## Alternative Installation Options

### Locking to a Specific Version with `npx`

The easiest way to run `github-actions-ctrf` is by using `npx`, which doesn't require installation. By default, it runs the latest version. However, if you'd like to lock to a specific version, you can do so by specifying the version:

```bash
npx github-actions-ctrf@1.2.3 path-to-your-ctrf-report.json
```

This command will download and run the specified version of `github-actions-ctrf`.

### Local Installation in Your Node.js Project

For users who prefer installing the package locally to their project, you can install `github-actions-ctrf` as a project dependency:

```bash
npm install github-actions-ctrf
```

This will install `github-actions-ctrf` into your `node_modules` folder, and you can run it with the following command:

```bash
./node_modules/.bin/github-actions-ctrf path-to-your-ctrf-report.json
```

Alternatively, you can add a script to your `package.json` to simplify the command:

```json
{
"scripts": {
"report": "github-actions-ctrf path-to-your-ctrf-report.json"
}
}
```

Now, you can run:

```bash
npm run report
```

## Components

[Click here](https://github.com/ctrf-io/github-actions-ctrf/actions) to see the Actions of this repository for a full example
Expand All @@ -500,13 +458,9 @@ npm run report

![Failed](images/failed.png)

### Failed Folded details

![Failed Folded](images/failed-folded.png)

### Failed rate

![Failed Rate](images/failed-rate.png)
![Failed](images/failed-rate.png)

### AI summary

Expand Down
44 changes: 33 additions & 11 deletions ctrf-reports/ctrf-report-no-fails.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,89 @@
{
"name": "should be able to login",
"status": "passed",
"duration": 1200
"duration": 1200,
"filePath": "tests/login.test.ts",
"suite": "login.test.ts > login"
},
{
"name": "should display profile information",
"status": "passed",
"duration": 800,
"message": "Assertion Failure: profile mismatch",
"trace": "ProfileTest.js:45"
"trace": "ProfileTest.js:45",
"filePath": "tests/login.test.ts",
"suite": "login.test.ts > profile"
},
{
"name": "should be able to update profile",
"status": "passed",
"duration": 1200,
"flaky": false,
"retries": 2
"retries": 2,
"filePath": "tests/login.test.ts",
"suite": "login.test.ts > profile"
},
{
"name": "should be able to logout",
"status": "skipped",
"duration": 0
"duration": 0,
"filePath": "tests/login.test.ts",
"suite": "login.test.ts > login"
},
{
"name": "should validate user settings",
"status": "passed",
"duration": 1100
"duration": 1100,
"filePath": "tests/settings.test.ts",
"suite": "settings.test.ts > settings"
},
{
"name": "should fail to update profile on network failure",
"status": "passed",
"duration": 900,
"message": "Network Timeout",
"trace": "ProfileUpdateTest.js:60"
"trace": "ProfileUpdateTest.js:60",
"filePath": "tests/network.test.ts",
"suite": "network.test.ts > network"
},
{
"name": "should fail to update profile on network failure",
"status": "passed",
"duration": 900
"duration": 900,
"filePath": "tests/network.test.ts",
"suite": "network.test.ts > network"
},
{
"name": "should load user data",
"status": "pending",
"duration": 0
"duration": 0,
"filePath": "tests/common.test.ts",
"suite": "common.test.ts > network"
},
{
"name": "should handle session timeouts",
"status": "passed",
"duration": 950,
"flaky": false,
"retries": 1
"retries": 1,
"filePath": "tests/common.test.ts",
"suite": "common.test.ts > network"
},
{
"name": "should clean up user session on logout",
"status": "other",
"duration": 1050
"duration": 1050,
"filePath": "tests/common.test.ts",
"suite": "common.test.ts > network"
},
{
"name": "should allow user to change password",
"status": "passed",
"duration": 1300,
"flaky": false,
"retries": 3
"retries": 3,
"filePath": "tests/common.test.ts",
"suite": "common.test.ts > network"
}
]
}
Expand Down
42 changes: 31 additions & 11 deletions ctrf-reports/ctrf-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,58 @@
{
"name": "should be able to login",
"status": "passed",
"duration": 1200
"duration": 1200,
"filePath": "tests/login.test.ts",
"suite": "login.test.ts > login"
},
{
"name": "should display title",
"status": "failed",
"duration": 800,
"message": "\u001b[31mTimed out 5000ms waiting for \u001b[39m\u001b[2mexpect(\u001b[22m\u001b[31mlocator\u001b[39m\u001b[2m).\u001b[22mtoHaveTitle\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m)\u001b[22m\n\nLocator: locator(':root')\nExpected pattern: \u001b[32m/Playwrc cight/\u001b[39m\nReceived string: \u001b[31m\"Fast and reliable end-to-end testing for modern web apps | Playwright\"\u001b[39m\nCall log:\n \u001b[2m- expect.toHaveTitle with timeout 5000ms\u001b[22m\n\u001b[2m - waiting for locator(':root')\u001b[22m\n\u001b[2m - locator resolved to <html lang=\"en\" dir=\"ltr\" data-theme=\"light\" data-has-…>…</html>\u001b[22m\n\u001b[2m - unexpected value \"Fast and reliable end-to-end testing for modern web apps | Playwright\"\u001b[22m\n",
"trace": "ProfileTest.js:45",
"ai": "The test failed because the page title didn't match the expected value within the given timeout period.\n\nTo resolve this issue, you should first check if the title of the page is correct in your application. It seems there might be a typo or a misunderstanding about what the actual title should be. If 'Common Test Report Format' is indeed the correct title, you'll need to update your test expectations. On the other hand, if 'Uncommon Test Report Format' is the intended title, you'll need to fix the title in your application code.\n\nAnother possibility is that the page might be taking longer to load than expected, causing the title to not appear within the 5-second timeout. In this case, you could try increasing the timeout duration in your test to give the page more time to load completely."
"ai": "The test failed because the page title didn't match the expected value within the given timeout period.\n\nTo resolve this issue, you should first check if the title of the page is correct in your application. It seems there might be a typo or a misunderstanding about what the actual title should be. If 'Common Test Report Format' is indeed the correct title, you'll need to update your test expectations. On the other hand, if 'Uncommon Test Report Format' is the intended title, you'll need to fix the title in your application code.\n\nAnother possibility is that the page might be taking longer to load than expected, causing the title to not appear within the 5-second timeout. In this case, you could try increasing the timeout duration in your test to give the page more time to load completely.",
"filePath": "tests/login.test.ts",
"suite": "login.test.ts > profile"
},
{
"name": "should be able to update profile",
"status": "passed",
"duration": 1200,
"flaky": true,
"retries": 2
"retries": 2,
"filePath": "tests/login.test.ts",
"suite": "login.test.ts > profile"
},
{
"name": "should be able to logout",
"status": "skipped",
"duration": 0
"duration": 0,
"filePath": "tests/login.test.ts",
"suite": "login.test.ts > login"
},
{
"name": "should validate user settings",
"status": "passed",
"duration": 1100
"duration": 1100,
"filePath": "tests/settings.test.ts",
"suite": "settings.test.ts > settings"
},
{
"name": "should fail to update profile on network failure",
"status": "failed",
"duration": 900,
"message": "Network Timeout",
"trace": "ProfileUpdateTest.js:60"
"trace": "ProfileUpdateTest.js:60",
"filePath": "tests/network.test.ts",
"suite": "network.test.ts > network"
},
{
"name": "should fail to update profile on network failure",
"status": "failed",
"duration": 900
"duration": 900,
"filePath": "tests/network.test.ts",
"suite": "network.test.ts > network"
},
{
"name": "should load user data",
Expand All @@ -66,20 +80,26 @@
"status": "passed",
"duration": 950,
"flaky": true,
"retries": 1
"retries": 1,
"filePath": "tests/network.test.ts",
"suite": "network.test.ts > network"
},
{
"name": "should clean up user session on logout",
"status": "other",
"duration": 1050
"duration": 1050,
"filePath": "tests/network.test.ts",
"suite": "network.test.ts > network"
},
{
"name": "should allow user to change password",
"status": "passed",
"duration": 1300,
"flaky": true,
"retries": 3
"retries": 3,
"filePath": "tests/network.test.ts",
"suite": "network.test.ts > network"
}
]
}
}
}
Binary file added images/suite-folded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-actions-ctrf",
"version": "0.0.46",
"version": "0.0.47",
"description": "View test results directly within your GitHub workflow summary and Pull Requests",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 14 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ export function validateCtrfFile(filePath: string): CtrfReport | null {
return null
}

export function formatDurationHumanReadable(durationMs: number): string {
if (durationMs < 1) {
return `1ms`
} else if (durationMs < 1000) {
return `${Math.floor(durationMs)}ms`
} else if (durationMs < 60000) {
return `${(durationMs / 1000).toFixed(1)}s`
} else {
const minutes = Math.floor(durationMs / 60000)
const seconds = Math.floor((durationMs % 60000) / 1000)
return `${minutes}m${seconds}s`
}
}

export function extractGithubProperties() {
const eventPath = process.env.GITHUB_EVENT_PATH

Expand Down
Loading
Loading