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

console.log inside test makes output after test ending #8664

Closed
zimtsui opened this issue Jul 9, 2019 · 3 comments
Closed

console.log inside test makes output after test ending #8664

zimtsui opened this issue Jul 9, 2019 · 3 comments

Comments

@zimtsui
Copy link

zimtsui commented Jul 9, 2019

🐛 Bug Report

console.log inside test makes output after test ending.

test('test timer', () => {
    console.log(1);
    return new Promise((resolve) => {
        setTimeout(() => {
            console.log(2);
            resolve();
        }, 1000);
    });
});

the actual result:

$ npx jest
  console.log test/test.js:2
    1

 PASS  test/test.js
  ✓ test timer (1018ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.056s
Ran all test suites.
  console.log test/test.js:5
    2

To Reproduce

  1. install jest with every config default.
  2. just run the code above.

Expected behavior

the expected result:

$ npx jest
  console.log test/test.js:2
    1

  console.log test/test.js:5
    2

 PASS  test/test.js
  ✓ test timer (1018ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.056s
Ran all test suites.

Link to repl or repo (highly encouraged)

https://repl.it/repls/LightblueSelfreliantApplicationprogram

Run npx envinfo --preset jest

  System:
    OS: Linux 4.15 Ubuntu 18.04.2 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
  Binaries:
    Node: 10.16.0 - /usr/local/bin/node
    npm: 6.10.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^24.8.0 => 24.8.0 
@lucasfcosta
Copy link
Contributor

This seems to be a duplicate of #4977.

Essentially, the problem description seems the same to me:

console.log inside test makes output after test ending.

This happens because, as per described in #4977:

The last process.stdout.write invocation in an async test is not flushed before Jest's test result summary is written.

@zimtsui
Copy link
Author

zimtsui commented Jul 16, 2019

This seems to be a duplicate of #4977.

Essentially, the problem description seems the same to me:

console.log inside test makes output after test ending.

This happens because, as per described in #4977:

The last process.stdout.write invocation in an async test is not flushed before Jest's test result summary is written.

thank you

@zimtsui zimtsui closed this as completed Jul 16, 2019
@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