question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing with Vitest

See original GitHub issue

Hello, any help how test vanilla-extract with Vitest?

Demo: Stackblitz

i have an error with npm run test

 FAIL  src/components/button/button.test.tsx [ src/components/button/button.test.tsx ]
Error: Styles were unable to be assigned to a file. This is generally caused by one of the following:

- You may have created styles outside of a '.css.ts' context
- You may have incorrect configuration. See https://vanilla-extract.style/documentation/setup

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:15
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
AndrewLeedhamcommented, Apr 28, 2022

Hey All. I ran into this a few weeks ago, it was a pain to debug. The issue is with some code being run in ESM and some in CJS so the file scopes stuff is split across 2 separate modules and therefore cannot see each-others local variables. Long story short you need to include the following in your Vite config:

{
  // ...
  test {
    deps: {
      fallbackCJS: true,
    }
  }
}

https://vitest.dev/config/#deps

See fixed fork here: https://stackblitz.com/edit/vitejs-vite-1fmagr?file=vite.config.ts

1reaction
frankwalliscommented, May 28, 2022

It looks to be related to this issue: https://github.com/vitest-dev/vitest/issues/747

Similar to the comment in that thread one solution is to delete node_modules/@vanilla-extract/css/fileScope/package.json

which interferes with the module resolution defined at the top-level (fallbackCJS: true did not work for me)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vitest | A blazing fast unit test framework powered by Vite
A blazing fast unit test framework powered by Vite. ... Reuse Vite's config, transformers, resolvers, and plugins - consistent across your app and...
Read more >
A guide to Vitest automated testing with Vue components
With Vue component testing, we can test our individual components to verify that they work correctly and that asynchronous operations are ...
Read more >
Vitest with React Testing Library - Robin Wieruch
Learn how to use React Testing Library with Vitest in Vite. React Testing Library is a popular testing library for writing tests in...
Read more >
Testing with Vitest - This Dot Labs
Vitest is a new testing framework powered by Vite. It's still in development, and some features may not be ready yet, but it's...
Read more >
Testing a React application with Vitest - Eternal Dev
Learn about testing React applications with Vitest. We will cover setting up react with vitest and show how to add unit tests and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found