Building Storybook fails, unable to find Jest globals
See original GitHub issueDescribe the bug
Running yarn build-storybook
fails consistently after upgrading our dependencies. The “Compiling preview” step fails with this output (just a small sample):
ERR! => Failed to build the preview
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(6,1)
ERR! TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(7,3)
ERR! TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(9,5)
ERR! TS2304: Cannot find name 'expect'.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(10,5)
ERR! TS2304: Cannot find name 'expect'.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(13,3)
ERR! TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(15,5)
ERR! TS2304: Cannot find name 'expect'.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(16,5)
ERR! TS2304: Cannot find name 'expect'.
As one might expect, only test files that use Jest globals are affected. Running the tests and the app, however, works fine—only Storybook is failing.
Expected behavior Storybook builds successfully.
Versions:
- TypeScript
3.5.2
- React
16.8.0
- Storybook
5.1.8
- Jest
24.8.0
- @types/jest
24.0.15
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Jest Addon | Storybook: Frontend workshop for UI development
React storybook addon that show component jest report. ... You could create a prebuild:storybook npm script, which will never fail by appending ||...
Read more >Storybook: ReferenceError: jest is not defined - Stack Overflow
Been trying to figure out how to solve the error but I am stuck. EDIT: I resolved the error Jest is not defined...
Read more >[Sovled] Jest error Cannot find name 'it' in TypeScript
To solve the "Cannot find name 'it'" jest error, make sure to install the typings for jest - npm i -D @types/jest and...
Read more >jest referenceerror: global is not defined - You.com | The AI ...
Test suite failed to run ReferenceError: global is not defined at Object. ... Describe the bug I am trying to get Vite +...
Read more >Jest · Delightful JavaScript Testing
By ensuring your tests have unique global state, Jest can reliably run tests in parallel. To make things quick, Jest runs previously failed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @jackiehluo, just ran into the same issue as you did (Storybook breaking trying to load test.tsx files). It’s a long shot, but did you find a solution?
I am literally not even using glob patterns (listing the paths to the stories directly), but storybook is still including all ts files