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

Ignore param matchers that match .{spec,test}.{js,ts} #8250

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/healthy-lizards-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Ignore `*.test.js` and `*.spec.js` files in `params` directory
2 changes: 2 additions & 0 deletions documentation/docs/30-advanced/10-advanced-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export function match(param) {

If the pathname doesn't match, SvelteKit will try to match other routes (using the sort order specified below), before eventually returning a 404.

Each module in the `params` directory corresponds to a matcher, with the exception of `*.test.js` and `*.spec.js` files which may be used to unit test your matchers.

> Matchers run both on the server and in the browser.

## Sorting
Expand Down
3 changes: 3 additions & 0 deletions packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ function create_matchers(config, cwd) {
matchers[type] = matcher_file;
}
} else {
// Allow for matcher test collocation
if (type.endsWith('.test') || type.endsWith('.spec')) continue;

throw new Error(
`Matcher names can only have underscores and alphanumeric characters — "${file}" is invalid`
);
Expand Down