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.

Storyshots Addon: Cannot find module 'jest-preset-angular/setupJest' from 'loader.js'

See original GitHub issue

Describe the bug Starting the jest storyshots test fails with

Cannot find module 'jest-preset-angular/setupJest' from 'loader.js'

      at Resolver.resolveModule (../node_modules/jest-runtime/node_modules/jest-resolve/build/index.js:230:17)
      at setupAngularJestPreset (../node_modules/@storybook/addon-storyshots/dist/frameworks/angular/loader.js:29:11)
      at Object.load (../node_modules/@storybook/addon-storyshots/dist/frameworks/angular/loader.js:37:3)
      at loadFramework (../node_modules/@storybook/addon-storyshots/dist/frameworks/frameworkLoader.js:31:17)
      at Object.testStorySnapshots [as default] (../node_modules/@storybook/addon-storyshots/dist/api/index.js:57:36)

this is due to a change in the jest-preset-angular module structure the library moved the code in the npm package from the root dir to ./build

To Reproduce Set up a Storybook Angular project with storyshots addon. And start the jest screenshot test.

Expected behavior tests should run

Workaround

Mapping the jest-preset-angular module to the new path

moduleNameMapper: {
        'jest-preset-angular/(.*)':'<rootDir>/../node_modules/jest-preset-angular/build/$1'
    }

Additional context

I think fixes should be applied here

// storybook/addons/storyshots/storyshots-core/src/frameworks/angular/loader.ts
 require.requireActual('jest-preset-angular/setupJest');

// storybook/addons/storyshots/storyshots-core/src/frameworks/angular/renderTree.ts

// eslint-disable-next-line import/no-extraneous-dependencies
import AngularSnapshotSerializer from 'jest-preset-angular/AngularSnapshotSerializer';
// eslint-disable-next-line import/no-extraneous-dependencies
import HTMLCommentSerializer from 'jest-preset-angular/HTMLCommentSerializer';

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
JMainolcommented, Nov 3, 2020

I have 1 solution that works for me. I am working with these versions:

"jest": "^26.6.2",
"jest-preset-angular": "^7.1.1",

The problem is in jest-preset-angular module the dir root has changed. Now the folder /build doesnt exist. So you have to change calls to jest-preset-angular dir structure on these two files

storybook/addons/storyshots/storyshots-core/src/frameworks/angular/loader.ts storybook/addons/storyshots/storyshots-core/src/frameworks/angular/renderTree.ts

Here is properly explained: https://www.gitmemory.com/issue/storybookjs/storybook/9072/562472401

1reaction
emanguycommented, Dec 6, 2019

I had this problem too. My workaround was to install jest-preset-angular at version 6.x where the file structure matched that of the instructions.

See if running npm install --save-dev jest-preset-angular@6.x fixes the issue for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Storybook Addon StoryShots for Angular 12 - Stack Overflow
Storyshots addon doesn't handle this change yet, so you can use moduleNameMapper from jest config to rewrite path and fix your issue. See...
Read more >
Angular >=13 | jest-preset-angular - GitHub Pages
Cannot find modules error when importing any deep paths from Angular ESM format packages​. Cannot find module '@angular/common/locales/xx' from 'src/app/app.
Read more >
Cannot find module '@angular/core/testing' - You.com
So I was searching online for quite sometime then I came across this solution, hope it works for you as well. In the...
Read more >
storybook/addon-storyshots-puppeteer
Add the following modules into your app. npm install @storybook/addon-storyshots-puppeteer puppeteer --save-dev. ⚠️ As of Storybook 5.3 puppeteer is no ...
Read more >
Storyshots is unable to run tests using Angular 12 ... - Issuehunt
import initStoryShots from '@storybook/addon-storyshots'; initStoryShots(); ... ngcc FAIL src/stories/storyshots.test.js ○ Test suite failed to run Cannot ...
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