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

Missing function coverage reporting in class without explicit constructor #7025

Open
simon-kepplinger opened this issue Nov 10, 2023 · 0 comments
Labels
bug Something isn't working bun:test Something related to the `bun test` runner

Comments

@simon-kepplinger
Copy link

What version of Bun is running?

1.0.11

What platform is your computer?

Linux 6.5.6-76060506-generic x86_64 x86_64

What steps can reproduce the bug?

index.ts

export class Test {
  public test(): boolean {
    return true;
  }
}

index.test.ts

import { describe, expect, it } from 'bun:test';
import { Test } from './index.ts';

describe('Test', () => {
  it('should test', () => {
    const actual = new Test().test();
    expect(actual).toBe(true);
  });
});

What is the expected behavior?

I would expect 100% function coverage when running bun test --coverage

-----------|---------|---------|-------------------
File       | % Funcs | % Lines | Uncovered Line #s
-----------|---------|---------|-------------------
All files  |  100.00 |  100.00 |
 index.ts  |  100.00 |  100.00 | 
-----------|---------|---------|-------------------

What do you see instead?

bun test --coverage reports only 50% function coverage

bun test v1.0.11 (f7f6233e)

index.test.ts:
✓ Test > should test [0.07ms]
-----------|---------|---------|-------------------
File       | % Funcs | % Lines | Uncovered Line #s
-----------|---------|---------|-------------------
All files  |   50.00 |  100.00 |
 index.ts  |   50.00 |  100.00 | 
-----------|---------|---------|-------------------

 1 pass
 0 fail
 1 expect() calls
Ran 1 tests across 1 files. [12.00ms]

Additional information

Upon adding an empty constructor to the class, the reported function coverage increased to 100%. This occurred without any modifications to the test case.

export class Test {
  public constructor() {
  }
  
  public test(): boolean {
    return true;
  }
}

bun test --coverage prints

bun test v1.0.11 (f7f6233e)

index.test.ts:
✓ Test > should test [0.06ms]
-----------|---------|---------|-------------------
File       | % Funcs | % Lines | Uncovered Line #s
-----------|---------|---------|-------------------
All files  |  100.00 |  100.00 |
 index.ts  |  100.00 |  100.00 | 
-----------|---------|---------|-------------------

 1 pass
 0 fail
 1 expect() calls
Ran 1 tests across 1 files. [13.00ms]
@simon-kepplinger simon-kepplinger added the bug Something isn't working label Nov 10, 2023
@Electroid Electroid added the bun:test Something related to the `bun test` runner label Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun:test Something related to the `bun test` runner
Projects
None yet
Development

No branches or pull requests

2 participants