Skip to content

Commit

Permalink
chore: Add necessary files and configurations for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrr committed Jul 20, 2024
1 parent 36eecca commit 10f9530
Show file tree
Hide file tree
Showing 9 changed files with 3,700 additions and 506 deletions.
2,424 changes: 2,278 additions & 146 deletions client/package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"test": "jest"
"test": "vitest run --coverage"
},
"dependencies": {
"@headlessui/react": "^1.7.18",
Expand Down Expand Up @@ -41,14 +41,17 @@
"@types/react-redux": "^7.1.33",
"@types/react-router-hash-link": "^2.4.9",
"@vitejs/plugin-react": "^3.1.0",
"@vitest/coverage-v8": "^2.0.1",
"autoprefixer": "^10.4.19",
"cypress": "^13.7.3",
"daisyui": "^4.10.1",
"jest": "^29.7.0",
"jsdom": "^24.1.0",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
"vite": "^4.5.3",
"vite-tsconfig-paths": "^4.3.2"
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^2.0.1"
}
}
8 changes: 8 additions & 0 deletions client/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { afterEach } from "vitest";
import { cleanup } from "@testing-library/react";
import "@testing-library/jest-dom/vitest";

// runs a clean after each test case (e.g. clearing jsdom)
afterEach(() => {
cleanup();
});
47 changes: 37 additions & 10 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import viteTsconfigPaths from 'vite-tsconfig-paths';
import react from "@vitejs/plugin-react";
import viteTsconfigPaths from "vite-tsconfig-paths";
import { defineConfig as defineViteConfig, mergeConfig } from "vite";
import {
defineConfig as defineVitestConfig,
configDefaults,
} from "vitest/config";

// https://vitejs.dev/config/
// export default defineConfig({
// plugins: [react()],
// })

export default defineConfig({
const viteConfig = defineViteConfig({
plugins: [react(), viteTsconfigPaths()],
server: {
watch: {
Expand All @@ -16,5 +16,32 @@ export default defineConfig({
host: true, // needed for the Docker Container port mapping to work
strictPort: true,
port: 5173, // you can replace this port with any port
}
})
},
});

const vitestConfig = defineVitestConfig({
test: {
coverage: {
provider: "v8",
thresholds: {
statements: 80,
branches: 80,
functions: 80,
lines: 80,
},
include: ["src/**"],
},
exclude: [
...configDefaults.exclude,
"**/node_modules/**",
"**/dist/**",
"**/cypress/**",
"**/.{idea,git,cache,output,temp}/**",
"./src/config/**",
],
environment: "jsdom",
setupFiles: "./tests/setup.ts",
},
});

export default mergeConfig(viteConfig, vitestConfig);
12 changes: 12 additions & 0 deletions server/controllers/users.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const server = require("../server.js");
const supertest = require("supertest");
const requestWithSupertest = supertest(server);

describe("User Endpoints", () => {
it("GET /user should show all users", async () => {
const res = await requestWithSupertest.get("/users");
expect(res.status).toEqual(200);
expect(res.type).toEqual(expect.stringContaining("json"));
expect(res.body).toHaveProperty("users");
});
});
10 changes: 10 additions & 0 deletions server/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import globals from "globals";
import pluginJs from "@eslint/js";


export default [
{files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
{languageOptions: { globals: globals.browser }},
pluginJs.configs.recommended,

];
1 change: 1 addition & 0 deletions server/models/users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const { ENUM } = require('sequelize');
const {
Model
} = require('sequelize');
Expand Down
Loading

0 comments on commit 10f9530

Please sign in to comment.