Skip to content

Commit 3abbe7d

Browse files
committed
Add code coverage report to unit test CI workflow, docs deletions, tweak vitest.config
1 parent 8f7afd1 commit 3abbe7d

12 files changed

Lines changed: 70 additions & 281 deletions

‎.eslintrc.js‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎.github/workflows/build-and-test.yml‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ jobs:
1111
name: Build and Test
1212
runs-on: ubuntu-latest
1313

14+
permissions:
15+
# Required to checkout the code
16+
contents: read
17+
# Required to put a comment into the pull-request
18+
pull-requests: write
19+
1420
# Define environment variables once at the job level
1521
# These will be available to ALL steps in this job
1622
env:
@@ -40,8 +46,19 @@ jobs:
4046
- name: Run lint
4147
run: npm run lint
4248

43-
- name: Run unit tests
44-
run: npm test -- --run
49+
- name: Run unit tests (Vitest — coverage with GitHub Actions reporter)
50+
run: |
51+
# Run vitest with coverage. The built-in 'github-actions' reporter
52+
# (configured in vitest.config.ts) will create annotations.
53+
# Coverage reporters (json-summary, json) are configured in vitest.config.ts.
54+
npx vitest run --coverage
55+
56+
- name: Report Coverage
57+
uses: davelosert/vitest-coverage-report-action@v2
58+
if: always()
59+
with:
60+
json-summary-path: './coverage/coverage-summary.json'
61+
json-final-path: './coverage/coverage-final.json'
4562

4663
- name: Build project
4764
run: npm run build

‎.gitignore‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ npm-debug.log*
2323

2424
# dotenv environment variable files
2525
.env*
26-
# Commit default dotenv environment variable file
27-
!.env.local
2826

2927
# Optional npm cache directory
3028
.npm

‎FRAMEWORK_CHOICE.md‎

Lines changed: 0 additions & 97 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

‎debug-ast.mjs‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎docs/GITHUB_SECRETS_SETUP.md‎

Lines changed: 0 additions & 109 deletions
This file was deleted.

‎eslint.config.ts‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,21 @@ export default [
157157
'jsdoc/valid-types': 'off',
158158
'new-cap': [level, { newIsCap: true, capIsNew: false }],
159159
'no-new': level,
160-
'no-process-env': level,
160+
'no-process-env': [level, , {
161+
"message": "Do not use process.env directly. See docs/ENVIRONMENT_VARIABLES."
162+
}]
161163
'no-restricted-globals': ['error'].concat(restrictedGlobals),
162164
'no-restricted-imports': [
163165
'error', {
164166
patterns: [
165167
{
166168
group: ['../*'],
167-
message: 'Usage of relative imports is not allowed. Please use path aliases.',
169+
message: 'Usage of relative imports is not allowed. Use path aliases.',
168170
},
169171
{
170172
group: ['*'],
171173
importNames: ['*'],
172-
message: 'Wildcard imports are not allowed. Please use named imports instead.',
174+
message: 'Wildcard imports are not allowed. Use named imports instead.',
173175
},
174176
],
175177
},
@@ -231,6 +233,34 @@ export default [
231233
},
232234
},
233235
{
236+
// Test files can import from server code in src/lib
237+
files: ['src/**/__tests__/**/*'],
238+
rules: {
239+
'import/no-restricted-paths': 'off',
240+
},
241+
},
242+
{
243+
// Test files can import from server code in src/lib
244+
'import/no-restricted-paths': [
245+
level,
246+
{
247+
zones: [
248+
{
249+
target: 'src/**/__tests__/**/*',
250+
from: 'src/components/scripts/utils/environmentClient.ts',
251+
message: 'use src/lib/config/environmentServer.ts in test files, not environmentClient.',
252+
},
253+
{
254+
target: 'src/**/__tests__/**/*',
255+
from: 'src/components/scripts/utils/siteUrlClient.ts',
256+
message: 'use src/lib/config/siteUrlServer.ts in test files, not siteUrlClient.',
257+
},
258+
],
259+
},
260+
],
261+
},
262+
{
263+
// Files that need access to process.env()
234264
files: [
235265
'.eslintrc.js',
236266
'astro.config.ts',
@@ -239,7 +269,6 @@ export default [
239269
'scripts/build/**/*'
240270
],
241271
rules: {
242-
// All files except Astro config should use import.meta.env.ENV_VAR
243272
'no-process-env': 'off',
244273
},
245274
},
@@ -254,7 +283,7 @@ export default [
254283
level,
255284
{
256285
'selector': 'MetaProperty[meta.name="import"][property.name="meta"]',
257-
'message': 'Do not use import.meta.env directly. Use methods in src/components/scripts/utils like isCI(), isDev(), etc.'
286+
'message': 'Do not use import.meta.env directly. See docs/ENVIRONMENT_VARIABLES.'
258287
}
259288
],
260289
},

‎package.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
"lint:style": "npx stylelint \"src/**/*.{css,astro}\"",
4343
"preview": "npm run build:favicons && npx astro build && astro preview",
4444
"sync": "npx astro sync",
45-
"test": "cross-env NODE_ENV=test npm run test:unit && npm run test:e2e",
46-
"test:coverage": "cross-env NODE_ENV=test npx vitest run --coverage",
47-
"test:e2e": "cross-env NODE_ENV=test npx playwright test",
48-
"test:unit": "cross-env NODE_ENV=test npx vitest run",
45+
"test": "npm run test:unit && npm run test:e2e",
46+
"test:coverage": "npx vitest run --coverage",
47+
"test:e2e": "npx playwright test",
48+
"test:unit": "npx vitest run",
4949
"upgrade": "npx @astrojs/upgrade",
5050
"prepare": "husky"
5151
},

0 commit comments

Comments
 (0)