test: replace jest with vitest on frontend (fehmer) ()

* test: replace jest with vitest on frontend

* vscode config

* use prettier to format modfifications on save
This commit is contained in:
Christian Fehmer 2024-02-26 12:23:50 +01:00 committed by GitHub
parent 002770ee26
commit b20df42f2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 809 additions and 2702 deletions

5
.gitignore vendored
View file

@ -69,10 +69,13 @@ node_modules_bak/
.env
#vs code
.vscode
.vscode/*
.vscode/.*
!.vscode/extensions.json
*.code-workspace
!monkeytype.code-workspace
.idea
#firebase

8
.vscode/extensions.json vendored Normal file
View file

@ -0,0 +1,8 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"Orta.vscode-jest",
"vitest.explorer",
"ryanluker.vscode-coverage-gutters"
]
}

View file

@ -1,19 +1,17 @@
import { jest } from "@jest/globals";
import $ from "jquery";
// @ts-ignore
global["$"] = $;
// @ts-ignore
global["jQuery"] = $;
jest.mock("../src/ts/constants/env-config", () => ({
vi.mock("../src/ts/constants/env-config", () => ({
envConfig: {
backendUrl: "invalid",
isDevelopment: true,
},
}));
jest.mock("../src/ts/firebase", () => ({
vi.mock("../src/ts/firebase", () => ({
app: undefined,
Auth: undefined,
}));

View file

@ -13,7 +13,8 @@
"esModuleInterop": true,
"strictNullChecks": true,
"skipLibCheck": true,
"noEmit": true
"noEmit": true,
"types": ["vitest/globals"]
},
"ts-node": {
"files": true

View file

@ -1,11 +1,7 @@
import { Formatting } from "../../src/ts/utils/format";
import * as MockConfig from "../../src/ts/config";
import DefaultConfig from "../../src/ts/constants/default-config";
describe("format.ts", () => {
afterEach(() => {
jest.resetAllMocks();
});
describe("typingsSpeed", () => {
it("should format with typing speed and decimalPlaces from configuration", () => {
//wpm, no decimals

View file

@ -1,10 +0,0 @@
import { defaults as tsjPreset } from "ts-jest/presets";
export default {
preset: "ts-jest",
transform: tsjPreset.transform,
testEnvironment: "jsdom",
setupFilesAfterEnv: ["<rootDir>/__tests__/setup-tests.ts"],
modulePathIgnorePatterns: ["<rootDir>/__tests__/setup-tests.ts"],
testRegex: "(/__tests__/.*|(\\.|/)(spec))\\.[jt]sx?$", //prevent files like test.ts outside the __tests__ folder to be detected as test
};

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,9 @@
"dev": "vite dev",
"deploy-live": "npm run validate-json && npm run build && firebase deploy -P live --only hosting",
"deploy-preview": "npm run validate-json && npm run build && firebase hosting:channel:deploy preview -P live --expires 2h",
"test": "jest --verbose --collect-coverage --runInBand",
"test": "vitest run",
"test-coverage": "vitest run --coverage",
"dev-test": "concurrently --kill-others \"vite dev\" \"vitest\"",
"tsc": "tsc",
"knip": "knip"
},
@ -30,25 +32,22 @@
"@types/chartjs-plugin-trendline": "1.0.1",
"@types/damerau-levenshtein": "1.0.0",
"@types/howler": "2.2.7",
"@types/jest": "27.5.0",
"@types/jquery": "3.5.14",
"@types/node": "18.19.1",
"@types/object-hash": "2.2.1",
"@types/throttle-debounce": "2.1.0",
"@vitest/coverage-istanbul": "1.3.1",
"autoprefixer": "10.4.14",
"dotenv": "16.4.5",
"eslint": "8.43.0",
"gulp": "4.0.2",
"gulp-eslint-new": "1.9.1",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"jest-environment-node": "29.7.0",
"happy-dom": "13.4.1",
"jsonschema": "1.4.0",
"madge": "5.0.1",
"normalize.css": "8.0.1",
"postcss": "8.4.27",
"sass": "1.70.0",
"ts-jest": "29.1.2",
"typescript": "5.3.3",
"vite": "5.1.2",
"vite-bundle-visualizer": "1.0.1",
@ -56,7 +55,8 @@
"vite-plugin-filter-replace": "0.1.13",
"vite-plugin-html-inject": "1.1.2",
"vite-plugin-inspect": "0.8.3",
"vite-plugin-pwa": "0.19.0"
"vite-plugin-pwa": "0.19.0",
"vitest": "1.3.1"
},
"dependencies": {
"axios": "1.6.4",

View file

@ -4,7 +4,7 @@
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "node",
"types": ["vite/client", "node", "jest", "jquery"],
"types": ["vite/client", "node", "jquery"],
"allowUmdGlobalAccess": true,
"resolveJsonModule": true,
"outDir": "./build",
@ -31,10 +31,7 @@
"noPropertyAccessFromIndexSignature": true,
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"skipLibCheck": false,
"paths": {
"@backend/*": ["../backend/src/*"]
}
"skipLibCheck": false
},
"include": ["./src/**/*.ts", "../shared-types/**/*.d.ts"],
"exclude": ["node_modules", "build", "setup-tests.ts", "**/*.spec.ts"]

18
frontend/vitest.config.js Normal file
View file

@ -0,0 +1,18 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
globals: true,
environment: "happy-dom",
setupFiles: ["__tests__/setup-tests.ts"],
coverage: {
include: ["**/*.ts"],
provider: "istanbul",
reporter: [
"text", // For the terminal
"lcov", // For the VSCode extension and browser
],
},
},
});

View file

@ -23,6 +23,23 @@
"backend": true,
"shared-types": true
},
"jest.disabledWorkspaceFolders": ["root", "shared-types"]
"search.exclude": {
//defaults
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true,
//exclude generated directories
"**/build/**": true,
"**/dist/**": true,
"**/public/**": true,
"**/coverage/**": true
},
"jest.disabledWorkspaceFolders": ["root", "shared-types", "frontend"],
"vitest.enable": true,
"vitest.watchOnStartup": true,
"coverage-gutters.coverageBaseDir": "**/coverage",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSaveMode": "modifications",
"editor.formatOnSave": true
}
}