kit icon indicating copy to clipboard operation
kit copied to clipboard

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

Open markjaquith opened this issue 2 years ago • 5 comments

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 with pnpm lint and pnpm 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 be patch until SvelteKit 1.0

markjaquith avatar Dec 22 '22 21:12 markjaquith

🦋 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

changeset-bot[bot] avatar Dec 22 '22 21:12 changeset-bot[bot]

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)

vercel[bot] avatar Dec 22 '22 21:12 vercel[bot]

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

benmccann avatar Dec 23 '22 15:12 benmccann

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))
}

markjaquith avatar Dec 23 '22 16:12 markjaquith

There's a setting for js and ts part: https://kit.svelte.dev/docs/configuration#moduleextensions

benmccann avatar Dec 23 '22 16:12 benmccann

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?

Rich-Harris avatar Jan 05 '23 15:01 Rich-Harris

No, just that we could refactor .test and .spec into a variable holding an array that can be referenced elsewhere

benmccann avatar Jan 05 '23 15:01 benmccann

I looked into #8180 and the solution is unrelated, so I'm going to file the test extensions array under YAGNI

Rich-Harris avatar Jan 06 '23 15:01 Rich-Harris

thank you!

Rich-Harris avatar Jan 06 '23 15:01 Rich-Harris