Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storyshots breaking with latest native storybook #2325

Closed
ritz078 opened this issue Nov 16, 2017 · 6 comments
Closed

Storyshots breaking with latest native storybook #2325

ritz078 opened this issue Nov 16, 2017 · 6 comments

Comments

@ritz078
Copy link
Contributor

ritz078 commented Nov 16, 2017

 FAIL  __tests__/Storyshots.test.js
  ● Test suite failed to run

    /Users/ritz078/projects/agents-app/node_modules/@storybook/react-native/dist/preview/components/OnDeviceUI/menu_open.png:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){�PNG
                                                                                             ^
    
    SyntaxError: Invalid or unexpected token
      
      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17)
      at Object.<anonymous> (node_modules/@storybook/react-native/dist/preview/components/OnDeviceUI/index.js:51:21)
      at Object.<anonymous> (node_modules/@storybook/react-native/dist/preview/index.js:47:19)

Versions

"@storybook/addon-storyshots": "v3.3.0-alpha.3",
"@storybook/react-native": "v3.3.0-alpha.3",
@danielduan
Copy link
Member

danielduan commented Nov 16, 2017

We need storyshots in our cra and maybe crna example too so we can test test and catch these regressions.

@brenordr
Copy link
Contributor

I'm getting the same error, It appeared after upgrade from RN48 to RN50,
I suspect that this is due the metro bundler, it's trying import the image as text (very weird, but this "�PNG" is at the beginning of every PNG file if you try open it as text in an editor)

This bug is very annoying since the CI pipeline of my company is locked to accept only commits that pass all stages 😒

@brenordr
Copy link
Contributor

@ritz078

Seems that this issue is with Jest itself.
Just fixed in the env here.

First install the package jest-static-stubs
then:

in package.json
at jest configs:

"moduleNameMapper": {
    ".+\\.(png)$": "jest-static-stubs\$1"
 },

This will add a mock to PNG images, instead try import it.
I've ended creating a custom mock instead of use jest-static-stubs.

@stale
Copy link

stale bot commented Jan 25, 2018

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!

@stale stale bot added the inactive label Jan 25, 2018
@igor-dv igor-dv closed this as completed Jan 25, 2018
@hmontes
Copy link

hmontes commented Jan 26, 2018

the @rodriguesbreno solution worked for me with this package.json configuration

"jest": {
    "preset": "react-native",
    "moduleNameMapper": {
    ".+\\.(png)$": "jest-static-stubs/png"
    }
  }

But, i receive this warning in the console.

console.warn node_modules/react-native/jest/setup.js:99
      Calling .blur() in the test renderer environment is not supported. Instead, mock out your components that use findNodeHandle with replacements that don't rely on the native environment.

I think we need a better solution. Is a jest issue?

@macrozone
Copy link
Contributor

macrozone commented May 1, 2018

@rodriguesbreno i added

"jest": {
    "preset": "react-native",
    "moduleNameMapper": {
      ".+\\.(png)$": "jest-static-stubs"
    }
  },

but it fails with

 Configuration error:

    Could not locate module ./menu_open.png (mapped as jest-static-stubs)

    Please check:

    "moduleNameMapper": {
      "/.+\.(png)$/": "jest-static-stubs"
    },
    "resolver": undefined

EDIT: jest-static-stubs was not installed, i seem to have overwritten the package.json while installing the module...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants