diff --git a/webapp/package.json b/webapp/package.json index 5adf9c97..7b70c00e 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -15,7 +15,8 @@ "lint": "eslint . --ignore-pattern .gitignore --max-warnings=0", "lint:fix": "eslint . --fix --ignore-pattern .gitignore", "lint:style": "stylelint \"src/**/*.{vue,less,css}\" --max-warnings=0", - "lint:style:fix": "stylelint \"src/**/*.{vue,less,css}\" --fix" + "lint:style:fix": "stylelint \"src/**/*.{vue,less,css}\" --fix", + "unitest": "vitest src/tests/unit/LoggingContent.spec.js --no-cache --mode test --detectAsyncLeaks --coverage --isolate --silent --changed --logHeapUsage" }, "dependencies": { "@vueuse/core": "^14.1.0", diff --git a/webapp/src/tests/unit/LoggingContent.spec.js b/webapp/src/tests/unit/LoggingContent.spec.js index 93a7aedc..7f4e0a66 100644 --- a/webapp/src/tests/unit/LoggingContent.spec.js +++ b/webapp/src/tests/unit/LoggingContent.spec.js @@ -1,6 +1,7 @@ import { shallowMount, flushPromises } from "@vue/test-utils"; import { describe, it, expect, vi, beforeEach } from "vitest"; import { createTestingPinia } from "@pinia/testing"; +import { setActivePinia } from 'pinia'; import axios from "axios"; import fs from "fs"; import path from "path"; @@ -37,8 +38,9 @@ describe("Test LoggingContent.vue", () => { // Things to do before each test beforeEach(async () => { + vi.useFakeTimers() // Reset mocks before each test - vi.clearAllMocks(); + vi.resetAllMocks(); // Set axios to return our fake logs axios.get.mockResolvedValue({ data: mockLogData }); @@ -67,11 +69,23 @@ describe("Test LoggingContent.vue", () => { }); // flush so we avoid leaving uncompleted processes running on background await flushPromises(); + vi.advanceTimersByTime(1000) + vi.useRealTimers() }); // Tear down wrapper, unmount testing component afterEach(() => { - wrapper.unmount(); + if (wrapper) { + wrapper.unmount() // Clean up virtual DOM and memory bindings + } + setActivePinia(undefined) + document.body.innerHTML = '' + + if (global.gc) { + global.gc() // Forces V8 engine to immediately run Garbage Collection + } + vi.clearAllTimers() + vi.useRealTimers() }); // Test 1: Render check, if things do exist in the page as intended diff --git a/webapp/vitest.config.js b/webapp/vitest.config.js index 372ea36b..2c243456 100644 --- a/webapp/vitest.config.js +++ b/webapp/vitest.config.js @@ -19,7 +19,30 @@ export default defineConfig({ ], test: { - environment: "jsdom", + css: false, + pool: 'forks', + singleThread: true, + + define: { + __VUE_PROD_DEVTOOLS__: false, + }, + + coverage: { + provider: 'v8', + clean: true, + cleanOnStart: true, + }, + + deps: { + optimizer: { + web: { + enabled: true, + include: ['@mui/material', 'lucide-react'], // Add your largest component dependencies here + }, + }, + }, + + environment: "happy-dom", globals: true,