Skip to content

Commit 991fe2a

Browse files
authored
Add QR config validation and browser testing setup (#248)
This pull request adds comprehensive test coverage for utility functions and refactors QR code configuration management. **Testing Infrastructure:** - Configures Vitest with a workspace setup separating Node.js and browser test environments - Adds browser testing capabilities using Playwright for DOM-dependent functionality - Installs required testing dependencies including `@vitest/browser` and additional Playwright version **New Utility Functions:** - Adds CSS validation utilities (`isValidCSSColor`, `isValidCSSLength`) using the browser's CSS.supports API - Implements frame configuration validation functions (`isValidFrameStyle`, `isValidFrameConfig`) - Creates QR code configuration validation (`isValidQRCodeConfig`) **QR Code Storage Refactoring:** - Extracts storage logic into a dedicated `useQRCodeStorage` module with proper TypeScript interfaces - Centralizes localStorage operations with validation and error handling - Moves configuration constants and helper functions to the new storage module **Test Coverage:** - Adds comprehensive unit tests for CSS validation functions - Tests frame preset validation with various valid/invalid inputs - Covers QR code configuration serialization, storage, and retrieval - Validates error handling for malformed JSON and invalid configurations **ESLint Configuration:** - Excludes additional directories (`scripts/**`, `*.json`) from linting - Adds `CSS` global for browser CSS API usage
1 parent b3f2c22 commit 991fe2a

15 files changed

Lines changed: 831 additions & 135 deletions

.github/workflows/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
name: Unit & Browser Tests
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Setup pnpm
23+
uses: pnpm/action-setup@v4
24+
25+
- name: Setup Node
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 20
29+
cache: pnpm
30+
31+
- name: Install dependencies
32+
run: pnpm install
33+
34+
- name: Install Playwright Chromium
35+
run: pnpm exec playwright install chromium --with-deps
36+
37+
- name: Run tests
38+
run: pnpm vitest run

eslint.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export default [
1313
'node_modules/**',
1414
'*.config.js',
1515
'public/**',
16-
'pnpm-lock.yaml'
16+
'pnpm-lock.yaml',
17+
'scripts/**',
18+
'*.json'
1719
]
1820
},
1921
js.configs.recommended,
@@ -58,6 +60,7 @@ export default [
5860
Node: 'readonly',
5961
XMLSerializer: 'readonly',
6062
ClipboardItem: 'readonly',
63+
CSS: 'readonly',
6164
DataTransferItemList: 'readonly',
6265
RequestInit: 'readonly',
6366
Response: 'readonly',

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"version": "0.13.1",
55
"type": "module",
6+
"packageManager": "pnpm@8.14.0",
67
"scripts": {
78
"dev": "vite",
89
"build": "vite build",
@@ -51,17 +52,20 @@
5152
"vue-i18n": "^9.14.2"
5253
},
5354
"devDependencies": {
55+
"@eslint/js": "^9",
5456
"@playwright/test": "^1.51.1",
5557
"@tailwindcss/typography": "^0.5.16",
5658
"@types/dom-to-image": "^2.6.7",
5759
"@types/node": "^20.17.23",
5860
"@typescript-eslint/parser": "^8.46.2",
61+
"@vitest/browser": "^3.1.2",
5962
"@vue/eslint-config-typescript": "^14.6.0",
6063
"eslint": "^9",
6164
"eslint-plugin-tailwindcss": "^3.18.2",
6265
"eslint-plugin-vue": "^10.5.1",
6366
"husky": "^8.0.3",
6467
"lint-staged": "^15.4.3",
68+
"playwright": "^1.58.2",
6569
"postcss": "^8.5.3",
6670
"prettier": "^3.5.3",
6771
"prettier-plugin-tailwindcss": "^0.7.1",

0 commit comments

Comments
 (0)