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.

Broken Storyshots with latest jest-preset-angular due to setupJest module being renamed to setup-jest on ^8.3.0

See original GitHub issue

Describe the bug

The jest-preset-angular library has a breaking change (and the only one that I’ve come across) introduced on its v8.3.0 release. They’ve renamed the setupJest file to setup-jest.

This loader storybook/addons/storyshots/storyshots-core/src/frameworks/angular/loader.ts is requiring setupJest.

To Reproduce Steps to reproduce the behavior:

Use the latest storyshots with "jest-preset-angular": "^8.3.0", run jest and you’ll get the following

Cannot find module 'jest-preset-angular/build/setupJest' from 'node_modules/@storybook/addon-storyshots/dist/frameworks/angular/loader.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:307:11)
      at requireActual (node_modules/@storybook/addon-storyshots/dist/frameworks/angular/loader.js:32:10)
      at Object.setupAngularJestPreset [as load] (node_modules/@storybook/addon-storyshots/dist/frameworks/angular/loader.js:38:5)
      at Object.load [as default] (node_modules/@storybook/addon-storyshots/dist/frameworks/frameworkLoader.js:26:19)
      at testStorySnapshots (node_modules/@storybook/addon-storyshots/dist/api/index.js:60:14)

Expected behavior

The tests should run normally.

Screenshots N/A

Code snippets N/A

System: N/A

Additional context N/A

Please let me know if it’s alright to raise a PR for this.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
DSteinmanncommented, Dec 22, 2021

You can also map the modules until this is fixed in your jest.config.js:

  moduleNameMapper: {
    'jest-preset-angular/build/setup-jest': 'jest-preset-angular/setup-jest',
    'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer':
      'jest-preset-angular/build/serializers/no-ng-attributes',
    'jest-preset-angular/build/AngularSnapshotSerializer':
      'jest-preset-angular/build/serializers/ng-snapshot',
    'jest-preset-angular/build/HTMLCommentSerializer':
      'jest-preset-angular/build/serializers/html-comment'
  },
6reactions
andyleeboocommented, Dec 8, 2020

I got the same error while following the official guide Learn Storybook.

● Test suite failed to run

Cannot find module 'jest-preset-angular/build/setup-jest' from 'node_modules/@storybook/addon-storyshots/dist/frameworks/angular/loader.js'

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11)
  at setupAngularJestPreset (node_modules/@storybook/addon-storyshots/dist/frameworks/angular/loader.js:36:14)
  at Object.load (node_modules/@storybook/addon-storyshots/dist/frameworks/angular/loader.js:43:5)
  at Object.loadFramework [as default] (node_modules/@storybook/addon-storyshots/dist/frameworks/frameworkLoader.js:26:19)
  at testStorySnapshots (node_modules/@storybook/addon-storyshots/dist/api/index.js:60:14)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Storybook Addon StoryShots for Angular 12 - Stack Overflow
Since jest-preset-angular version 9, setup-jest.ts is no longer located into jest-preset-angular/build/ folder (and this is not the only impacted file).
Read more >
jest-preset-angular | Yarn - Package Manager
Getting Started. These instructions will get you setup to use jest-preset-angular in your project. For more detailed documentation, please check online ...
Read more >
Cannot find module '@angular/core/testing' - You.com
Cannot find module '@angular/core/testing' from 'node_modules/jest-preset-angular/build/setup-jest.js. app references appear to be fine.
Read more >
Storyshots is unable to run tests using Angular 12 ... - Issuehunt
//setup-jest.ts import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/ ...
Read more >
Angular >=13 | jest-preset-angular - GitHub Pages
0.0, jest-preset-angular introduces a few extra changes to be able to run Jest with Angular 13: moduleFileExtensions is updated to include mjs files...
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