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

Code Coverage report stating last closing brace as uncovered #10740

Closed
victormoraesgs opened this issue Oct 30, 2020 · 6 comments
Closed

Code Coverage report stating last closing brace as uncovered #10740

victormoraesgs opened this issue Oct 30, 2020 · 6 comments

Comments

@victormoraesgs
Copy link

🐛 Bug Report

To Reproduce

Steps to reproduce the behavior:
Here is my class:

import { container, inject, injectable } from 'tsyringe';

import AppError from '@shared/errors/AppError';
import ILogger from '@shared/infra/logger/interfaces/ILogger';

import User from '../models/User';
import CheckIfUserExists from './CheckIfUserExistsUseCase';

interface IRequest {
  requestedUserId: string;
  requestingUserId: string;
  requestId: string;
}

@injectable()
class ShowUserUseCase {
  constructor(
    @inject('logger')
    private logger: ILogger
  ) {}

  public async execute({
    requestedUserId,
    requestingUserId,
    requestId,
  }: IRequest): Promise<User> {
    this.logger.log('info', 'Showing a User', {
      requestedUserId,
      requestingUserId,
      requestId,
    });

    const checkIfUserExists = container.resolve(CheckIfUserExists);
    const doesUserExist = await checkIfUserExists.execute({
      id: requestedUserId,
    });

    if (!doesUserExist) {
      this.logger.log('info', 'Requested user does not exist.', {
        requestedUserId,
        requestingUserId,
        requestId,
      });

      throw new AppError('User not found', {}, 404);
    }

    this.logger.log('info', 'User found.', {
      requestedUserId,
      requestingUserId,
      requestId,
    });

    return doesUserExist as User;
  }
}

export default ShowUserUseCase;

Here is the lcov output alongside jest

image

This happens to every single class of mine. As you can see, it is the only factor that makes this particular class not 100% on coverage of statements and lines. Also not sure why branches is not 100% covered here.

Expected behavior

I expected to a closing brace be a covered line of code.

envinfo

  System:
    OS: Linux 4.19 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-4460  CPU @ 3.20GHz
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
  npmPackages:
    jest: 26.6.1 => 26.6.1 
@SimenB
Copy link
Member

SimenB commented Oct 30, 2020

This is an issue either with the transformer not providing correct source maps or with istanbul.

At the very least we'll need a full minimal reproduction we can pull down to run and test. Regardless I highly doubt it's a bug in Jest itself, but I've been surprised before 🙂

@victormoraesgs
Copy link
Author

@SimenB okay! I'll work on the reproduction and get back to you soon. Made some tests here and looks like the problem is when two closing braces are after each other, whithout any characters between them (except for \n), like:

01: class A {
02:     method(){
03:      return;
04:     }
05: }

Line 4 will be marked as uncovered every single time.

@victormoraesgs
Copy link
Author

@SimenB I've managed to reproduce the bug in: https://github.com/VIMGAS/jest-coverage-bug-reproduction

The README.md file states how to make it happen.

@SimenB
Copy link
Member

SimenB commented Nov 1, 2020

@VIMGAS I don't see the same:
image

(same for the other test files)

I'm unsure about the branches stuff - I'm guessing it has something to do with some generated code adding guards that are not hit?

@SimenB
Copy link
Member

SimenB commented Nov 1, 2020

Ah no wait! It works on Node 14 correctly, but with node 12 I get the same result as you do. Probably something to do with babel's transform then. I don't think it's an issue with Jest, tho?

Closing, but if you still think it's a bug in Jest we can reopen

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants