Add Cypress run to GitHub Actions workflow #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: node_mongo CI | |
on: | |
pull_request: | |
push: | |
branches: [ main ] | |
paths: [ node_mongo/** ] | |
workflow_dispatch: | |
env: | |
node_app_root: node_mongo | |
jobs: | |
jest: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repo | |
uses: actions/checkout@v4 | |
- name: Install modules | |
run: npm install | |
working-directory: ${{ env.node_app_root }} | |
- name: Install Jest | |
run: npm install --global jest | |
working-directory: ${{ env.node_app_root }} | |
- name: Run Jest | |
run: jest --json --outputFile=jest_results.json | |
working-directory: ${{ env.node_app_root }} | |
- name: Test Summary | |
run: | | |
echo '### Tests' >> $GITHUB_STEP_SUMMARY | |
echo '| | Total | Passed | Pending | Failed |' >> $GITHUB_STEP_SUMMARY | |
echo '|---|:-----:|:------:|:-------:|:------:|' >> $GITHUB_STEP_SUMMARY | |
jq --raw-output '["suites", .numTotalTestSuites, .numPassedTestSuites, .numPendingTestSuites, .numFailedTestSuites]|join(" | ")' jest_results.json >> $GITHUB_STEP_SUMMARY | |
jq --raw-output '["tests", .numTotalTests, .numPassedTests, .numPendingTests, .numFailedTests]|join(" | ")' jest_results.json >> $GITHUB_STEP_SUMMARY | |
jq --raw-output '[.testResults[].assertionResults]|flatten|map(select(.status == "failed"))[]|[(.ancestorTitles|join(" >> ")),.title]|join(" | ")' jest_results.json >> failed.md | |
if [[ -s failed.md ]] | |
then | |
echo '' >> $GITHUB_STEP_SUMMARY | |
echo '### Failed Tests' >> $GITHUB_STEP_SUMMARY | |
echo '| Suite | Test |' >> $GITHUB_STEP_SUMMARY | |
echo '|-------|------|' >> $GITHUB_STEP_SUMMARY | |
cat failed.md >> $GITHUB_STEP_SUMMARY | |
fi | |
jq --raw-output '[.testResults[].assertionResults]|flatten|map(select(.status == "pending"))[]|[(.ancestorTitles|join(" >> ")),.title]|join(" | ")' jest_results.json >> pending.md | |
if [[ -s pending.md ]] | |
then | |
echo '' >> $GITHUB_STEP_SUMMARY | |
echo '### Pending (Skipped) Tests' >> $GITHUB_STEP_SUMMARY | |
echo '| Suite | Test |' >> $GITHUB_STEP_SUMMARY | |
echo '|-------|------|' >> $GITHUB_STEP_SUMMARY | |
cat pending.md >> $GITHUB_STEP_SUMMARY | |
fi | |
working-directory: ${{ env.node_app_root }} | |
if: always() | |
cypress: | |
runs-on: ubuntu-latest | |
services: | |
mongo: | |
image: mongo | |
steps: | |
- name: Checkout the repo | |
uses: actions/checkout@v4 | |
- name: Cypress run | |
uses: cypress-io/github-action@v6 | |
with: | |
config-file: cypress.config.ci.js | |
working-directory: ${{ env.node_app_root }} | |
env: | |
MONGODB_URI: mongodb://mongo/node_mongo_book_reviews_test | |
JWT_SECRET: thisIsANotSoSecretTestSecretinDocker |