refactor: Tests to separate location

This commit is contained in:
Aleksander Grygier 2025-11-29 21:44:57 +01:00
parent 949b5fd63e
commit ae8a1e8137
26 changed files with 44 additions and 22 deletions

View File

@ -1,7 +1,7 @@
import type { StorybookConfig } from '@storybook/sveltekit'; import type { StorybookConfig } from '@storybook/sveltekit';
const config: StorybookConfig = { const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|ts|svelte)'], stories: ['../tests/stories/**/*.mdx', '../tests/stories/**/*.stories.@(js|ts|svelte)'],
addons: [ addons: [
'@storybook/addon-svelte-csf', '@storybook/addon-svelte-csf',
'@chromatic-com/storybook', '@chromatic-com/storybook',

View File

@ -7,5 +7,5 @@ export default defineConfig({
timeout: 120000, timeout: 120000,
reuseExistingServer: false reuseExistingServer: false
}, },
testDir: 'e2e' testDir: 'tests/e2e'
}); });

View File

@ -2,12 +2,19 @@ import { describe, expect, it } from 'vitest';
import { isValidModelName, normalizeModelName } from './model-names'; import { isValidModelName, normalizeModelName } from './model-names';
describe('normalizeModelName', () => { describe('normalizeModelName', () => {
it('extracts filename from forward slash path', () => { it('preserves Hugging Face org/model format (single slash)', () => {
expect(normalizeModelName('models/model-name-1')).toBe('model-name-1'); // Single slash is treated as Hugging Face format and preserved
expect(normalizeModelName('path/to/model/model-name-2')).toBe('model-name-2'); expect(normalizeModelName('meta-llama/Llama-3.1-8B')).toBe('meta-llama/Llama-3.1-8B');
expect(normalizeModelName('models/model-name-1')).toBe('models/model-name-1');
}); });
it('extracts filename from backslash path', () => { it('extracts filename from multi-segment paths', () => {
// Multiple slashes -> extract just the filename
expect(normalizeModelName('path/to/model/model-name-2')).toBe('model-name-2');
expect(normalizeModelName('/absolute/path/to/model')).toBe('model');
});
it('extracts filename from backslash paths', () => {
expect(normalizeModelName('C\\Models\\model-name-1')).toBe('model-name-1'); expect(normalizeModelName('C\\Models\\model-name-1')).toBe('model-name-1');
expect(normalizeModelName('path\\to\\model\\model-name-2')).toBe('model-name-2'); expect(normalizeModelName('path\\to\\model\\model-name-2')).toBe('model-name-2');
}); });

View File

@ -1,11 +0,0 @@
import { describe, it } from 'vitest';
import { render } from 'vitest-browser-svelte';
import Page from './+page.svelte';
describe('/+page.svelte', () => {
it('should render page', async () => {
render(Page);
// todo - add tests
});
});

View File

@ -0,0 +1,17 @@
<script lang="ts">
import * as Tooltip from '$lib/components/ui/tooltip';
import * as Sidebar from '$lib/components/ui/sidebar/index.js';
import Page from '../../../src/routes/+page.svelte';
let sidebarOpen = $state(false);
</script>
<!--
Test wrapper that provides necessary context providers for component testing.
This mirrors the providers from +layout.svelte.
-->
<Tooltip.Provider>
<Sidebar.Provider bind:open={sidebarOpen}>
<Page />
</Sidebar.Provider>
</Tooltip.Provider>

View File

@ -0,0 +1,11 @@
import { describe, it, expect } from 'vitest';
import { render } from 'vitest-browser-svelte';
import TestWrapper from './components/TestWrapper.svelte';
describe('/+page.svelte', () => {
it('should render page without throwing', async () => {
// Basic smoke test - page should render without throwing errors
// API calls will fail in test environment but component should still mount
expect(() => render(TestWrapper)).not.toThrow();
});
});

View File

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -118,8 +118,7 @@ export default defineConfig({
provider: 'playwright', provider: 'playwright',
instances: [{ browser: 'chromium' }] instances: [{ browser: 'chromium' }]
}, },
include: ['src/**/*.svelte.{test,spec}.{js,ts}'], include: ['tests/client/**/*.svelte.{test,spec}.{js,ts}'],
exclude: ['src/lib/server/**'],
setupFiles: ['./vitest-setup-client.ts'] setupFiles: ['./vitest-setup-client.ts']
} }
}, },
@ -128,8 +127,7 @@ export default defineConfig({
test: { test: {
name: 'server', name: 'server',
environment: 'node', environment: 'node',
include: ['src/**/*.{test,spec}.{js,ts}'], include: ['tests/server/**/*.{test,spec}.{js,ts}']
exclude: ['src/**/*.svelte.{test,spec}.{js,ts}']
} }
}, },
{ {
@ -142,7 +140,7 @@ export default defineConfig({
provider: 'playwright', provider: 'playwright',
instances: [{ browser: 'chromium', headless: true }] instances: [{ browser: 'chromium', headless: true }]
}, },
include: ['src/**/*.stories.{js,ts,svelte}'], include: ['tests/stories/**/*.stories.{js,ts,svelte}'],
setupFiles: ['./.storybook/vitest.setup.ts'] setupFiles: ['./.storybook/vitest.setup.ts']
}, },
plugins: [ plugins: [