Skip to content

Commit 51722d5

Browse files
Merge pull request #26 from iExecBlockchainComputing/feature/coverage
Display coverage in Github PR checks
2 parents 619bfa6 + 667f949 commit 51722d5

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

.github/workflows/coverage.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- develop
5+
- main
6+
7+
jobs:
8+
coverage:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
- name: Init
14+
run: npm ci
15+
- name: Run Coverage
16+
run: (npm run coverage 2>&1) | tee /tmp/coverage.out | cat
17+
- name: Extract coverage
18+
run: echo "COVERAGE=$(cat /tmp/coverage.out | grep "Global test coverage")" >> $GITHUB_ENV
19+
- name: Display coverage in Github PR checks
20+
# See https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run
21+
# and https://www.kenmuse.com/blog/creating-github-checks/
22+
env:
23+
GH_TOKEN: ${{ github.token }}
24+
run: | # TODO: Set "failure" conclusion if coverage is too low
25+
curl -L -X POST \
26+
-H "Accept: application/vnd.github+json" \
27+
-H "Authorization: Bearer $GH_TOKEN"\
28+
-H "X-GitHub-Api-Version: 2022-11-28" \
29+
https://api.github.com/repos/${{ github.repository }}/check-runs \
30+
-d '{"name":"Coverage ratio", "head_sha":"${{ github.event.pull_request.head.sha }}", "status":"completed", "conclusion":"success", "output":{"title":"${{env.COVERAGE}}", "summary":""}}'
31+

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## vNext
4+
- Display coverage in Github PR checks. (#26)
45
- Add integration test suite. (#21)
56
- Add unit test suite. (#20)
67

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ A subgraph to explore the PoCo smarcontracts
44

55
[CHANGELOG](./CHANGELOG.md)
66

7+
# Setup coverage⁠
8+
9+
> In order for Matchstick to check which handlers are being run, those handlers need to be exported from the test file.
10+
11+
Check how to export handlers with [Matchstick - Test Coverage documentation](https://thegraph.com/docs/en/subgraphs/developing/creating/unit-testing-framework/#test-coverage).
12+
13+
> [!NOTE]
14+
> Since Matchstick code coverage is in very early stages, Matchstick cannot check for branch coverage, but rely on the assertion that a given handler has been called.
15+
16+
717
## local dev
818

919
run local services:

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"prepare": "husky",
88
"codegen": "graph codegen subgraph.template.yaml",
99
"test": "npm run codegen && graph test",
10+
"coverage": "npm run codegen && graph test -- -c",
1011
"test-docker": "npm run codegen && docker run -it --rm -v $(pwd):/matchstick/subgraph rainprotocol/matchstick:main",
1112
"build": "npm run codegen && cp subgraph.template.yaml subgraph.yaml && graph build --network ${NETWORK_NAME:-bellecour}",
1213
"create": "graph create ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020}",

test/Modules/IexecCategoryManager.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { ethereum } from '@graphprotocol/graph-ts';
55
import { assert, describe, newTypedMockEventWithParams, test } from 'matchstick-as/assembly/index';
66
import { CreateCategory } from '../../generated/Core/IexecInterfaceToken';
7-
import { handleCreateCategory } from '../../src/Modules/IexecCategoryManager';
7+
import { handleCreateCategory } from '../../src/Modules';
88

99
describe('IexecCategoryManager', () => {
1010
test('Should handle CreateCategory', () => {
@@ -33,3 +33,5 @@ describe('IexecCategoryManager', () => {
3333
});
3434
});
3535
});
36+
37+
export { handleCreateCategory };

test/Modules/IexecPoco.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ describe('IexecPoco', () => {
4040
assert.fieldEquals('Transaction', transactionId, 'id', transactionId);
4141
});
4242
});
43+
44+
export { handleDealSponsored };

0 commit comments

Comments
 (0)