Skip to content

Commit

Permalink
feat: Enhance testing and CI workflow
Browse files Browse the repository at this point in the history
- Updated the `.gitignore` file to include test artifacts and coverage reports, improving project cleanliness.
- Modified `package.json` to adjust the test command order and include coverage reporting for unit tests.
- Added a new GitHub Actions workflow (`test.yml`) to automate testing on push and pull request events, ensuring consistent quality checks.
- Created new tests for the home page using Playwright, verifying page load, link functionality, and image loading.
- Removed outdated test file (`test.ts`) to streamline the test suite.

These changes enhance the testing framework and CI/CD process, ensuring better code quality and reliability.
  • Loading branch information
jketcham committed Jan 6, 2025
1 parent 882fbc3 commit ea2e9f4
Show file tree
Hide file tree
Showing 6 changed files with 6,419 additions and 6,203 deletions.
137 changes: 137 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Test

on:
push:
branches: [main]
pull_request:
branches: [main]
# Also run when Dependabot creates PRs
pull_request_target:
branches: [main]

jobs:
test:
name: Build and Test
runs-on: ubuntu-latest
# Important for security when using pull_request_target
permissions:
contents: read
pull-requests: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Full git history for Dependabot PRs
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Type check
id: typecheck
continue-on-error: true
run: npm run check

- name: Lint
id: lint
continue-on-error: true
run: npm run lint

- name: Build
id: build
continue-on-error: true
run: npm run build

- name: Run unit tests
id: unit-tests
continue-on-error: true
run: npm run test:unit

- name: Install Playwright browsers
run: npx playwright install --with-deps chromium

- name: Run integration tests
id: integration-tests
continue-on-error: true
run: npm run test:integration

- name: Start preview server and test endpoints
id: preview
continue-on-error: true
run: |
npm run preview &
sleep 5
# Basic health check
curl -f http://localhost:4173/
# Test API endpoints
curl -f http://localhost:4173/api/weather
- name: Comment on PR
if: github.event_name == 'pull_request_target' && always()
uses: actions/github-script@v7
with:
script: |
// Store step outcomes
const outcomes = {
typecheck: '${{ steps.typecheck.outcome }}',
lint: '${{ steps.lint.outcome }}',
build: '${{ steps.build.outcome }}',
unitTests: '${{ steps.unit-tests.outcome }}',
integrationTests: '${{ steps.integration-tests.outcome }}',
preview: '${{ steps.preview.outcome }}'
};
// Convert outcome to emoji
const getEmoji = (outcome) => {
switch(outcome) {
case 'success': return '✅';
case 'failure': return '❌';
case 'skipped': return '⏭️';
default: return '❓';
}
};
// Check if any tests failed
const hasFailures = Object.values(outcomes).includes('failure');
const header = hasFailures ? '## Test Results ❌' : '## Test Results ✅';
const message = `${header}\n\n` +
'Build and test run completed.\n\n' +
'Details:\n' +
`- Type checking: ${getEmoji(outcomes.typecheck)}\n` +
`- Linting: ${getEmoji(outcomes.lint)}\n` +
`- Build: ${getEmoji(outcomes.build)}\n` +
`- Unit tests: ${getEmoji(outcomes.unitTests)}\n` +
`- Integration tests: ${getEmoji(outcomes.integrationTests)}\n` +
`- Preview: ${getEmoji(outcomes.preview)}\n\n` +
(hasFailures ? '⚠️ Some checks failed. Please review the workflow logs for details.\n\n' : '') +
'Full results available in workflow artifacts.';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
# Make the workflow fail if any tests failed
- name: Check for test failures
if: always()
run: |
if [[ "${{ steps.typecheck.outcome }}" == "failure" ]] || \
[[ "${{ steps.lint.outcome }}" == "failure" ]] || \
[[ "${{ steps.build.outcome }}" == "failure" ]] || \
[[ "${{ steps.unit-tests.outcome }}" == "failure" ]] || \
[[ "${{ steps.integration-tests.outcome }}" == "failure" ]] || \
[[ "${{ steps.preview.outcome }}" == "failure" ]]; then
echo "Some tests failed!"
exit 1
fi
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ node_modules
.vercel
/.svelte-kit
/build
/coverage
/playwright-report
/test-results
/tests-examples

# OS
.DS_Store
Expand All @@ -22,3 +26,8 @@ vite.config.ts.timestamp-*

# Wrangler
.wrangler

# Test artifacts
*.spec.js.snap
*.test.js.snap
/playwright/.cache/
Loading

0 comments on commit ea2e9f4

Please sign in to comment.