🛠️ Configure testing setup and update Vitest configuration
This commit is contained in:
49
code/websites/pokedex.online/tests/setup.js
Normal file
49
code/websites/pokedex.online/tests/setup.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* Test Setup File
|
||||||
|
* Runs before all tests to configure global test environment
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { vi } from 'vitest';
|
||||||
|
|
||||||
|
// Mock localStorage
|
||||||
|
const localStorageMock = {
|
||||||
|
getItem: vi.fn(),
|
||||||
|
setItem: vi.fn(),
|
||||||
|
removeItem: vi.fn(),
|
||||||
|
clear: vi.fn()
|
||||||
|
};
|
||||||
|
global.localStorage = localStorageMock;
|
||||||
|
|
||||||
|
// Mock sessionStorage
|
||||||
|
const sessionStorageMock = {
|
||||||
|
getItem: vi.fn(),
|
||||||
|
setItem: vi.fn(),
|
||||||
|
removeItem: vi.fn(),
|
||||||
|
clear: vi.fn()
|
||||||
|
};
|
||||||
|
global.sessionStorage = sessionStorageMock;
|
||||||
|
|
||||||
|
// Mock fetch
|
||||||
|
global.fetch = vi.fn();
|
||||||
|
|
||||||
|
// Mock console methods to reduce noise in tests
|
||||||
|
global.console = {
|
||||||
|
...console,
|
||||||
|
error: vi.fn(),
|
||||||
|
warn: vi.fn(),
|
||||||
|
log: vi.fn(),
|
||||||
|
debug: vi.fn()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Reset all mocks before each test
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
localStorageMock.getItem.mockReset();
|
||||||
|
localStorageMock.setItem.mockReset();
|
||||||
|
localStorageMock.removeItem.mockReset();
|
||||||
|
localStorageMock.clear.mockReset();
|
||||||
|
sessionStorageMock.getItem.mockReset();
|
||||||
|
sessionStorageMock.setItem.mockReset();
|
||||||
|
sessionStorageMock.removeItem.mockReset();
|
||||||
|
sessionStorageMock.clear.mockReset();
|
||||||
|
});
|
||||||
36
code/websites/pokedex.online/vitest.config.js
Normal file
36
code/websites/pokedex.online/vitest.config.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { defineConfig } from 'vitest/config';
|
||||||
|
import vue from '@vitejs/plugin-vue';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [vue()],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
test: {
|
||||||
|
globals: true,
|
||||||
|
environment: 'happy-dom',
|
||||||
|
setupFiles: ['./tests/setup.js'],
|
||||||
|
coverage: {
|
||||||
|
provider: 'v8',
|
||||||
|
reporter: ['text', 'json', 'html', 'lcov'],
|
||||||
|
exclude: [
|
||||||
|
'node_modules/',
|
||||||
|
'tests/',
|
||||||
|
'dist/',
|
||||||
|
'server/',
|
||||||
|
'*.config.js',
|
||||||
|
'.eslintrc.cjs'
|
||||||
|
],
|
||||||
|
thresholds: {
|
||||||
|
lines: 80,
|
||||||
|
functions: 80,
|
||||||
|
branches: 75,
|
||||||
|
statements: 80
|
||||||
|
}
|
||||||
|
},
|
||||||
|
include: ['tests/**/*.test.js', 'tests/**/*.spec.js']
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user