Add test suite

This commit is contained in:
Alex Gleason 2025-05-27 23:10:17 +02:00
parent 4254b9eb0b
commit d14652559e
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
8 changed files with 1292 additions and 9 deletions

30
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: Test
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Clean install dependencies
run: |
rm -rf node_modules package-lock.json
npm install
- name: Run tests
run: npm run test

View File

@ -377,7 +377,7 @@ export function Post(/* ...props */) {
Whenever you modify code, you should test your changes after you're finished by running:
```bash
npm run ci
npm run test
```
This command will typecheck the code and attempt to build it.

1220
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,10 +6,7 @@
"scripts": {
"dev": "npm i && vite",
"build": "npm i && vite build && cp dist/index.html dist/404.html",
"build:dev": "npm i && vite build --mode development",
"ci": "npm i && tsc -p tsconfig.app.json --noEmit && eslint && vite build",
"lint": "npm i && eslint .",
"preview": "npm i && vite preview",
"test": "npm i && tsc -p tsconfig.app.json --noEmit && eslint && vitest run && vite build",
"deploy": "npm run build && npx -y surge@latest dist"
},
"dependencies": {
@ -69,6 +66,8 @@
"devDependencies": {
"@eslint/js": "^9.9.0",
"@tailwindcss/typography": "^0.5.15",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.3.0",
"@types/node": "^22.5.5",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.1",
@ -78,10 +77,12 @@
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"jsdom": "^26.1.0",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.11",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.1",
"vite": "^5.4.1"
"vite": "^5.4.1",
"vitest": "^3.1.4"
}
}

8
src/App.test.tsx Normal file
View File

@ -0,0 +1,8 @@
import { render } from '@testing-library/react';
import { test } from 'vitest';
import App from './App';
test('App', () => {
render(<App />);
})

View File

@ -8,6 +8,7 @@ import { TooltipProvider } from "@/components/ui/tooltip";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { NostrLoginProvider } from '@nostrify/react/login';
import AppRouter from './AppRouter';
import { useLocation } from 'react-router-dom';
// DO NOT MODIFY THIS RELAY LIST UNLESS EXPLICITLY REQUESTED
const defaultRelays = [
@ -27,6 +28,8 @@ const queryClient = new QueryClient({
});
export function App() {
const location = useLocation();
return (
<NostrLoginProvider storageKey='nostr:login'>
<NostrProvider relays={defaultRelays}>

17
src/test/setup.ts Normal file
View File

@ -0,0 +1,17 @@
import '@testing-library/jest-dom';
import { vi } from 'vitest';
// Mock window.matchMedia
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});

View File

@ -1,7 +1,8 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import path from "node:path";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vitest/config";
// https://vitejs.dev/config/
export default defineConfig(() => ({
server: {
@ -9,6 +10,11 @@ export default defineConfig(() => ({
port: 8080,
},
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/test/setup.ts',
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),