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

[Bug] Code outside of the yarn workspace are not instrumented #19

Open
sw-tracker opened this issue Mar 11, 2023 · 4 comments
Open

[Bug] Code outside of the yarn workspace are not instrumented #19

sw-tracker opened this issue Mar 11, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@sw-tracker
Copy link

sw-tracker commented Mar 11, 2023

Describe the bug

I have 2 yarn workspaces, one containing my app and another containing storybook.

Steps to reproduce the behavior

  1. Setup react in one yarn workspace, create react components and stories here
  2. Setup a separate yarn workspace and install storybook there
  3. Set storybook main.js stories to be found in the react workspace
  4. Start storybook
  5. Run tests with coverage -> Error: The code in this story is not instrumented, which means the coverage setup is likely not correct.
// main.js
module.exports = {
  stories: [
    "../../components/src/**/*.stories.mdx",
    "../../components/src/**/*.stories.@(js|jsx|ts|tsx)",
  ],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
    '@storybook/addon-coverage',
  ],
  framework: "@storybook/react",
  features: {
    interactionsDebugger: true,
  },
}

I have also ejected storybook to get the tests to run:

// test-runner-jest.config.js
const {getJestConfig} = require('@storybook/test-runner');

module.exports = {
  // The default configuration comes from @storybook/test-runner
  ...getJestConfig(),
  /** Add your own overrides below
   * @see https://jestjs.io/docs/configuration
   */
  rootDir: '../components/',
  testEnvironmentOptions: {
    'jest-playwright': {
      browsers: ['chromium'],
    },
  },
};

Expected behavior

Tests with coverage work.

Screenshots and/or logs

Error:

 [Test runner] An error occurred when evaluating code coverage:
      The code in this story is not instrumented, which means the coverage setup is likely not correct.
      More info: https://github.com/storybookjs/test-runner#setting-up-code-coverage

Environment

  • OS: Windows
  • Node.js version: v14.21.1
  • NPM version: 6.14.17
  • Browser (if applicable): chrome (although storybook app isnt open)
@sw-tracker sw-tracker added the bug Something isn't working label Mar 11, 2023
@HenryKenya
Copy link

Having the same error despite the addon being setup correctly

@HenryKenya
Copy link

HenryKenya commented May 10, 2023

@yannbf is this a known thing?

@himself65
Copy link

same error here

@idesigncode
Copy link

idesigncode commented Jun 9, 2023

Possibly unrelated but I was getting this error when using an external React component (from an installed dependency) within the render/component of a story. It was the external component that could not be instrumented as removing it allowed the coverage tests to run.

npx sb upgrade seems to have resolved my issue now (although I was only using one workspace).

Alternatively you could try specifying where you want coverage from with the include configuration ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants