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

Fixed incorrect coverage for Vue files #711

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marekdedic
Copy link
Contributor

This somehow fixes the Vue error described in the comments of #707.

I have no idea how this works, but at least in https://github.com/rklos/istanbul-lib-instrument-repro it seems a string is passed as the inputSourceMap and it contains the following:

"{\"version\":3,\"sources\":[\"/home/marekdedic/Documents/git/istanbul-lib-instrument-repro/components/NuxtLogo.vue\"],\"names\":[],\"mappings\":\";;;;;;;eAUe;EACb,IAAI,EAAE,UADO;EAEb,OAAO,EAAE;IACP,OAAO,GAAG;MACR,KAAK,CAAC,OAAD,CAAL;IACD;;EAHM;AAFI\",\"file\":\"/home/marekdedic/Documents/git/istanbul-lib-instrument-repro/components/NuxtLogo.vue\",\"sourcesContent\":[\"<template>\\n  <div id=\\\"logo-wrapper\\\" @click=\\\"onClick\\\">\\n    Nuxt Logo\\n    <svg class=\\\"nuxt-logo\\\" viewBox=\\\"0 0 45 30\\\" fill=\\\"none\\\" xmlns=\\\"http://www.w3.org/2000/svg\\\">\\n      <path d=\\\"M24.7203 29.704H41.1008C41.6211 29.7041 42.1322 29.5669 42.5828 29.3061C43.0334 29.0454 43.4075 28.6704 43.6675 28.2188C43.9275 27.7672 44.0643 27.2549 44.0641 26.7335C44.0639 26.2121 43.9266 25.6999 43.6662 25.2485L32.6655 6.15312C32.4055 5.70162 32.0315 5.32667 31.581 5.06598C31.1305 4.8053 30.6195 4.66805 30.0994 4.66805C29.5792 4.66805 29.0682 4.8053 28.6177 5.06598C28.1672 5.32667 27.7932 5.70162 27.5332 6.15312L24.7203 11.039L19.2208 1.48485C18.9606 1.03338 18.5864 0.658493 18.1358 0.397853C17.6852 0.137213 17.1741 0 16.6538 0C16.1336 0 15.6225 0.137213 15.1719 0.397853C14.7213 0.658493 14.3471 1.03338 14.0868 1.48485L0.397874 25.2485C0.137452 25.6999 0.000226653 26.2121 2.8053e-07 26.7335C-0.000226092 27.2549 0.136554 27.7672 0.396584 28.2188C0.656614 28.6704 1.03072 29.0454 1.48129 29.3061C1.93185 29.5669 2.44298 29.7041 2.96326 29.704H13.2456C17.3195 29.704 20.3239 27.9106 22.3912 24.4118L27.4102 15.7008L30.0986 11.039L38.1667 25.0422H27.4102L24.7203 29.704ZM13.0779 25.0374L5.9022 25.0358L16.6586 6.36589L22.0257 15.7008L18.4322 21.9401C17.0593 24.2103 15.4996 25.0374 13.0779 25.0374Z\\\" fill=\\\"#00DC82\\\" />\\n    </svg>\\n  </div>\\n</template>\\n\\n<script>\\nexport default {\\n  name: 'NuxtLogo',\\n  methods: {\\n    onClick() {\\n      alert('click');\\n    }\\n  }\\n}\\n</script>\\n\\n<style>\\n.nuxt-logo {\\n  height: 180px;\\n}\\n</style>\\n\"]}"

Yes, that actually is a JSON encoded value, passed as a string.

@marekdedic
Copy link
Contributor Author

@Shereef, would you please try this for your version of #707 as well?

@unematiii
Copy link

@marekdedic Regarding #707, this seems to fix it for me.

@Shereef
Copy link

Shereef commented Feb 7, 2023

@marekdedic

  1. I removed the /* istanbul ignore next*/
  2. npm install 'https://gitpkg.now.sh/marekdedic/istanbuljs/packages/istanbul-lib-instrument?coverage-fix'
  3. npm run test:cov
---------------------------------------------------|---------|----------|---------|---------|-------------------
File                                               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
---------------------------------------------------|---------|----------|---------|---------|-------------------
All files                                          |   99.12 |      100 |   95.55 |      99 |                   
 auth                                              |     100 |      100 |     100 |     100 |                   
  jwt-auth.guard.graphql.ts                        |     100 |      100 |     100 |     100 |                   
  jwt-auth.guard.http.ts                           |     100 |      100 |     100 |     100 |                   
  jwt.strategy.ts                                  |     100 |      100 |     100 |     100 |                   
 config/app.config                                 |     100 |      100 |     100 |     100 |                   
  app.config.ts                                    |     100 |      100 |     100 |     100 |                   
 health/indicators/dynamo-health                   |     100 |      100 |     100 |     100 |                   
  dynamo-health.indicator.ts                       |     100 |      100 |     100 |     100 |                   
 reservations/create-reservation                   |   98.43 |      100 |    90.9 |   98.18 |                   
  create-reservation.controller.ts                 |     100 |      100 |     100 |     100 |                   
  create-reservation.dynamo.repository.ts          |     100 |      100 |     100 |     100 |                   
  create-reservation.resolver.ts                   |   92.85 |      100 |   66.66 |   91.66 | 12                
  create-reservation.service.ts                    |     100 |      100 |     100 |     100 |                   
  reservation-model-creator.service.ts             |     100 |      100 |     100 |     100 |                   
 reservations/get-reservations-after-date          |   98.07 |      100 |    90.9 |   97.72 |                   
  get-reservations-after-date.controller.ts        |     100 |      100 |     100 |     100 |                   
  get-reservations-after-date.dynamo.repository.ts |     100 |      100 |     100 |     100 |                   
  get-reservations-after-date.resolver.ts          |    92.3 |      100 |   66.66 |    90.9 | 11                
  get-reservations-after-date.service.ts           |     100 |      100 |     100 |     100 |                   
 reservations/list-reservations                    |   98.07 |      100 |   91.66 |   97.72 |                   
  list-reservations.controller.ts                  |     100 |      100 |     100 |     100 |                   
  list-reservations.dynamo.repository.ts           |     100 |      100 |     100 |     100 |                   
  list-reservations.resolver.ts                    |   92.85 |      100 |      75 |   91.66 | 12                
  list-reservations.service.ts                     |     100 |      100 |     100 |     100 |                   
 reservations/patch-update-reservation             |   99.08 |      100 |   93.33 |   98.95 |                   
  patch-reservation.controller.ts                  |     100 |      100 |     100 |     100 |                   
  reservation-model-updater.service.ts             |     100 |      100 |     100 |     100 |                   
  update-reservation.controller.ts                 |     100 |      100 |     100 |     100 |                   
  update-reservation.dynamo.repository.ts          |     100 |      100 |     100 |     100 |                   
  update-reservation.resolver.ts                   |   92.85 |      100 |   66.66 |   91.66 | 12                
  update-reservation.service.ts                    |     100 |      100 |     100 |     100 |                   
 shared/config                                     |     100 |      100 |     100 |     100 |                   
  aws.config.ts                                    |     100 |      100 |     100 |     100 |                   
 shared/dynamo                                     |     100 |      100 |     100 |     100 |                   
  dynamo-key-generator.service.ts                  |     100 |      100 |     100 |     100 |                   
  dynamo.client.ts                                 |     100 |      100 |     100 |     100 |                   
 shared/entity-identity-generator                  |     100 |      100 |     100 |     100 |                   
  entity-identity-generator.service.ts             |     100 |      100 |     100 |     100 |                   
 shared/pipes                                      |     100 |      100 |     100 |     100 |                   
  parse-date.pipe.ts                               |     100 |      100 |     100 |     100 |                   
---------------------------------------------------|---------|----------|---------|---------|-------------------

Test Suites: 29 passed, 29 total
Tests:       136 passed, 136 total
Snapshots:   0 total
Time:        24.937 s

dependencies from package.json and package-lock.json

            "dependencies": {
                "@nestjs/apollo": "^10.1.7",
                "@nestjs/common": "^9.3.2",
                "@nestjs/config": "^2.3.0",
                "@nestjs/core": "^9.3.1",
                "@nestjs/graphql": "^10.1.7",
                "@nestjs/passport": "^9.0.1",
                "@nestjs/platform-express": "^9.3.2",
                "@nestjs/swagger": "^6.1.4",
                "@nestjs/terminus": "^9.2.0",
                "aws-serverless-express": "^3.4.0",
                "class-transformer": "^0.5.1",
                "class-validator": "^0.14.0",
                "istanbul-lib-instrument": "https://gitpkg.now.sh/marekdedic/istanbuljs/packages/istanbul-lib-instrument?coverage-fix",
                "jwks-rsa": "^3.0.1",
                "nestjs-ddtrace": "^3.0.2",
                "nestjs-pino": "^3.1.2",
                "passport-jwt": "^4.0.1"
            },

part of the package-lock.json

        "node_modules/istanbul-lib-instrument": {
            "version": "5.2.1",
            "resolved": "https://gitpkg.now.sh/marekdedic/istanbuljs/packages/istanbul-lib-instrument?coverage-fix",
            "integrity": "sha512-zhwQzcmbVm4O94/UxHA4l8OYycZYwyY5z2hWdZ/fZoBpC1dFNjj75anOyojcBZ3UsSw1hKck3nLg/Zs4XRDzOw==",
            "license": "BSD-3-Clause",
            "dependencies": {
                "@babel/core": "^7.12.3",
                "@babel/parser": "^7.14.7",
                "@istanbuljs/schema": "^0.1.2",
                "istanbul-lib-coverage": "^3.2.0",
                "semver": "^6.3.0"
            },
            "engines": {
                "node": ">=8"
            }
        },

part of the package-lock.json

        "istanbul-lib-instrument": {
            "version": "https://gitpkg.now.sh/marekdedic/istanbuljs/packages/istanbul-lib-instrument?coverage-fix",
            "integrity": "sha512-zhwQzcmbVm4O94/UxHA4l8OYycZYwyY5z2hWdZ/fZoBpC1dFNjj75anOyojcBZ3UsSw1hKck3nLg/Zs4XRDzOw==",
            "requires": {
                "@babel/core": "^7.12.3",
                "@babel/parser": "^7.14.7",
                "@istanbuljs/schema": "^0.1.2",
                "istanbul-lib-coverage": "^3.2.0",
                "semver": "^6.3.0"
            },
            "dependencies": {
                "semver": {
                    "version": "6.3.0"
                }
            }
        },

@Shereef
Copy link

Shereef commented Feb 7, 2023

This was a full project in my previous message
Here is from the repo I created to replicate this issue:

> graphql-jest-coverage-attribute@0.0.1 test:cov
> jest --coverage

 PASS  src/app.resolver.spec.ts (9.657 s)
  AppResolver
    root
      ✓ should return "Hello World!" (12 ms)

-----------------|---------|----------|---------|---------|-------------------
File             | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-----------------|---------|----------|---------|---------|-------------------
All files        |   85.71 |      100 |      50 |     100 |                   
 app.resolver.ts |   85.71 |      100 |      50 |     100 |                   
-----------------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        10.383 s

Shereef/graphql-jest-coverage-attribute@main...coverage-fix-test

@smk
Copy link

smk commented Feb 17, 2023

I've installed the patched version and can confirm it works, the coverage report line numbers as well as the coverage percentages are working again.

@CasualBot
Copy link

Would like to bump this as fix as it resolves issues I'm facing on a project. Thanks for the hard work to all involved 🥇

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@SimenB
Copy link
Member

SimenB commented Oct 4, 2023

Ergh, actually - should we parse it if it's a string?

@marekdedic
Copy link
Contributor Author

Ergh, actually - should we parse it if it's a string?

I don't know :D I don't know why encoded json is passed as the source map in the first place :D

@SimenB
Copy link
Member

SimenB commented Nov 3, 2023

I think I'd like to see a test added before merging this - anybody up for contributing one?

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

Successfully merging this pull request may close these issues.

None yet

6 participants