Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Run Tests

on:
pull_request:
branches: ["main", "master"]
push:
branches: ["main", "master"]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Run linter
run: npm run lint

- name: Run tests
run: npm run test -- --run
env:
VITE_SUPABASE_URL: https://test.supabase.co
VITE_SUPABASE_ANON_KEY: test-key

- name: Build project
run: npm run build
env:
VITE_SUPABASE_URL: https://test.supabase.co
VITE_SUPABASE_ANON_KEY: test-key

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
coverage/
test-results/
retention-days: 30
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# TimeTracker Pro

[![Run Tests](https://github.com/adamjolicoeur/TimeTrackerPro/actions/workflows/test.yml/badge.svg)](https://github.com/adamjolicoeur/TimeTrackerPro/actions/workflows/test.yml)

A modern, feature-rich Progressive Web App (PWA) for time tracking built with React, TypeScript, and Tailwind CSS. Installable on desktop and mobile devices with full offline support. Perfect for freelancers, consultants, and professionals who need to track time, manage projects, and generate invoices.

![React](https://img.shields.io/badge/react-%2320232a.svg?style=for-the-badge&logo=react&logoColor=%2361DAFB) ![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white) ![Vite](https://img.shields.io/badge/vite-%23646CFF.svg?style=for-the-badge&logo=vite&logoColor=white) ![TailwindCSS](https://img.shields.io/badge/tailwindcss-%2338B2AC.svg?style=for-the-badge&logo=tailwind-css&logoColor=white) ![Supabase](https://img.shields.io/badge/Supabase-3ECF8E?style=for-the-badge&logo=supabase&logoColor=white) ![PWA](https://img.shields.io/badge/PWA-Enabled-5A0FC8?style=for-the-badge&logo=pwa&logoColor=white)
Expand Down
165 changes: 165 additions & 0 deletions docs/CI_CD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# CI/CD Documentation

## Overview

TimeTracker Pro uses GitHub Actions for continuous integration and continuous deployment. The CI/CD pipeline automatically runs tests, linting, and builds on every pull request and push to the main branch.

## Workflows

### Test Workflow (`.github/workflows/test.yml`)

**Triggers:**
- Pull requests to `main` or `master` branches
- Pushes to `main` or `master` branches

**Jobs:**
1. **Checkout code** - Retrieves the repository code
2. **Setup Node.js** - Configures Node.js 20.x environment
3. **Install dependencies** - Runs `npm ci` for clean install
4. **Run linter** - Executes ESLint to check code quality
5. **Run tests** - Runs the Vitest test suite (41 tests) with mock Supabase environment
6. **Build project** - Verifies the production build succeeds with mock Supabase environment
7. **Upload test results** - Archives test results and coverage (if generated)

**Environment Variables:**
The workflow sets mock Supabase credentials for testing:
- `VITE_SUPABASE_URL`: Test URL (not a real Supabase instance)
- `VITE_SUPABASE_ANON_KEY`: Test key (not a real key)

These are only used for CI/CD and are completely mocked in tests.

**Status Badge:**
The test workflow status is displayed at the top of the README.md file.

### Release Workflow (`.github/workflows/release.yml`)

Handles automated versioning and releases when pull requests are merged to main.

## Test Suite

The test suite includes 41 comprehensive tests covering:

### Test Files

1. **Date Parsing Tests** (`src/components/dateParsing.test.ts`) - 10 tests
- Verifies timezone-safe date parsing
- Tests date formatting consistency
- Validates edge cases (leap years, year boundaries)

2. **Time Utility Tests** (`src/utils/timeUtil.test.ts`) - 9 tests
- Duration formatting (H:MM format)
- Decimal hours conversion
- Date and time formatting

3. **Data Service Tests** (`src/services/dataService.test.ts`) - 10 tests
- localStorage persistence operations
- Current day save/load operations
- Archived days management
- Error handling for corrupted data

4. **TimeTracking Context Tests** (`src/contexts/TimeTracking.test.tsx`) - 12 tests
- Day management (start, end, archive)
- Task management (create, update, delete)
- Archive operations (update, delete, restore)
- Duration calculations

## Running Tests Locally

### Quick Test Run
```bash
npm run test
```

### Run Tests Once (CI Mode)
```bash
npm run test -- --run
```

### Run Linter
```bash
npm run lint
```

### Run Build
```bash
npm run build
```

### Run All CI Checks Locally
```bash
npm run lint && npm run test -- --run && npm run build
```

## Test Configuration

- **Framework**: Vitest
- **Environment**: jsdom (simulates browser environment)
- **Setup File**: `src/test-setup.ts`
- **Coverage**: Not yet configured (can be added)

## CI/CD Best Practices

### For Contributors

1. **Run tests locally** before pushing:
```bash
npm run lint
npm run test -- --run
npm run build
```

2. **Check CI status** on your pull request - all checks must pass before merging

3. **Fix failing tests** - Don't merge PRs with failing tests

4. **Keep tests updated** - Update tests when modifying functionality

### For Maintainers

1. **Review test results** in the Actions tab
2. **Don't merge PRs** with failing CI checks
3. **Monitor test coverage** and add tests for new features
4. **Keep dependencies updated** to avoid security vulnerabilities

## Troubleshooting

### Tests Fail Locally but Pass in CI (or vice versa)

1. **Node version mismatch** - CI uses Node 20.x, ensure you're using the same
2. **Dependency differences** - Run `npm ci` instead of `npm install`
3. **Environment variables** - Check if tests depend on env vars
4. **Timezone issues** - Tests use mocked dates to avoid timezone problems

### Lint Errors

```bash
npm run lint -- --fix
```

This will auto-fix many common linting issues.

### Build Failures

1. Check TypeScript errors: `npm run build`
2. Verify all imports are correct
3. Ensure all dependencies are installed

## Future Enhancements

Potential improvements to the CI/CD pipeline:

- [ ] Add test coverage reporting with codecov.io
- [ ] Add performance benchmarking
- [ ] Add visual regression testing with Playwright
- [ ] Add E2E tests for critical user flows
- [ ] Add automatic dependency updates with Dependabot
- [ ] Add security scanning with Snyk or similar
- [ ] Add bundle size tracking
- [ ] Add preview deployments for PRs

## Resources

- [GitHub Actions Documentation](https://docs.github.com/en/actions)
- [Vitest Documentation](https://vitest.dev/)
- [ESLint Documentation](https://eslint.org/)
- [Vite Build Documentation](https://vitejs.dev/guide/build.html)
Loading
Loading