chore(test): bootstrap vitest + jsdom test infrastructure
Add vitest 4.1, jsdom 25, and @testing-library/preact as devDeps so the widget gets a real test surface for the upcoming Shadow DOM mount work. - vitest.config.ts mirrors the build aliases (preact/compat) and uses jsdom for DOM-touching tests. - tests/setup.ts is the place to add polyfills as the surface grows. - tests/unit/smoke.test.ts confirms vitest runs, jsdom is wired, and Shadow DOM API is available. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c5d1880589
commit
ca084735ac
2189
package-lock.json
generated
2189
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -7,14 +7,19 @@
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"preact": "^10.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^6.0.0",
|
||||
"@testing-library/preact": "^3.2.4",
|
||||
"@types/node": "^22.0.0",
|
||||
"jsdom": "^25.0.0",
|
||||
"typescript": "^5.6.0",
|
||||
"@types/node": "^22.0.0"
|
||||
"vite": "^6.0.0",
|
||||
"vitest": "^4.1.4"
|
||||
}
|
||||
}
|
||||
|
||||
2
tests/setup.ts
Normal file
2
tests/setup.ts
Normal file
@ -0,0 +1,2 @@
|
||||
// Global test setup for Vitest + jsdom.
|
||||
// Add polyfills/stubs here as the test surface grows.
|
||||
21
tests/unit/smoke.test.ts
Normal file
21
tests/unit/smoke.test.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
describe('Vitest infrastructure', () => {
|
||||
it('runs assertions', () => {
|
||||
expect(1 + 1).toBe(2);
|
||||
});
|
||||
|
||||
it('exposes the jsdom document', () => {
|
||||
const div = document.createElement('div');
|
||||
div.id = 'sanity';
|
||||
document.body.appendChild(div);
|
||||
expect(document.getElementById('sanity')).toBe(div);
|
||||
});
|
||||
|
||||
it('supports Shadow DOM API in jsdom', () => {
|
||||
const host = document.createElement('div');
|
||||
document.body.appendChild(host);
|
||||
const shadow = host.attachShadow({ mode: 'open' });
|
||||
expect(host.shadowRoot).toBe(shadow);
|
||||
});
|
||||
});
|
||||
20
vitest.config.ts
Normal file
20
vitest.config.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { defineConfig } from 'vitest/config';
|
||||
import { resolve } from 'path';
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
react: 'preact/compat',
|
||||
'react-dom': 'preact/compat',
|
||||
'react-dom/test-utils': 'preact/test-utils',
|
||||
'react/jsx-runtime': 'preact/jsx-runtime',
|
||||
'@': resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
test: {
|
||||
environment: 'jsdom',
|
||||
globals: true,
|
||||
setupFiles: ['./tests/setup.ts'],
|
||||
include: ['tests/unit/**/*.test.ts'],
|
||||
},
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user