Run unit test when creating a PR
Run Jest unit test
- We need to enable
Run workflows from fork pull requests
to get workflow triggered.- Go to setting of enterprise, organization or repository settings.
- Example URL of an organization settings URL: https://github.com/organizations/your-oganization-name/settings/profile.
- Go to Actions > Fork pull request workflows section
- Check
Run workflows from fork pull requests
- Click
Save
- Example of workflow:
name: Run unit test workflowon: pull_request # Pull request on any branchesenv:NODE_VERSION: 14.x # Set this to change the Node.js version to usejobs:run_unit_test:name: Run unit test# Find more virtual environment. https://github.com/actions/virtual-environmentsruns-on: ubuntu-18.04steps:- name: Checkout the latest source code from the current branchuses: actions/checkout@v2- name: Use Node.js version ${{ env.NODE_VERSION }}# https://github.com/actions/setup-nodeuses: actions/setup-node@v2with:node-version: ${{ env.NODE_VERSION }}- name: Run all test cases with Jest# https://classic.yarnpkg.com/en/docs/cli/workspaces/#toc-yarn-workspaces-run# Yarn Yarn 1.22.5 is already installed https://docs.github.com/en/actions/guides/building-and-testing-nodejs#installing-dependencies# https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1604-README.mdworking-directory: src # We must be in a path that has yarn workspaces package.jsonrun: |echo ${{ github.repository }}git rev-parse HEADgit log -1node --versionyarn --versionyarn installyarn run test
Result in GitHub PR checks
Run xUnit unit test
Coming soon
Useful links
Loading comments...