Skip to content

Commit

Permalink
Merge pull request #53 from UoaWDCC/setup/test
Browse files Browse the repository at this point in the history
setup vitest, jest and react testing library for testing
  • Loading branch information
gmat224 authored Jun 6, 2024
2 parents 02817ed + 7ef9e43 commit cb1a42b
Show file tree
Hide file tree
Showing 8 changed files with 1,142 additions and 17 deletions.
15 changes: 15 additions & 0 deletions web/__test__/ExecScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, it } from "vitest";
import { render, screen } from "@testing-library/react";
import React from "react";
import ExecScreen from "../src/screens/ExecScreen";
import { describe } from "node:test";
import { execs } from "../src/data/data";

describe("ExecScreen component", () => {
it("should display President", () => {
render(<ExecScreen execs={execs} />);
const message = screen.getAllByText(/President/i);
const president = message[0];
expect(president).toBeInTheDocument();
});
});
13 changes: 13 additions & 0 deletions web/__test__/TestScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, it } from "vitest";
import { render, screen } from "@testing-library/react";
import React from "react";
import TestScreen from "../src/screens/Test";
import { describe } from "node:test";

describe("TestScreen component", () => {
it("should display the 'Test' message", () => {
render(<TestScreen />);
const message = screen.getByText(/Test/i);
expect(message).toBeInTheDocument();
});
});
10 changes: 8 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"test": "vitest"
},
"dependencies": {
"@tanstack/react-query": "^5.18.1",
Expand All @@ -24,6 +25,9 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@testing-library/dom": "^10.1.0",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^16.0.0",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
Expand All @@ -34,9 +38,11 @@
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"jsdom": "^24.1.0",
"postcss": "^8.4.34",
"tailwindcss": "^3.4.1",
"typescript": "^5.2.2",
"vite": "^5.0.8"
"vite": "^5.0.8",
"vitest": "^1.6.0"
}
}
1 change: 1 addition & 0 deletions web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"types": ["vitest/globals"],

"paths": {
"@utils/*": ["./src/utils/*"],
Expand Down
17 changes: 10 additions & 7 deletions web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
/// <reference types="vitest" />

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@utils': '/src/utils',
'@components': '/src/components',
'@pages': '/src/pages',
'@contexts': '/src/contexts',
'@layouts': '/src/layouts',
"@utils": "/src/utils",
"@components": "/src/components",
"@pages": "/src/pages",
"@contexts": "/src/contexts",
"@layouts": "/src/layouts",
"@screens": "/src/screens",
},
},
});
13 changes: 13 additions & 0 deletions web/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference types="vitest" />
/// <reference types = "vite/client" />

import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
environment: "jsdom",
setupFiles: ["./vitest.setup.ts"],
css: true,
},
});
1 change: 1 addition & 0 deletions web/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "@testing-library/jest-dom";
1,089 changes: 1,081 additions & 8 deletions web/yarn.lock

Large diffs are not rendered by default.

0 comments on commit cb1a42b

Please sign in to comment.