Skip to content

Conversation

@Rich-Harris
Copy link
Member

This is a naive but effective fix for #8180. When running Vitest, both process.env.VITEST and process.env.TEST are true, meaning we can simply ignore illegal imports during unit testing.

I opted for TEST over VITEST because it will then work with any unit testing framework that works with Vite, as long as they adhere to this convention.

I think it's totally fine to skip detection during tests, since it'd be vanishingly rare that something was explicitly testing for that behaviour. The error will show up soon enough in dev, and the build will fail.

One gotcha is that if you do TEST=true npm run dev it will disable illegal import detection during dev (not build), which I think is probably a fine trade-off.

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

@changeset-bot
Copy link

changeset-bot bot commented Jan 6, 2023

🦋 Changeset detected

Latest commit: e9e1285

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 Jan 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
kit 🔄 Building (Inspect) Jan 8, 2023 at 5:21PM (UTC)

@Conduitry
Copy link
Member

I think we should list this in the docs somewhere. Unless this TEST=true convention is very widespread and somehow everyone's heard about it but me?

@Rich-Harris
Copy link
Member Author

added some docs

@dummdidumm dummdidumm merged commit ac082cf into master Jan 9, 2023
@dummdidumm dummdidumm deleted the gh-8180 branch January 9, 2023 09:45
@github-actions github-actions bot mentioned this pull request Jan 9, 2023
HEYGUL added a commit to gip-inclusion/carnet-de-bord that referenced this pull request Apr 1, 2023
This is needed to make tests pass

see sveltejs/kit#8365
HEYGUL added a commit to gip-inclusion/carnet-de-bord that referenced this pull request Apr 1, 2023
This is needed to make tests pass

see sveltejs/kit#8365
HEYGUL added a commit to gip-inclusion/carnet-de-bord that referenced this pull request Apr 1, 2023
This is needed to make tests pass

see sveltejs/kit#8365
HEYGUL added a commit to gip-inclusion/carnet-de-bord that referenced this pull request Apr 3, 2023
This is needed to make tests pass

see sveltejs/kit#8365
HEYGUL added a commit to gip-inclusion/carnet-de-bord that referenced this pull request Apr 8, 2023
This is needed to make tests pass

see sveltejs/kit#8365
vjousse pushed a commit to gip-inclusion/carnet-de-bord that referenced this pull request Apr 11, 2023
This is needed to make tests pass

see sveltejs/kit#8365
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.

Unable to perform Vitest integrations tests using $env/dynamic/private

4 participants