Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ignore *.{test,spec}.{js,ts} and similar files #13009

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/forty-insects-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': minor
---

feat: ignore \*.{test,spec}.{js,ts} and similar files
3 changes: 2 additions & 1 deletion packages/kit/kit.vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export default defineConfig({
'**/node_modules/**',
'**/.svelte-kit/**',
'**/.{idea,git,cache,output,temp}/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*'
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/src/core/sync/create_manifest_data/test/**'
]
}
});
1 change: 1 addition & 0 deletions packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const get_defaults = (prefix = '') => ({
},
inlineStyleThreshold: 0,
moduleExtensions: ['.js', '.ts'],
testExtensions: ['.test.js', '.test.ts', '.spec.js', '.spec.ts', '.stories.svelte'],
output: { preloadStrategy: 'modulepreload' },
outDir: join(prefix, '.svelte-kit'),
serviceWorker: {
Expand Down
7 changes: 7 additions & 0 deletions packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ const options = object(
inlineStyleThreshold: number(0),

moduleExtensions: string_array(['.js', '.ts']),
testExtensions: string_array([
'.test.js',
'.test.ts',
'.spec.js',
'.spec.ts',
'.stories.svelte'
]),

outDir: string('.svelte-kit'),

Expand Down
4 changes: 3 additions & 1 deletion packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ function create_matchers(config, cwd) {
if (fs.existsSync(config.kit.files.params)) {
for (const file of fs.readdirSync(config.kit.files.params)) {
const ext = path.extname(file);
if (!config.kit.moduleExtensions.includes(ext)) continue;
if (config.kit.testExtensions.includes(ext) || !config.kit.moduleExtensions.includes(ext))
continue;
const type = file.slice(0, -ext.length);

if (/^\w+$/.test(type)) {
Expand Down Expand Up @@ -222,6 +223,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
// process files first
for (const file of files) {
if (file.is_dir) continue;
if (config.kit.testExtensions.find((ext) => file.name.endsWith(ext))) continue;

const ext = valid_extensions.find((ext) => file.name.endsWith(ext));
if (!ext) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,10 @@ test('ignores things that look like lockfiles', () => {

test('works with custom extensions', () => {
const { nodes, routes } = create('samples/custom-extension', {
extensions: ['.jazz', '.beebop', '.funk', '.svelte']
extensions: ['.jazz', '.beebop', '.funk', '.svelte'],
kit: {
testExtensions: ['.rizz.jazz']
}
});

expect(nodes.map(simplify_node)).toEqual([
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,12 @@ export interface KitConfig {
* @default [".js", ".ts"]
*/
moduleExtensions?: string[];
/**
* An array of file extensions that SvelteKit will treat as test files and will ignore.
*
* @default [".test.js", ".test.ts", ".spec.js", ".spec.ts", ".stories.svelte"]
*/
testExtensions?: string[];
/**
* The directory that SvelteKit writes files to during `dev` and `build`. You should exclude this directory from version control.
* @default ".svelte-kit"
Expand Down
6 changes: 6 additions & 0 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ declare module '@sveltejs/kit' {
* @default [".js", ".ts"]
*/
moduleExtensions?: string[];
/**
* An array of file extensions that SvelteKit will treat as test files and will ignore.
*
* @default [".test.js", ".test.ts", ".spec.js", ".spec.ts", ".stories.svelte"]
*/
testExtensions?: string[];
/**
* The directory that SvelteKit writes files to during `dev` and `build`. You should exclude this directory from version control.
* @default ".svelte-kit"
Expand Down
Loading