chore(packages): add test coverage support to plugin sdk and shared package

This commit is contained in:
jubnl
2026-08-25 01:22:20 +02:00
parent 190dc482e4
commit 4548743874
10 changed files with 545 additions and 265 deletions
+44 -1
View File
@@ -78,7 +78,50 @@ jobs:
run: cd shared && npm run typecheck run: cd shared && npm run typecheck
- name: Run tests - name: Run tests
run: cd shared && npm test run: cd shared && npm run test:coverage
- name: Upload coverage
if: success()
uses: actions/upload-artifact@v6
with:
name: shared-coverage
path: shared/coverage/
retention-days: 7
plugin-sdk-tests:
name: Plugin SDK Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: plugin-sdk
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
# 22 matches the TREK server runtime and has node:sqlite, which the
# dev-server tests exercise (same choice as publish-plugin-sdk.yml).
node-version: 22
# plugin-sdk is standalone (own lockfile, not a root workspace), so it
# installs from its own directory.
- name: Install dependencies
run: npm ci
- name: Typecheck
run: npm run typecheck
- name: Run tests
run: npm run test:coverage
- name: Upload coverage
if: success()
uses: actions/upload-artifact@v6
with:
name: plugin-sdk-coverage
path: plugin-sdk/coverage/
retention-days: 7
server-tests: server-tests:
name: Server Tests name: Server Tests
+1 -1
View File
@@ -34,7 +34,7 @@ npm run test:unit --workspace=server # tests/unit only
npm run test:integration --workspace=server npm run test:integration --workspace=server
npm run test:ws --workspace=server # websocket tests npm run test:ws --workspace=server # websocket tests
npm run test:e2e # server e2e (boots Nest against temp SQLite) npm run test:e2e # server e2e (boots Nest against temp SQLite)
npm run test:cov # coverage, server + client npm run test:cov # coverage (lcov), all four packages incl. shared + plugin-sdk
cd client && npm run test # client vitest run cd client && npm run test # client vitest run
cd client && npm run e2e # Playwright cd client && npm run e2e # Playwright
cd client && npm run lint:pages # enforce the Page pattern (see below) cd client && npm run lint:pages # enforce the Page pattern (see below)
+1
View File
@@ -22084,6 +22084,7 @@
"devDependencies": { "devDependencies": {
"@eslint/js": "^10.0.1", "@eslint/js": "^10.0.1",
"@trivago/prettier-plugin-sort-imports": "^6.0.2", "@trivago/prettier-plugin-sort-imports": "^6.0.2",
"@vitest/coverage-v8": "^4.1.9",
"eslint": "^10.3.0", "eslint": "^10.3.0",
"eslint-config-flat-gitignore": "^2.3.0", "eslint-config-flat-gitignore": "^2.3.0",
"eslint-config-prettier": "^10.1.8", "eslint-config-prettier": "^10.1.8",
+1 -1
View File
@@ -18,7 +18,7 @@
"dev": "npm run build --workspace=shared && concurrently --names shared,server,client \"npm run build:watch --workspace=shared\" \"npm run dev --workspace=server\" \"npm run dev --workspace=client\"", "dev": "npm run build --workspace=shared && concurrently --names shared,server,client \"npm run build:watch --workspace=shared\" \"npm run dev --workspace=server\" \"npm run dev --workspace=client\"",
"build": "npm run build --workspace=shared && npm run build --workspace=server && npm run build --workspace=client", "build": "npm run build --workspace=shared && npm run build --workspace=server && npm run build --workspace=client",
"test": "npm run test --workspace=shared && npm run test --workspace=server && npm run test --workspace=client", "test": "npm run test --workspace=shared && npm run test --workspace=server && npm run test --workspace=client",
"test:cov": "npm run test:coverage --workspace=server && npm run test:coverage --workspace=client", "test:cov": "npm run test:coverage --workspace=shared && npm run test:coverage --workspace=server && npm run test:coverage --workspace=client && npm run test:coverage --prefix plugin-sdk",
"test:e2e": "npm run test:e2e --workspace=server", "test:e2e": "npm run test:e2e --workspace=server",
"lint": "npm run lint --workspace=shared && npm run lint --workspace=server && npm run lint --workspace=client", "lint": "npm run lint --workspace=shared && npm run lint --workspace=server && npm run lint --workspace=client",
"format": "npm run format --workspace=shared && npm run format --workspace=server && npm run format --workspace=client", "format": "npm run format --workspace=shared && npm run format --workspace=server && npm run format --workspace=client",
+440 -255
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -71,12 +71,14 @@
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/finish-cjs.mjs", "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/finish-cjs.mjs",
"typecheck": "tsc -p tsconfig.json --noEmit", "typecheck": "tsc -p tsconfig.json --noEmit",
"test": "vitest run", "test": "vitest run",
"test:coverage": "vitest run --coverage",
"prepublishOnly": "npm run build && npm test" "prepublishOnly": "npm run build && npm test"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.20.0", "@types/node": "^22.20.0",
"@types/semver": "^7.7.1", "@types/semver": "^7.7.1",
"@types/update-notifier": "^6.0.8", "@types/update-notifier": "^6.0.8",
"@vitest/coverage-v8": "^4.1.9",
"typescript": "^5.9.3", "typescript": "^5.9.3",
"vitest": "^4.1.9" "vitest": "^4.1.9"
}, },
+20
View File
@@ -0,0 +1,20 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['lcov', 'text'],
reportsDirectory: './coverage',
include: ['src/**/*.ts'],
// Mirrored in the repo root's sonar.coverage.exclusions — a file skipped
// here emits no lcov entry, so Sonar must not count it as uncovered either.
exclude: [
// Machine-written by server/scripts/gen-plugin-facts.ts.
'src/generated/**',
// Generated snapshot (scripts/gen-lucide-icon-names.mjs) — pure data.
'src/lucide-icon-names.ts',
],
},
},
});
+2
View File
@@ -54,6 +54,7 @@
"build:watch": "tsdown --watch --no-clean", "build:watch": "tsdown --watch --no-clean",
"test": "vitest run", "test": "vitest run",
"test:watch": "vitest", "test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"typecheck": "tsc --noEmit", "typecheck": "tsc --noEmit",
"format": "prettier --write \"src/**/*.ts\"", "format": "prettier --write \"src/**/*.ts\"",
"format:check": "prettier --check \"src/**/*.ts\"", "format:check": "prettier --check \"src/**/*.ts\"",
@@ -68,6 +69,7 @@
"devDependencies": { "devDependencies": {
"@eslint/js": "^10.0.1", "@eslint/js": "^10.0.1",
"@trivago/prettier-plugin-sort-imports": "^6.0.2", "@trivago/prettier-plugin-sort-imports": "^6.0.2",
"@vitest/coverage-v8": "^4.1.9",
"eslint": "^10.3.0", "eslint": "^10.3.0",
"eslint-config-flat-gitignore": "^2.3.0", "eslint-config-flat-gitignore": "^2.3.0",
"eslint-config-prettier": "^10.1.8", "eslint-config-prettier": "^10.1.8",
+22
View File
@@ -0,0 +1,22 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['lcov', 'text'],
reportsDirectory: './coverage',
include: ['src/**/*.ts'],
// Mirrored in sonar.coverage.exclusions — a file skipped here emits no
// lcov entry, so Sonar must not count it as uncovered either.
exclude: [
// Machine-generated by server/scripts/gen-plugin-facts.ts.
'src/plugin-permissions.ts',
// Per-locale string tables are data, not executable code; the parity
// specs import every locale, which would report them as 100% covered
// and inflate the package number.
'src/i18n/*/**',
],
},
},
});
+12 -7
View File
@@ -30,14 +30,17 @@ sonar.exclusions=\
**/*.spec.ts,\ **/*.spec.ts,\
**/*.d.ts **/*.d.ts
# Coverage — lcov paths relative to repo root. # Coverage — lcov paths relative to repo root, one per package
# shared/ and plugin-sdk/ have test suites but don't emit lcov (no coverage # (each package's vitest config emits lcov to <pkg>/coverage/).
# reporter configured); their sources are coverage-excluded below until they do.
sonar.javascript.lcov.reportPaths=\ sonar.javascript.lcov.reportPaths=\
server/coverage/lcov.info,\ server/coverage/lcov.info,\
client/coverage/lcov.info client/coverage/lcov.info,\
shared/coverage/lcov.info,\
plugin-sdk/coverage/lcov.info
# Infrastructure/bootstrap files and packages without coverage instrumentation # Infrastructure/bootstrap files plus generated/data files the vitest configs
# exclude from instrumentation (a file absent from lcov would otherwise count
# as 0% covered here — keep these in sync with each package's vitest.config.ts)
sonar.coverage.exclusions=\ sonar.coverage.exclusions=\
server/src/index.ts,\ server/src/index.ts,\
server/src/config.ts,\ server/src/config.ts,\
@@ -48,8 +51,10 @@ sonar.coverage.exclusions=\
server/src/nest/plugins/runtime/plugin-host-entry.ts,\ server/src/nest/plugins/runtime/plugin-host-entry.ts,\
client/src/main.tsx,\ client/src/main.tsx,\
client/src/types.ts,\ client/src/types.ts,\
shared/src/**,\ shared/src/plugin-permissions.ts,\
plugin-sdk/src/** shared/src/i18n/*/**,\
plugin-sdk/src/generated/**,\
plugin-sdk/src/lucide-icon-names.ts
# Locale files are large near-identical literal objects — keep them out of duplication metrics # Locale files are large near-identical literal objects — keep them out of duplication metrics
sonar.cpd.exclusions=shared/src/i18n/** sonar.cpd.exclusions=shared/src/i18n/**