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]: Default reporter shows duplicated test results when using projects #15320

Open
MattLishmanYara opened this issue Sep 24, 2024 · 0 comments

Comments

@MattLishmanYara
Copy link

MattLishmanYara commented Sep 24, 2024

Version

29.7.0

Steps to reproduce

  1. Clone the repo https://github.com/MattLishmanYara/jest-double-test-report-problem
  2. Run npm install
  3. Run npm run test:projects - Shows double the tests while running
  4. Run npm run test - Shows the correct number of tests while running

Note: If it is not possible to see the incorrect numbers because it clears the console too quickly, the Jest reporter can be edited.

Open node_modules/@jest/reporters/build/DefaultReporter.js
Edit the constructor to no longer clear the console:

this._status.onChange(() => {
  // this.__clearStatus();
  this.__printStatus();
});

Expected behaviour

While the tests are running, it should count each completed test up to the final result of 50.

(With clear console disabled)
image

Actual behaviour

While the tests are running, tests from the broken.test.js are duplicated in the test output until the final output.

(With clear console disabled)
image

Additional context

This issue only occurs when using Jest projects.
When using Jest without projects, the numbers are correct.

I have tried with and without TypeScipt, and the issue occurs with both.

In the minimal example, this issue only flashes the wrong test numbers for a second or 2. In larger repositories with more slower-running tests, the number of incorrect tests increases.

The issue does not happen when the duplicated tests are replaced with a for loop instead of having multiple tests in the describe.

// No duplication

describe('Broken test suite', () => {
    for (let i = 1; i <= 20; i++) {
        it(`should pass ${i}`, async () => {
            expect(true).toBe(true);
        });
    }
});
// Duplication

describe('Broken test suite', () => {
    it('should pass 1', () => {
        expect(1).toBe(1);
    });
    it('should pass 2', () => {
        expect(1).toBe(1);
    });
    it('should pass 3', () => {
        expect(1).toBe(1);
    });
    it('should pass 4', () => {
        expect(1).toBe(1);
    });
// ...

Environment

System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M2 Max
  Binaries:
    Node: 20.15.0 - ~/.nvm/versions/node/v20.15.0/bin/node
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.0/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant