Merge pull request 'Add frontend testing stage to Jenkinsfile and update Vitest configuration for CI environments' (#312) from feature/testing into development
Reviewed-on: ADUANASOFT/anexo76#312
This commit is contained in:
28
Jenkinsfile
vendored
28
Jenkinsfile
vendored
@@ -131,6 +131,34 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
/* Frontend: i18n (paraglide no versionado) + vitest solo proyecto "server" (Node).
|
||||
* "client" usa @vitest/browser+Playwright: requeriría playwright install (chromium) en el contenedor.
|
||||
* pnpm run check svelte-check se omite mientras haya deuda de tipos en el árbol; pnpm run lint alinear cuando pase. */
|
||||
stage('Test frontend') {
|
||||
steps {
|
||||
sh '''
|
||||
set -euxo pipefail
|
||||
echo "== Test frontend (vitest —project server) =="
|
||||
docker run --rm \
|
||||
-e CI=true \
|
||||
-e NODE_ENV=test \
|
||||
-e JENKINS_URL=${JENKINS_URL} \
|
||||
-v "$WORKSPACE:/workspace" \
|
||||
-w /workspace/frontend \
|
||||
node:22-bookworm \
|
||||
bash -lc '
|
||||
set -euxo pipefail
|
||||
node --version
|
||||
corepack enable
|
||||
pnpm --version
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm run i18n:compile
|
||||
pnpm run test:unit -- --run
|
||||
'
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Generate version') {
|
||||
steps {
|
||||
script {
|
||||
|
||||
@@ -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