Skip to content

Commit

Permalink
Ignore param matchers that match .{spec,test}.{js,ts} (#8250)
Browse files Browse the repository at this point in the history
* Ignore param matchers that match .{spec,test}.{js,ts}

This allows for param matcher tests to be collocated.

fixes #7583

* changeset/docs

Co-authored-by: Rich Harris <hello@rich-harris.dev>
  • Loading branch information
markjaquith and Rich-Harris committed Jan 6, 2023
1 parent 6de506a commit 366d290
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
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

0 comments on commit 366d290

Please sign in to comment.