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: Wrong Code Coverage for JSX #267

Closed
1 of 2 tasks
asimonok opened this issue May 31, 2023 · 2 comments · Fixed by #271
Closed
1 of 2 tasks

Bug: Wrong Code Coverage for JSX #267

asimonok opened this issue May 31, 2023 · 2 comments · Fixed by #271
Labels
create-plugin related to the create-plugin tool released This issue/pull request has been released. type/bug Something isn't working

Comments

@asimonok
Copy link
Contributor

Which package(s) does this bug affect?

  • Create Plugin
  • Sign Plugin

Package versions

1.5.0

What happened?

After migration from @grafana/toolkit to the new plugin tools. The same code has less coverage that had before. It seems that some issue with coverage tool or jest config exists. The problem is related to all jsx/tsx files.

Coverage with default /.config/jest.config file (wrong coverage)
100% Statements 63/63
97.01% Branches 65/67
100% Functions 13/13
100% Lines 53/53
default

Way to fix the issue:

Adjusted /.config/jest.config file

transform: {
    '^.+\\.(t|j)sx?$': [
      '@swc/jest',
      {
        /**
         * Override sourceMaps with inline to see the correct coverage lines
         */
        sourceMaps: 'inline',
        jsc: {
          parser: {
            syntax: 'typescript',
            tsx: true,
            decorators: false,
            dynamicImport: true,
          },
        },
      },
    ],
  },

Coverage with adjusted jest config (correct coverage)
100% Statements 56/56
100% Branches 51/51
100% Functions 11/11
100% Lines 52/52
fixed

What you expected to happen

Code coverage for JSX is the same for the same code. Code coverage highlights uncovered lines correctly.

How to reproduce it (as minimally and precisely as possible)

  1. Migrate to the plugins tools (1.5.0) of the existing panel plugin
  2. Run jest tests with coverage
  3. Compare coverage with results before migration

Environment

System:
    OS: macOS 11.5.2
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 450.57 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Chrome: 113.0.5672.126
    Firefox: 94.0.1
    Safari: 14.1.2
  npmPackages:
    @grafana/data: 9.5.2 => 9.5.2 
    @grafana/e2e: ^9.5.2 => 9.5.2 
    @grafana/e2e-selectors: ^9.5.2 => 9.5.2 
    @grafana/eslint-config: ^5.1.0 => 5.1.0 
    @grafana/runtime: 9.5.2 => 9.5.2 
    @grafana/tsconfig: ^1.2.0-rc1 => 1.2.0-rc1 
    @grafana/ui: 9.5.2 => 9.5.2

Additional context

Tests packages versions

"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
@jackw jackw added create-plugin related to the create-plugin tool type/bug Something isn't working labels Jun 1, 2023
@jackw
Copy link
Collaborator

jackw commented Jun 1, 2023

Many thanks for raising this issue @asimonok . It looks like the underlying issue is indeed related to swc. Switching to inline source maps is one of the suggestions in that issue so it looks like a good addition to me. 👍

Would you be willing to open a PR with the fix?

@grafana-delivery-bot
Copy link

🚀 Issue was released in @grafana/create-plugin@1.5.2 🚀

@grafana-delivery-bot grafana-delivery-bot bot added the released This issue/pull request has been released. label Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-plugin related to the create-plugin tool released This issue/pull request has been released. type/bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants