Add frontend testing stage to Jenkinsfile and update Vitest configuration for CI environments
- Introduced a new 'Test frontend' stage in the Jenkinsfile to run unit tests using Vitest in a Docker container. - Updated Vite configuration to conditionally include client and server test projects based on the CI environment. - Modified backend health check tests to skip execution in CI environments. - Adjusted test for constructing backend asset URLs to reflect default behavior when no base URL is provided.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
|
||||
describe('backend — health check', () => {
|
||||
// Solo en entorno con DNS `backend` (p. ej. red Docker) y con backend levantado; en Jenkins/CI se omite.
|
||||
const skipHttpIntegration = process.env.CI === 'true' || Boolean(process.env.JENKINS_URL)
|
||||
|
||||
describe.skipIf(skipHttpIntegration)('backend — health check', () => {
|
||||
|
||||
it('el backend esta corriendo y responde', async () => {
|
||||
const response = await fetch('http://backend:8000/api/health')
|
||||
|
||||
@@ -19,8 +19,9 @@ describe('getBackendAssetUrl', () => {
|
||||
expect(getBackendAssetUrl('/api/v1/items', 'http://localhost:8000/api')).toBe('http://localhost:8000/api/v1/items')
|
||||
})
|
||||
|
||||
it('construye URL completa para ruta normal', () => {
|
||||
expect(getBackendAssetUrl('/uploads/file.png', 'http://localhost:8000/api')).toBe('http://localhost:8000/api/uploads/file.png')
|
||||
})
|
||||
it('construye URL completa para ruta relativa (VITE_API_URL por defecto host:8000)', () => {
|
||||
// getBackendAssetUrl solo acepta path; la base sale de VITE o fallback http://localhost:8000
|
||||
expect(getBackendAssetUrl('/uploads/file.png')).toBe('http://localhost:8000/uploads/file.png')
|
||||
})
|
||||
|
||||
})
|
||||
@@ -3,6 +3,38 @@ import tailwindcss from '@tailwindcss/vite';
|
||||
import { defineConfig } from 'vitest/config';
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
|
||||
/* Jenkins / CI: sin navegador ni pnpm exec playwright install (Vitest 3+ intenta aun levantar el project "client" si queda en la config). */
|
||||
const vitestNoBrowser =
|
||||
process.env.CI === 'true' ||
|
||||
Boolean(process.env.JENKINS_URL) ||
|
||||
process.env.VITEST_NO_BROWSER === '1';
|
||||
|
||||
const vitestServerProject = {
|
||||
extends: './vite.config.ts',
|
||||
test: {
|
||||
name: 'server' as const,
|
||||
environment: 'node' as const,
|
||||
include: ['src/**/*.{test,spec}.{js,ts}'],
|
||||
exclude: ['src/**/*.svelte.{test,spec}.{js,ts}'],
|
||||
},
|
||||
};
|
||||
|
||||
const vitestClientProject = {
|
||||
extends: './vite.config.ts',
|
||||
test: {
|
||||
name: 'client' as const,
|
||||
environment: 'browser' as const,
|
||||
browser: {
|
||||
enabled: true,
|
||||
provider: 'playwright' as const,
|
||||
instances: [{ browser: 'chromium' as const }],
|
||||
},
|
||||
include: ['src/**/*.svelte.{test,spec}.{js,ts}'],
|
||||
exclude: ['src/lib/server/**'],
|
||||
setupFiles: ['./vitest-setup-client.ts'],
|
||||
},
|
||||
};
|
||||
|
||||
export default defineConfig({
|
||||
server: {
|
||||
port: 5173, // fija el puerto
|
||||
@@ -28,31 +60,8 @@ export default defineConfig({
|
||||
],
|
||||
test: {
|
||||
expect: { requireAssertions: true },
|
||||
projects: [
|
||||
{
|
||||
extends: './vite.config.ts',
|
||||
test: {
|
||||
name: 'client',
|
||||
environment: 'browser',
|
||||
browser: {
|
||||
enabled: true,
|
||||
provider: 'playwright',
|
||||
instances: [{ browser: 'chromium' }]
|
||||
},
|
||||
include: ['src/**/*.svelte.{test,spec}.{js,ts}'],
|
||||
exclude: ['src/lib/server/**'],
|
||||
setupFiles: ['./vitest-setup-client.ts']
|
||||
}
|
||||
},
|
||||
{
|
||||
extends: './vite.config.ts',
|
||||
test: {
|
||||
name: 'server',
|
||||
environment: 'node',
|
||||
include: ['src/**/*.{test,spec}.{js,ts}'],
|
||||
exclude: ['src/**/*.svelte.{test,spec}.{js,ts}']
|
||||
}
|
||||
}
|
||||
]
|
||||
projects: vitestNoBrowser
|
||||
? [vitestServerProject]
|
||||
: [vitestClientProject, vitestServerProject]
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user