e2e tests, and new github workflow for executing test runners

This commit is contained in:
Alicia Sykes committed 2025-09-22 22:29:53 +01:00
1 parent ee3e041fbf
commit 6b7ff84275
7 files changed
+222 -92

No files matched your search

+40 -47
View File
@@ -20,18 +20,17 @@ jobs:
- run: npm ci
- run: npm run build-check
# TODO: Fix linting issues, and then re-enable this job.
# lint:
# name: 🧼 Lint
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: 22
# cache: npm
# - run: npm ci
# - run: npm run lint
lint:
name: 🧼 Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run lint
format:
name: 💅 Format
@@ -43,7 +42,7 @@ jobs:
node-version: 22
cache: npm
- run: npm ci
- run: npm run format
- run: npx prettier --check src || (echo "⚠️ Formatting issues found" && exit 1)
types:
name: 🧩 Types
@@ -69,8 +68,8 @@ jobs:
- run: npm ci
- run: npm run check
deps_lockfile:
name: ⛓️‍💥 Deps • Lockfile integrity
test:
name: 🧪 Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@@ -79,9 +78,10 @@ jobs:
node-version: 22
cache: npm
- run: npm ci
- run: npm test
deps_audit:
name: 🔐 Deps • Audit (high+)
deps:
name: 🔒 Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@@ -89,19 +89,8 @@ jobs:
with:
node-version: 22
cache: npm
- run: npm ci --ignore-scripts
- run: npm ci
- run: npm audit --audit-level=high
deps_health:
name: 🩺 Deps • Peer/health
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci --ignore-scripts
- run: npm ls --all
summarize:
@@ -110,36 +99,40 @@ jobs:
if: always()
needs:
- build
# - lint
- lint
- format
- types
- svelte_check
- deps_lockfile
- deps_audit
- deps_health
- test
- deps
steps:
- name: Create summary
env:
BUILD: ${{ needs.build.result }}
# LINT: ${{ needs.lint.result }}
LINT: ${{ needs.lint.result }}
FORMAT: ${{ needs.format.result }}
TYPES: ${{ needs.types.result }}
SVCHK: ${{ needs.svelte_check.result }}
DEP_LOCK: ${{ needs.deps_lockfile.result }}
DEP_AUDIT: ${{ needs.deps_audit.result }}
DEP_HEALTH: ${{ needs.deps_health.result }}
TEST: ${{ needs.test.result }}
DEPS: ${{ needs.deps.result }}
run: |
em() { case "$1" in success) echo "✅";; failure) echo "❌";; cancelled|skipped) echo "⏭️";; *) echo "❔";; esac; }
line() { r="$1"; n="$2"; s="Failing"; [ "$r" = "success" ] && s="Passing"; echo "- $(em "$r") $n - $s"; }
line() { r="$1"; n="$2"; cmd="$3"; s="Passing"; [ "$r" != "success" ] && s="**Failing** - run \`$cmd\`"; echo "- $(em "$r") $n: $s"; }
{
echo "## PR Checks"
line "$BUILD" "Build"
line "$LINT" "Lint"
line "$FORMAT" "Format"
line "$TYPES" "Types"
line "$SVCHK" "Svelte Check"
line "$DEP_LOCK" "Deps - Lockfile"
line "$DEP_AUDIT" "Deps - Audit"
line "$DEP_HEALTH" "Deps - Health"
echo "## Check Summary"
line "$BUILD" "Build" "npm run build"
line "$LINT" "Lint" "npm run lint"
line "$FORMAT" "Format" "npm run format"
line "$TYPES" "Types" "npm run types"
line "$SVCHK" "Svelte Check" "npm run check"
line "$TEST" "Tests" "npm test"
line "$DEPS" "Dependencies" "npm audit --audit-level=high"
failed_count=$(echo "$BUILD $LINT $FORMAT $TYPES $SVCHK $TEST $DEPS" | tr ' ' '\n' | grep -c failure || echo "0")
if [ "$failed_count" -eq 0 ]; then
echo -e "\n🎉 **All checks passed!**"
else
echo -e "\n⚠️ **$failed_count check(s) failed** - please fix the issues above before merging."
fi
} >> "$GITHUB_STEP_SUMMARY"
+169 -34
View File
@@ -11,73 +11,208 @@ concurrency:
permissions:
contents: read
id-token: write # For OIDC with Codecov
checks: write # For test reporting
jobs:
tests:
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
kind: [unit, e2e]
env:
NODE_OPTIONS: "--max_old_space_size=8192"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- name: Install deps
run: npm ci
- name: Run unit tests
id: test
run: |
npx vitest run \
--reporter=github-actions \
--reporter=verbose \
--reporter=junit \
--outputFile=test-results.xml
continue-on-error: true
# --- Unit (Vitest) ---
- name: Run unit tests (Vitest + coverage)
if: matrix.kind == 'unit'
run: npm run test:coverage
- name: Upload unit coverage
if: matrix.kind == 'unit' && (success() || failure())
- name: Save test result
if: always()
run: echo "${{ steps.test.outcome }}" > test-result-unit.txt
- name: Upload test result
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-unit
path: coverage
if-no-files-found: ignore
name: test-result-unit
path: test-result-unit.txt
# --- E2E (Playwright) ---
- name: Install Playwright browsers
if: matrix.kind == 'e2e'
run: npx playwright install --with-deps
- name: Run e2e tests (Playwright)
if: matrix.kind == 'e2e'
run: npm run test:e2e -- --reporter=junit,html
- name: Upload e2e reports
if: matrix.kind == 'e2e' && (success() || failure())
- name: Upload coverage to Codecov
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
flags: unittests
name: ip-calc
fail_ci_if_error: false
continue-on-error: true
- name: Unit Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: Unit Tests
path: test-results.xml
reporter: java-junit
fail-on-error: false
- name: Upload coverage artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage
- name: Fail if tests failed
if: steps.test.outcome == 'failure'
run: exit 1
e2e-tests:
name: E2E Tests
runs-on: ubuntu-latest
env:
NODE_OPTIONS: "--max_old_space_size=8192"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- name: Get Playwright version
id: playwright-version
run: echo "version=$(npx playwright --version | awk '{print $2}')" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}
- name: Install Playwright
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps chromium
- name: Install Playwright deps only
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: npx playwright install-deps chromium
- name: Run e2e tests
id: test
run: npx playwright test
continue-on-error: true
- name: Save test result
if: always()
run: echo "${{ steps.test.outcome }}" > test-result-e2e.txt
- name: Upload test result
if: always()
uses: actions/upload-artifact@v4
with:
name: test-result-e2e
path: test-result-e2e.txt
- name: E2E Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: E2E Tests
path: e2e-results.xml
reporter: java-junit
fail-on-error: false
- name: Upload e2e artifacts
if: always() && steps.test.outcome != 'success'
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: |
playwright-report
test-results
if-no-files-found: ignore
- name: Fail if tests failed
if: steps.test.outcome == 'failure'
run: exit 1
summary:
name: Summary
runs-on: ubuntu-latest
if: always()
needs: [tests]
needs: [unit-tests, e2e-tests]
steps:
- name: Download test results
uses: actions/download-artifact@v4
with:
pattern: test-result-*
merge-multiple: true
- name: Write summary
env:
TESTS: ${{ needs.tests.result }} # success | failure | cancelled
UNIT_JOB: ${{ needs.unit-tests.result }}
E2E_JOB: ${{ needs.e2e-tests.result }}
run: |
# Read actual test results from artifacts (or use job result as fallback)
UNIT=$(cat test-result-unit.txt 2>/dev/null || echo "$UNIT_JOB")
E2E=$(cat test-result-e2e.txt 2>/dev/null || echo "$E2E_JOB")
em() { case "$1" in success) echo "✅";; failure) echo "❌";; cancelled|skipped) echo "⏭️";; *) echo "❔";; esac; }
verb() { [ "$1" = "success" ] && echo "Passing" || { [ "$1" = "cancelled" ] && echo "Skipped" || echo "Failing"; }; }
line() { r="$1"; n="$2"; cmd="$3"; s="Passing"; [ "$r" = "failure" ] && s="**Failing** - run \`$cmd\`"; [ "$r" = "skipped" ] && s="Skipped"; echo "- $(em "$r") $n: $s"; }
# Count test results for chart
passing=0; failing=0; skipped=0; unknown=0
for result in "$UNIT" "$E2E"; do
case "$result" in
success) passing=$((passing + 1)) ;;
failure) failing=$((failing + 1)) ;;
skipped) skipped=$((skipped + 1)) ;;
*) unknown=$((unknown + 1)) ;;
esac
done
# Calculate percentages for chart
total=$((passing + failing + skipped + unknown))
[ "$total" -eq 0 ] && total=1 # Avoid division by zero
pass_pct=$((passing * 100 / total))
fail_pct=$((failing * 100 / total))
skip_pct=$((skipped * 100 / total))
unkn_pct=$((unknown * 100 / total))
# Create QuickChart URL (simple URL encoding)
chart_config="{\"type\":\"pie\",\"data\":{\"labels\":[\"Passing\",\"Failing\",\"Skipped\",\"Unknown\"],\"datasets\":[{\"data\":[$pass_pct,$fail_pct,$skip_pct,$unkn_pct],\"backgroundColor\":[\"#50fa7b\",\"#ff5555\",\"#8be9fd\",\"#808080\"]}]},\"options\":{\"plugins\":{\"legend\":{\"position\":\"bottom\"}}}}"
# Simple URL encoding for the chart config
encoded_config=$(echo "$chart_config" | sed 's/ /%20/g; s/{/%7B/g; s/}/%7D/g; s/\[/%5B/g; s/\]/%5D/g; s/"/%22/g; s/:/%3A/g; s/,/%2C/g; s/#/%23/g')
chart_url="https://quickchart.io/chart?v=2.9.4&w=300&h=200&c=$encoded_config"
{
echo "## Test Summary"
echo "- $(em "$TESTS") Tests - $(verb "$TESTS")"
echo "## 🧪 Test Results"
echo ""
echo "_See job logs and artifacts for details (coverage & Playwright reports)._"
echo "![Test Results Chart]($chart_url)"
echo ""
line "$UNIT" "Unit Tests" "npm run test:coverage"
line "$E2E" "E2E Tests" "npm run test:e2e"
if [ "$failing" -eq 0 ]; then
echo -e "\n🎉 **All test suites passed!**"
[ "$passing" -gt 0 ] && echo "📈 Coverage report may be available in [Codecov](https://codecov.io)"
else
echo -e "\n⚠️ **$failing of $total test suite(s) failed**"
echo "📊 Check artifacts for detailed test reports"
fi
} >> "$GITHUB_STEP_SUMMARY"
+6 -2
View File
@@ -6,7 +6,11 @@ export default defineConfig({
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
reporter: [
['github'],
['html', { open: 'never', outputFolder: 'playwright-report' }],
['junit', { outputFile: 'e2e-results.xml' }],
],
use: {
baseURL: 'http://localhost:4173',
trace: 'on-first-retry',
@@ -30,4 +34,4 @@ export default defineConfig({
command: 'npm run build && npm run preview',
port: 4173,
},
});
});
+2 -2
View File
@@ -90,11 +90,11 @@
break;
case 'frequent':
items = $frequentlyUsedTools.slice(0, 8).map(tool => ({
items = $frequentlyUsedTools.slice(0, 8).map((tool) => ({
href: tool.href,
label: tool.label || 'Untitled Tool',
icon: tool.icon,
description: tool.description
description: tool.description,
}));
break;
-2
View File
@@ -34,7 +34,6 @@ function getAdapter() {
case 'auto':
return adapterAuto();
default:
console.warn(`Unknown DEPLOY_ENV: '${deployEnv}', falling back to auto adapter`);
return adapterAuto();
}
}
@@ -60,7 +59,6 @@ function getAdapter() {
} else if (isStatic) {
return adapterStatic();
}
console.log('No specific deployment environment detected, using auto adapter');
return adapterAuto();
}
+5 -5
View File
@@ -16,12 +16,12 @@ test.describe('Core calculation accuracy', () => {
// Verify input fields are present
await expect(page.locator('input').first()).toBeVisible();
// Input a test value
// Input a test value (CIDR notation required)
const firstInput = page.locator('input').first();
await firstInput.fill('192.168.1.100');
await firstInput.fill('192.168.1.0/24');
// Verify input was accepted
await expect(firstInput).toHaveValue('192.168.1.100');
await expect(firstInput).toHaveValue('192.168.1.0/24');
});
test('CIDR to subnet mask converter works', async ({ page }) => {
@@ -97,7 +97,7 @@ test.describe('Core calculation accuracy', () => {
// Wait for page to load
await expect(page.locator('body')).toBeVisible();
// Check for content
await expect(page.locator('p, ul, ol, table').first()).toBeVisible();
// Check for content in the main area (not header)
await expect(page.locator('main p, main ul, main ol, main table, .content p, .content ul, .content ol, .content table').first()).toBeVisible();
});
});
Whitespace-only changes.