kit
kit copied to clipboard
Ignore param matchers that match .{spec,test}.{js,ts}
This allows for param matcher tests to be collocated with their matchers
fixes #7583
Collocation of tests is a common practice, and the current param matcher scanning will throw an error if there are .{test,spec}.{js,ts}
files in the src/params
directory, as it sees them as malformed param names.
This is a simple change that just skips over those files instead of throwing an exception.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [ ] Ideally, include a test that fails without this PR but passes with it.
Tests
- [x] Run the tests with
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
- [ ] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0
🦋 Changeset detected
Latest commit: 4e24a6aea8ba4cca14b068f77488fa05faa7578f
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
Name | Type |
---|---|
@sveltejs/kit | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Updated |
---|---|---|---|
kit | 🔄 Building (Inspect) | Dec 22, 2022 at 9:28PM (UTC) |
There are other places we might need special handling for test extensions. E.g. https://github.com/sveltejs/kit/issues/8180 may need it. Perhaps we should create a list of extensions that can be referenced other places where it may be needed
Perhaps we should create a list of extensions that can be referenced other places where it may be needed
Makes sense. Don't know if it makes sense to abstract out the js
and ts
parts (I really thought CoffeeScript was gonna be the last "transpiles to JS" language but I was wrong):
const langExtensions = ['js', 'ts']
const testFlags = ['spec', 'test']
const testExtensions = langExtensions.map(lang => testFlags.map(flag => `.${flag}.${lang}`)).flat()
function isTestFile(file: string) {
return testExtensions.some(ext => file.endsWith(ext))
}
There's a setting for js
and ts
part: https://kit.svelte.dev/docs/configuration#moduleextensions
Perhaps we should create a list of extensions that can be referenced other places where it may be needed
Are you saying there'd be a config option that allows you do to e.g. +page.test.js
?
No, just that we could refactor .test
and .spec
into a variable holding an array that can be referenced elsewhere
I looked into #8180 and the solution is unrelated, so I'm going to file the test extensions array under YAGNI
thank you!