-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enhance testing and CI workflow
- 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
Showing
6 changed files
with
6,419 additions
and
6,203 deletions.
There are no files selected for viewing
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
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 |
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
Oops, something went wrong.