profile
viewpoint

Ask questionsinitStoryshots can't work with typescript and accessing non-needed files

Describe the bug

initStoryshots doesn't work with typescript, although stories are written in typescript

To Reproduce

  1. init storybook

  2. create test files:

// jest.config.js
  module.exports = {
    transform: {
    '^.+\\.[tj]sx?$': 'babel-jest',
    '^.+\\.mdx$': '@storybook/addon-docs/jest-transform-mdx',
  },
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
  };

// tests/storybook.test.ts
import path from 'path';

import initStoryshots from '@storybook/addon-storyshots';
import { imageSnapshot } from '@storybook/addon-storyshots-puppeteer';


initStoryshots({
  suite: 'sample',
  test: imageSnapshot({
    storybookUrl: `file://${path.resolve(__dirname, '../storybook-static')}`,
    getMatchOptions: () => ({
      failureThreshold: 0.05,
      failureThresholdType: 'percent',
    }),
  }),
});

  1. build-storybook

  2. jest. you will see this

FAIL  tests/sampleTest.test.ts
  ● Test suite failed to run

    storyshots found 0 stories

      10 | });
      11 |
    > 12 | initStoryshots({
         | ^
      13 |   suite: 'sample',
      14 |   test: imageSnapshot({
      15 |     storybookUrl: `file://${path.resolve(__dirname, '../storybook-static')}`,

      at testStorySnapshots (../../../node_modules/@storybook/addon-storyshots/dist/ts3.9/api/index.js:104:15)
      at Object.<anonymous> (tests/sampleTest.test.ts:12:1)

  console.warn
    Unexpected error while loading ./stories/Introduction.stories.mdx: SyntaxError: Unexpected token 'export'

      at Object.warn (../../../node_modules/@storybook/client-logger/dist/cjs/index.js:63:73)
      at ../../../node_modules/@storybook/core-client/dist/cjs/preview/loadCsf.js:101:34
          at Array.forEach (<anonymous>)
      at ../../../node_modules/@storybook/core-client/dist/cjs/preview/loadCsf.js:94:20
          at Array.forEach (<anonymous>)
      at ../../../node_modules/@storybook/core-client/dist/cjs/preview/loadCsf.js:93:12
      at ConfigApi.configure (../../../node_modules/@storybook/core-client/node_modules/@storybook/client-api/dist/cjs/config_api.js:26:7)

  console.warn
    Unexpected error while loading ./stories/Button.stories.tsx: SyntaxError: Unexpected token '.'

      at Object.warn (../../../node_modules/@storybook/client-logger/dist/cjs/index.js:63:73)
      at ../../../node_modules/@storybook/core-client/dist/cjs/preview/loadCsf.js:101:34
          at Array.forEach (<anonymous>)
      at ../../../node_modules/@storybook/core-client/dist/cjs/preview/loadCsf.js:94:20
          at Array.forEach (<anonymous>)
      at ../../../node_modules/@storybook/core-client/dist/cjs/preview/loadCsf.js:93:12
      at ConfigApi.configure (../../../node_modules/@storybook/core-client/node_modules/@storybook/client-api/dist/cjs/config_api.js:26:7)

  console.warn
    Unexpected error while loading ./stories/Header.stories.tsx: SyntaxError: Unexpected token '.'

      at Object.warn (../../../node_modules/@storybook/client-logger/dist/cjs/index.js:63:73)
      at ../../../node_modules/@storybook/core-client/dist/cjs/preview/loadCsf.js:101:34
          at Array.forEach (<anonymous>)
      at ../../../node_modules/@storybook/core-client/dist/cjs/preview/loadCsf.js:94:20
          at Array.forEach (<anonymous>)
      at ../../../node_modules/@storybook/core-client/dist/cjs/preview/loadCsf.js:93:12
      at ConfigApi.configure (../../../node_modules/@storybook/core-client/node_modules/@storybook/client-api/dist/cjs/config_api.js:26:7)

Expected behavior things working as https://github.com/storybookjs/storybook/tree/next/addons/storyshots/storyshots-core says

Screenshots If applicable, add screenshots to help explain your problem.

Code snippets If applicable, add code samples to help explain your problem.

System

Environment Info:

System: OS: macOS 10.15.7 CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz Binaries: Node: 12.20.1 - ~/.nvm/versions/node/v12.20.1/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.11 - ~/.nvm/versions/node/v12.20.1/bin/npm Browsers: Chrome: 89.0.4389.114 Safari: 14.0.3

Additional context

initStoryshots is configured to run local build storybooks, but it is accessing stories inside src dir, which is not suppose to be doing this..

storybookjs/storybook

Answer questions RWOverdijk

Did you happen to figure this out? What was the issue?

useful!
source:https://uonfu.com/
Github User Rank List