Skip to content

Code Coverage Pipeline & Discord Improvements โ€‹

Date: January 14, 2026
Status: โœ… Complete

Summary โ€‹

Implemented two major improvements:

  1. Custom code coverage pipeline - No more Playwright browser testing issues
  2. Enhanced Discord deployment messages - Shows exactly what failed

1. Custom Code Coverage Pipeline โœ… โ€‹

Problem Solved โ€‹

npm test:coverage was failing due to:

  • โŒ Playwright browser installation issues (missing system dependencies)
  • โŒ Storybook vitest addon conflicts with coverage mode
  • โŒ Browser mode conflicts with jsdom environment

Solution Implemented โ€‹

Simplified test configuration:

  • Removed Playwright browser testing from vitest config
  • Disabled Storybook vitest plugin for code coverage
  • Set up jsdom environment for DOM testing
  • Enhanced test.setup.js with proper mocks

Files Changed โ€‹

  1. vitest.config.js

    • Removed Playwright browser mode
    • Set environment to jsdom
    • Simplified plugin configuration
  2. test.setup.js

    • Added DOM mocking (IntersectionObserver, matchMedia)
    • Added cleanup after each test
    • Added jsdom polyfills
  3. package.json

    • Added @testing-library/user-event dependency

New GitHub Actions Workflow โ€‹

Created: .github/workflows/coverage.yml

  • Generates code coverage reports automatically
  • Creates coverage badges (visual indicators)
  • Uploads coverage reports to artifacts
  • Comments on PRs with coverage summary
  • Validates against coverage thresholds (configurable)

How to Use It โ€‹

Local testing:

bash
# Run tests with coverage report
npm run test:coverage

# Output: displays coverage percentages
# Creates coverage/html/index.html for detailed report

In GitHub:

  • Coverage workflow runs on every push to dev/main and on PRs
  • Generates artifacts in coverage/ directory
  • PR comments show coverage changes
  • Links to full HTML coverage report

Coverage Output โ€‹

Test Files  3 passed (3)
Tests  13 passed (13)

% Coverage report from v8
-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |   78.49 |    54.28 |      90 |   79.77 |                   
 src/firebase.js   |      64 |    28.57 |     100 |   64.58 |                   
 src/components... |      80 |       75 |     100 |     100 |                   
-------------------|---------|----------|---------|---------|-------------------

2. Enhanced Discord Deployment Messages โœ… โ€‹

What Changed โ€‹

Before:

**App:** โœ…
**Storybook:** โŒ
**Docs:** โœ…
**Firebase:** โœ…

After:

**Services:**
โ€ข App: โœ… [dev.ourlantern.app](https://dev.ourlantern.app)
โ€ข Storybook: โŒ Failed
โ€ข Docs: โœ… [docs.dev.ourlantern.app](https://docs.dev.ourlantern.app)
โ€ข Firebase: โœ… Rules & Indexes Deployed

**Failures:**
โ€ข Storybook: failure

Improvements โ€‹

  1. Service links are clickable - Direct links to deployed services in Discord
  2. Clear failure indicators - Shows which services actually failed
  3. Detailed failure reasons - Lists failure types (success, failure, skipped)
  4. Links to failed workflow - Click through to GitHub Actions for logs

Files Modified โ€‹

  1. .github/workflows/deploy-dev.yml

    • Enhanced status determination
    • Tracks failure reasons
    • Better formatted Discord message
    • Link to GitHub Actions run
  2. .github/workflows/deploy-prod.yml

    • Same improvements as dev
    • Uses DISCORD_WEBHOOK_PROD_DEPLOY

Discord Message Example โ€‹

Success Message:

๐Ÿš€ Development Deployment โœ… Success

Environment: Development
Branch: dev
Commit: abc1234

Services:
โ€ข App: โœ… [dev.ourlantern.app](https://dev.ourlantern.app)
โ€ข Storybook: โœ… [storybook.dev.ourlantern.app](...)
โ€ข Docs: โœ… [docs.dev.ourlantern.app](...)
โ€ข Firebase: โœ… Rules & Indexes Deployed

Deployed by: @username

Failure Message:

๐Ÿš€ Development Deployment โŒ Failed

Environment: Development
Branch: dev
Commit: abc1234

Services:
โ€ข App: โœ… [dev.ourlantern.app](...)
โ€ข Storybook: โŒ Failed
โ€ข Docs: โœ… [docs.dev.ourlantern.app](...)
โ€ข Firebase: โŒ Rules/Indexes Failed

Failures:
โ€ข Storybook: failure
โ€ข Firebase Rules: failure

Deployed by: @username

How It Works โ€‹

Code Coverage Workflow โ€‹

Push to dev/main or PR
        โ†“
Run tests with coverage (npm run test:coverage)
        โ†“
Generate reports (HTML, JSON, LCOV)
        โ†“
Create coverage badge
        โ†“
Upload artifacts
        โ†“
(Optional) Comment on PR with summary
        โ†“
Validate against thresholds

Discord Notification Flow โ€‹

Deployment Jobs (App, Storybook, Docs, Firebase)
        โ†“
Check each job's result status
        โ†“
Build list of failures if any
        โ†“
Create formatted Discord message with:
  - Overall status (โœ… or โŒ)
  - Each service with link
  - Failure details if any
  - Link to GitHub Actions
        โ†“
Send to Discord webhook

Configuration โ€‹

Code Coverage Thresholds โ€‹

Edit coverage.yml to set thresholds:

yaml
- name: Check coverage thresholds
  run: |
    THRESHOLD=50  # Change this number
    # Current: 50% (MVP threshold)
    # Recommended for beta: 70%
    # Recommended for production: 80%

Discord Webhook Secrets โ€‹

Make sure these are set in GitHub (Settings โ†’ Secrets):

  • DISCORD_WEBHOOK_COMMITS - For commit notifications
  • DISCORD_WEBHOOK_DEV_DEPLOY - For dev deployments
  • DISCORD_WEBHOOK_PROD_DEPLOY - For prod deployments

Testing the Setup โ€‹

Test Code Coverage Locally โ€‹

bash
cd /home/mechelle/repos/lantern_app
npm run test:coverage

Expected output:

  • โœ… Tests run successfully
  • โœ… Coverage report generated
  • โœ… HTML report at coverage/index.html

Test Discord Messages โ€‹

Push a commit to dev branch:

  1. Check #commits channel โ†’ should see commit notification
  2. Wait for deployment to complete
  3. Check #deployments channel โ†’ should see deployment status

Files Summary โ€‹

Modified:
  vitest.config.js                          โ† Simplified config
  test.setup.js                             โ† DOM setup
  .github/workflows/deploy-dev.yml          โ† Enhanced Discord
  .github/workflows/deploy-prod.yml         โ† Enhanced Discord
  package.json                              โ† Added test-library user-event

Created:
  .github/workflows/coverage.yml            โ† New coverage pipeline

Next Steps โ€‹

Immediate (Now) โ€‹

  • โœ… Test npm run test:coverage locally
  • โœ… Verify Discord messages show failures properly
  • โœ… Check coverage reports in artifacts

Short Term (Before Beta) โ€‹

  • [ ] Set coverage threshold (currently 50%)
  • [ ] Review failed deployment messages in Discord
  • [ ] Test rollback procedure

Medium Term (Beta Launch) โ€‹

  • [ ] Increase coverage threshold to 70%+
  • [ ] Add more unit tests
  • [ ] Consider CODECOV_TOKEN if coverage tracking needed

Troubleshooting โ€‹

Tests still failing with "document is not defined" โ€‹

Fix: Make sure environment: 'jsdom' is in vitest.config.js

Coverage reports not generating โ€‹

Check:

  1. No syntax errors in coverage.yml
  2. Tests are passing (at least 1 passing test)
  3. Check GitHub Actions logs for errors

Discord messages not showing failure details โ€‹

Check:

  1. Webhook URLs are valid (DISCORD_WEBHOOK_DEV_DEPLOY, etc.)
  2. Discord servers haven't rate-limited us
  3. Try manually posting to test webhook

Coverage artifact not uploading โ€‹

Check:

  1. Tests completed (even if some failed)
  2. Coverage directory exists at coverage/
  3. Retention days not set to 0

See Also โ€‹

Built with VitePress