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

Conversation

markjaquith
Copy link
Contributor

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:

  • 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • 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

This allows for param matcher tests to be collocated.

fixes sveltejs#7583
@changeset-bot
Copy link

changeset-bot bot commented Dec 22, 2022

🦋 Changeset detected

Latest commit: 4e24a6a

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

@vercel
Copy link

vercel bot commented Dec 22, 2022

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)

@benmccann
Copy link
Member

There are other places we might need special handling for test extensions. E.g. #8180 may need it. Perhaps we should create a list of extensions that can be referenced other places where it may be needed

@markjaquith
Copy link
Contributor Author

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

@benmccann
Copy link
Member

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

@Rich-Harris
Copy link
Member

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?

@benmccann
Copy link
Member

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

@Rich-Harris
Copy link
Member

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

@Rich-Harris
Copy link
Member

thank you!

@github-actions github-actions bot mentioned this pull request Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow unit test files in params directory
3 participants