-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
test: add testing groups and browser testing environment #728
Conversation
This reverts commit df2e508.
Coverage report❌ An unexpected error occurred. For more details, check console
Show files with reduced coverage 🔻
Test suite run failedFailed tests: 1/643. Failed suites: 1/99.
Report generated by 🧪jest coverage report action from 5e7427c |
@arboleya I think we definitely can. Let me get on it |
@arboleya I've made it so that the newly added workflows will only run for this PR's branch. I think we can safely merge this to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had some notes
- name: CI Setup | ||
uses: ./.github/actions/ci-setup | ||
|
||
- name: Build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These steps are repeated and should all be abstracted away into composite actions, such as a wrapper like this:
https://github.com/FuelLabs/fuels-ts/blob/master/.github/actions/ci-setup/action.yaml
That would apply to all of these "setup" steps as well as the "coverage" and "teardown" steps after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also have you looked at using the advanced GitHub action called a test matrix?
Alongside the test matrix idea, you could also investigate fail-fast
or the similar continue-on-error
to let builds find the bad linting first, then bad unit tests, then get into the meaty stuff like e2e
jobs: | ||
node-e2e-tests: | ||
# only run this job if the base branch is dp/testing-groups | ||
if: ${{github.ref_name == '728/merge'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this check from all the files as this action only exists on your PR anyways, unless you had noticed some kind of weird side effect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are having to keep this here because we will need to merge this PR in before being fully done with this whole setup, as things stand. Please see: #728 (comment)
path: node-e2e-coverage | ||
|
||
- name: Merge all coverage reports | ||
run: npx istanbul-merge --out coverage-merged.json browser-unit-coverage/coverage-final.json browser-e2e-coverage/coverage-final.json node-unit-coverage/coverage-final.json node-e2e-coverage/coverage-final.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -6,6 +6,9 @@ import type { DecodedValue } from './coders/abstract-coder'; | |||
|
|||
const B256 = '0xd5579c46dfcc7f18207013e65b44e4cb4e2c2298f4ac457ba8f82743f31e930b'; | |||
|
|||
/* | |||
* @group node/unit | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if someone forgets to mark the group in the file?
Usually when I split tests out into different groups I just change the file extension:
abi-coder.unit.test.ts
and
contract-usage.e2e.test.ts
For us maybe even:
contract-usage.node.e2e.test.ts
Easy to glob:
*.unit.test.ts
finds all unit tests
*.e2e.test.ts
finds all e2e tests
*.node.e2e.test.ts
finds all node e2e tests (feel free to make this shorter somehow)
*.test.ts
finds all tests
Its also easier to see in the file tree on GitHub/shell/IDE what kind of test a given file is without hunting through the file source for the group name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone forgets to mark the group, those tests won't run. I agree that this is not ideal and that's why I have switched to the approach you suggested instead. Things are running fine locally, but for some reason when I'm trying to run the tests in Github actions it's not being able to pattern match 🤔:
Run npx jest -- "**/*.node.unit.test.ts" --coverage
Invalid testPattern **/*.node.unit.test.ts|--coverage supplied. Running all tests instead.
package.json
Outdated
@@ -70,12 +70,14 @@ | |||
"forc-bin": "workspace:*", | |||
"husky": "^8.0.3", | |||
"jest": "^29.3.1", | |||
"jest-runner-groups": "^2.2.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its easier to change file names instead of adding a dependency to rely on that could cause issue
- name: Lint | ||
run: | | ||
pnpm lint | ||
|
||
- name: Checking PR Number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the Run tests and publish coverage
step below be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we merge this PR, we still want the rest of the repo to use this old test
action instead of the new one. More context here: #728 (comment)
That's why I have kept it intact still.
|
||
- name: Build | ||
run: | | ||
BUILD_VERSION="0.0.0-${{ github.ref_name }}-$(git rev-parse --short $GITHUB_SHA)" pnpm build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned, still need to at very least move these into an action
BUILD_VERSION="0.0.0-${{ github.ref_name }}-$(git rev-parse --short $GITHUB_SHA)" pnpm build | ||
|
||
- name: Browser unit tests | ||
run: npx jest -- "**/*.common.unit.test.ts" --setupFilesAfterEnv=./setup-puppeteer.ts --testTimeout=30000 --coverage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just launches puppeteer and then runs the tests on node?
@Dhaiwat10 Is it worth resolving conflicts here? Or would extracting the good parts/workflows into a new PR be easier? |
@arboleya not worth resolving the conflicts. I was planning on opening a new PR once the build tooling revamp was done since the Karma-Jasmine setup that we tried was having trouble reading the |
Closes #721
Summary
This PR makes use of
jest-runner-groups
to divide all of our tests into four testing groups:fuel-core
to be running in bgfuel-core
to be running in bgWorkflows
I have created four new GitHub workflows, each utilizing the grouping tags to pick the relevant set of tests that need to be tested in the given environment.
To emulate a browser environment, I am using
puppeteer
.Group Tagging
In this setup, we must ensure that our tests are always appropriately tagged with the relevant testing group (example).
If a new test is added but is not tagged, it will not run, and the checks for the given PR should fail. They should fail due to the resulting decrease in code-coverage percentage caused by the new source code addition for which the tests never ran.
To-do
README
, reflecting the project coverage statusFinal Notes
By enforcing a minimum coverage threshold, we can disable the
jest-coverage-report-action
, speeding up our checks by 50%, which will be huge.The rationale here is that this report action only serves the purpose of informing about coverage changes. In contrast, the new approach enforces a minimum threshold, guaranteeing an increased confidence level for our tests at each new PR.
Ideally, we'd have 100% coverage for everything. In the beginning, that will not be possible, but we can work it up with time while sticking to 100% regarding new additions.