Skip to content

Commit 90f6c4b

Browse files
authored
Merge pull request #4 from chialab/vitest
Vitest
2 parents be84470 + 5deebc5 commit 90f6c4b

34 files changed

+2207
-449
lines changed

.changeset/fifty-drinks-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chialab/sveltekit-utils': patch
3+
---
4+
5+
Fix headers not being written to logs on fetch failures.

.github/workflows/lint.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ jobs:
1616
with:
1717
cache: yarn
1818

19+
- name: Get Yarn cache directory path
20+
id: yarn-cache-dir-path
21+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
22+
23+
- name: Setup Yarn cache
24+
uses: actions/cache@v4
25+
with:
26+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
27+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
28+
restore-keys: |
29+
${{ runner.os }}-yarn-
30+
1931
- name: Install project dependencies
2032
run: yarn install
2133

.github/workflows/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ jobs:
1212
uses: ./.github/workflows/lint.yml
1313
secrets: inherit
1414

15+
test:
16+
uses: ./.github/workflows/test.yml
17+
secrets: inherit
18+
1519
release:
16-
needs: lint
20+
needs: [lint, test]
1721
uses: ./.github/workflows/release.yml
1822
secrets: inherit

.github/workflows/pr.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ jobs:
1010
lint:
1111
uses: ./.github/workflows/lint.yml
1212
secrets: inherit
13+
14+
test:
15+
uses: ./.github/workflows/test.yml
16+
secrets: inherit

.github/workflows/test.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Test
2+
on:
3+
workflow_call:
4+
5+
jobs:
6+
unit:
7+
name: Run unit tests
8+
runs-on: ubuntu-latest
9+
timeout-minutes: 5
10+
steps:
11+
- name: Checkout the repository
12+
uses: actions/checkout@v4
13+
14+
- name: Setup Node
15+
uses: actions/setup-node@v4
16+
with:
17+
cache: yarn
18+
19+
- name: Get Yarn cache directory path
20+
id: yarn-cache-dir-path
21+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
22+
23+
- name: Setup Yarn cache
24+
uses: actions/cache@v4
25+
with:
26+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
27+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
28+
restore-keys: |
29+
${{ runner.os }}-yarn-
30+
31+
- name: Install project dependencies
32+
run: yarn install
33+
34+
- name: Setup Playwright cache
35+
uses: actions/cache@v4
36+
with:
37+
path: ~/.cache/ms-playwright
38+
key: ${{ runner.os }}-playwright
39+
40+
- name: Install Playwright browsers
41+
run: yarn run playwright install --with-deps
42+
43+
- name: Check
44+
run: yarn run test:unit:coverage
45+
46+
- name: Upload coverage reports to Codecov
47+
uses: codecov/codecov-action@v5
48+
with:
49+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ node_modules
77
/.env.production
88
/.env.*.local
99
/*.log
10+
/tests/coverage/
1011
vite.config.js.timestamp-*
1112
vite.config.ts.timestamp-*
1213
*.tsbuildinfo

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dbaeumer.vscode-eslint", // ESLint official extension
66
"esbenp.prettier-vscode", // Prettier official extension
77
"stylelint.vscode-stylelint", // Stylelint official extension
8-
"svelte.svelte-vscode" // Svelte official extension
8+
"svelte.svelte-vscode", // Svelte official extension
9+
"vitest.explorer" // Vitest official extension
910
]
1011
}

package.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
"exports": {
1111
".": {
1212
"types": "./dist/index.d.ts",
13-
"default": "./dist/index.js",
14-
"svelte": "./dist/index.js"
13+
"svelte": "./dist/index.js",
14+
"default": "./dist/index.js"
1515
},
1616
"./server": {
1717
"types": "./dist/server/index.d.ts",
1818
"node": "./dist/server/index.js",
19-
"default": null,
20-
"svelte": null
19+
"svelte": null,
20+
"default": null
2121
},
2222
"./logger": {
2323
"types": "./dist/logger.d.ts",
2424
"default": "./dist/logger.js"
2525
},
2626
"./utils": {
27-
"types": "./dist/utils.d.ts",
28-
"default": "./dist/utils.js"
27+
"types": "./dist/utils/index.d.ts",
28+
"default": "./dist/utils/index.js"
2929
}
3030
},
3131
"scripts": {
@@ -34,13 +34,17 @@
3434
"build": "svelte-kit sync && svelte-package",
3535
"app:build": "vite build",
3636
"app:preview-build": "vite preview | pino-pretty",
37+
"test:unit": "vitest run",
38+
"test:unit:coverage": "vitest run --coverage",
39+
"test:unit:watch": "vitest watch",
3740
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
3841
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
3942
"eslint-check": "eslint --ignore-path .gitignore . --ext .js,.cjs,.ts,.svelte",
4043
"eslint-fix": "eslint --fix --ignore-path .gitignore . --ext .js,.cjs,.ts,.svelte",
4144
"prettier-check": "prettier --check \"./**/*.{json,css,js,cjs,ts,svelte}\"",
4245
"prettier-fix": "prettier --write \"./**/*.{json,css,js,cjs,ts,svelte}\"",
43-
"lint-fix-all": "yarn eslint-fix && yarn prettier-fix"
46+
"lint": "yarn run check && yarn run eslint-check && yarn run prettier-fix",
47+
"lint-fix-all": "yarn run eslint-fix && yarn run prettier-fix"
4448
},
4549
"dependencies": {
4650
"cookie": "^1.0.2",
@@ -57,17 +61,21 @@
5761
"@types/node": "^22.9.1",
5862
"@typescript-eslint/eslint-plugin": "^8.15.0",
5963
"@typescript-eslint/parser": "^8.15.0",
64+
"@vitest/browser": "^3.0.5",
65+
"@vitest/coverage-v8": "^3.0.5",
6066
"eslint": "^8.57.1",
6167
"eslint-config-prettier": "^9.1.0",
6268
"eslint-plugin-svelte": "^2.46.0",
6369
"pino-pretty": "^13.0.0",
70+
"playwright": "^1.50.1",
6471
"prettier": "^3.3.3",
6572
"prettier-plugin-svelte": "^3.3.1",
6673
"svelte": "^5.0.0",
6774
"svelte-check": "^4.1.4",
6875
"tslib": "^2.8.1",
6976
"typescript": "^5.6.3",
70-
"vite": "^6.0.0"
77+
"vite": "^6.0.0",
78+
"vitest": "^3.0.5"
7179
},
7280
"peerDependencies": {
7381
"@sveltejs/kit": "^2.0.0",

src/lib/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './logger.js';
2-
export * from './url.js';
3-
export * from './utils.js';
2+
export * from './utils/index.js';

src/lib/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Pino from 'pino';
22
import { dev } from '$app/environment';
33

4-
const pino: typeof Pino.pino = typeof Pino === 'function' ? (Pino as any) : Pino.default;
4+
const pino: typeof Pino.pino = typeof Pino === 'function' ? Pino : Pino.default;
55
export const logger: Pino.Logger = pino({
66
transport: dev ? { target: 'pino-pretty' } : undefined,
77
level: dev ? 'debug' : 'info',

0 commit comments

Comments
 (0)