Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"eslint": "^9.34.0",
"prettier": "^3.6.0",
"prettier-plugin-svelte": "^3.4.0",
"typescript-eslint": "^8.43.0"
"typescript-eslint": "^8.43.0",
"vitest": "catalog:"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-auto/test/adapters.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert, test } from 'vitest';
import { adapters } from 'adapters.js';
import { adapters } from '../adapters.js';
import { existsSync, readFileSync } from 'node:fs';

test('adapter versions are up to date', () => {
Expand Down
27 changes: 9 additions & 18 deletions packages/kit/test/apps/basics/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from 'node:path';
import path from 'node:path';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';

Expand All @@ -20,22 +20,13 @@ export default defineConfig({
},
test: {
expect: { requireAssertions: true },
projects: [
{
extends: './vite.config.js',
test: {
name: 'client',
environment: 'browser',
browser: {
enabled: true,
provider: 'playwright',
instances: [{ browser: 'chromium' }],
headless: true
},
include: ['unit-test/**/*.spec.js'],
setupFiles: ['./vitest-setup-client.ts']
}
}
]
browser: {
enabled: true,
provider: 'playwright',
instances: [{ browser: 'chromium' }],
headless: true
},
include: ['unit-test/**/*.spec.js'],
setupFiles: ['vitest-setup-client.ts'],
}
});
19 changes: 11 additions & 8 deletions packages/kit/test/build-errors/env.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { assert, test } from 'vitest';
import { execSync } from 'node:child_process';
import path from 'node:path';
import process from 'node:process';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { assert, test } from 'vitest';

const timeout = 60_000;

const dir = path.dirname(fileURLToPath(import.meta.url));

// ordinarily server-only modules are allowed during testing, since Vitest can't differentiate
/** @type {Record<string, any>} */
const env = { ...process.env, TEST: false };
Expand All @@ -13,7 +16,7 @@ test('$env/dynamic/private is not statically importable from the client', { time
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/private-dynamic-env'),
cwd: path.join(dir, 'apps/private-dynamic-env'),
stdio: 'pipe',
timeout,
env
Expand All @@ -26,7 +29,7 @@ test('$env/dynamic/private is not dynamically importable from the client', { tim
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/private-dynamic-env-dynamic-import'),
cwd: path.join(dir, 'apps/private-dynamic-env-dynamic-import'),
stdio: 'pipe',
timeout,
env
Expand All @@ -39,7 +42,7 @@ test('$env/static/private is not statically importable from the client', { timeo
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/private-static-env'),
cwd: path.join(dir, 'apps/private-static-env'),
stdio: 'pipe',
timeout,
env
Expand All @@ -52,7 +55,7 @@ test('$env/static/private is not dynamically importable from the client', { time
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/private-static-env-dynamic-import'),
cwd: path.join(dir, 'apps/private-static-env-dynamic-import'),
stdio: 'pipe',
timeout,
env
Expand All @@ -65,7 +68,7 @@ test('$env/dynamic/private is not importable from the service worker', { timeout
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/service-worker-private-env'),
cwd: path.join(dir, 'apps/service-worker-private-env'),
stdio: 'pipe',
timeout,
env
Expand All @@ -78,7 +81,7 @@ test('$env/dynamic/public is not importable from the service worker', { timeout
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/service-worker-dynamic-public-env'),
cwd: path.join(dir, 'apps/service-worker-dynamic-public-env'),
stdio: 'pipe',
timeout,
env
Expand Down
14 changes: 8 additions & 6 deletions packages/kit/test/build-errors/prerender.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { assert, test } from 'vitest';
import { execSync } from 'node:child_process';
import path from 'node:path';
import { execSync } from 'node:child_process';
import { EOL } from 'node:os';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { assert, test } from 'vitest';

const timeout = 60_000;

const dir = path.dirname(fileURLToPath(import.meta.url));

test('prerenderable routes must be prerendered', { timeout }, () => {
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/prerenderable-not-prerendered'),
cwd: path.join(dir, 'apps/prerenderable-not-prerendered'),
stdio: 'pipe',
timeout
}),
Expand All @@ -22,7 +24,7 @@ test('entry generators should match their own route', { timeout }, () => {
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/prerender-entry-generator-mismatch'),
cwd: path.join(dir, 'apps/prerender-entry-generator-mismatch'),
stdio: 'pipe',
timeout
}),
Expand All @@ -34,7 +36,7 @@ test('an error in a `prerender` function should fail the build', { timeout }, ()
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/prerender-remote-function-error'),
cwd: path.join(dir, 'apps/prerender-remote-function-error'),
stdio: 'pipe',
timeout
}),
Expand Down
15 changes: 9 additions & 6 deletions packages/kit/test/build-errors/server-only.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { assert, test } from 'vitest';
import { execSync } from 'node:child_process';
import path from 'node:path';
import process from 'node:process';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { assert, test } from 'vitest';

const timeout = 60_000;

const dir = path.dirname(fileURLToPath(import.meta.url));

// ordinarily server-only modules are allowed during testing, since Vitest can't differentiate
/** @type {Record<string, any>} */
const env = { ...process.env, TEST: false };
Expand All @@ -13,7 +16,7 @@ test('$lib/*.server.* is not statically importable from the client', { timeout }
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/server-only-module'),
cwd: path.join(dir, 'apps/server-only-module'),
stdio: 'pipe',
timeout,
env
Expand All @@ -26,7 +29,7 @@ test('$lib/*.server.* is not dynamically importable from the client', { timeout
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/server-only-module-dynamic-import'),
cwd: path.join(dir, 'apps/server-only-module-dynamic-import'),
stdio: 'pipe',
timeout,
env
Expand All @@ -39,7 +42,7 @@ test('$lib/server/* is not statically importable from the client', { timeout },
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/server-only-folder'),
cwd: path.join(dir, 'apps/server-only-folder'),
stdio: 'pipe',
timeout,
env
Expand All @@ -52,7 +55,7 @@ test('$lib/server/* is not dynamically importable from the client', { timeout },
assert.throws(
() =>
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/server-only-folder-dynamic-import'),
cwd: path.join(dir, 'apps/server-only-folder-dynamic-import'),
stdio: 'pipe',
timeout,
env
Expand Down
10 changes: 6 additions & 4 deletions packages/kit/test/build-errors/syntax-error.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { assert, test } from 'vitest';
import { execSync } from 'node:child_process';
import path from 'node:path';
import process from 'node:process';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { assert, test } from 'vitest';

const timeout = 60_000;

const dir = path.dirname(fileURLToPath(import.meta.url));

test('$lib/*.server.* is not statically importable from the client', { timeout }, () => {
try {
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/syntax-error'),
cwd: path.join(dir, 'apps/syntax-error'),
stdio: 'pipe',
timeout
});
Expand Down
18 changes: 11 additions & 7 deletions packages/kit/test/prerendering/basics/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import * as path from 'node:path';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';

/** @type {import('vitest/config').UserConfig} */
const config = {
// we need to append the current directory because Vitest's workspace config
// doesn't correctly resolve relative paths in `include`
const dir = path.dirname(fileURLToPath(import.meta.url));

export default defineConfig({
build: {
minify: false
},
Expand All @@ -24,8 +29,7 @@ const config = {
},

test: {
globalSetup: './globalSetup.js'
globalSetup: `${dir}/globalSetup.js`,
include: [`${dir}/test/**/*.spec.js`]
}
};

export default config;
});
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"checkJs": true,
"noEmit": true
},
"include": ["eslint.config.js"]
"include": ["eslint.config.js", "vitest.config.js"]
}
79 changes: 79 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
projects: [
{
test: {
root: 'packages/adapter-auto',
name: 'adapter-auto',
}
},
{
test: {
root: 'packages/adapter-cloudflare',
name: 'adapter-cloudflare',
}
},
{
test: {
root: 'packages/adapter-netlify',
name: 'adapter-netlify',
}
},
{
test: {
root: 'packages/adapter-node',
name: 'adapter-node',
}
},
{
test: {
root: 'packages/adapter-vercel',
name: 'adapter-vercel',
}
},
{
test: {
root: 'packages/enhanced-img',
name: 'enhanced-img',
}
},
{
test: {
root: 'packages/package',
name: 'package'
}
},
// TODO: 'Creates correct $types' test in write_types/index.spec.js does not work because of the wrong cwd
{
extends: 'packages/kit/kit.vitest.config.js',
test: {
root: 'packages/kit',
name: 'kit',
}
},
// TODO: uncomment this when cwd is set correctly
// {
// extends: 'packages/kit/test/apps/basics/vite.config.js',
// test: {
// root: 'packages/kit/test/apps/basics',
// name: 'kit-apps-basics',
// }
// },
{
test: {
root: 'packages/kit/test/build-errors',
name: 'kit-build-errors',
}
},
{
extends: 'packages/kit/test/prerendering/basics/vite.config.js',
test: {
root:'packages/kit/test/prerendering/basics',
name: 'kit-prerendering-basics',
}
}
]
}
});
Loading