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

Jest Progress bar and live stats not showing up when running in band #9420

Closed
jeremygottfried opened this issue Jan 16, 2020 · 18 comments
Closed

Comments

@jeremygottfried
Copy link

🐛 Bug Report

When I run jest, I don't see the green progress bar or any of the live printout data in my terminal.
The Test Suites, Tests, Snapshots, and Time stats are only printed out after all my tests are complete. Until tests are complete, the only indicator I see is:

RUNS path/to/tests

There's no way for me to tell whether the tests have stalled or are still running until the entire suite is complete.

I am running jest with puppeteer for end to end testing.

To Reproduce

  1. Clone the repo here: https://github.com/jeremygottfried/test-jest-cli
  2. Run yarn install
  3. Run yarn test (I set up jest global setup/teardown scripts to handle starting the server)

Test Code

import puppeteer from 'puppeteer';

describe('a basic react app that puppeteer can automate', () => {
  let browser;
  let page;

  beforeAll(async () => {
    browser = await puppeteer.launch({ slowMo: 250 });
    page = await browser.newPage();
  });

  afterAll(async () => {
    await browser.close();
  })

  it('opens the home page', async () => {
    await page.goto('http://localhost:3000');
    expect(await page.url()).toBe('http://localhost:3000/');
  })

  it('has app header', async () => {
    expect(await page.$('.App-header')).not.toBe(null);
  })

  it('has logo', async () => {
    expect(await page.$('img[src="/static/media/logo.5d5d9eef.svg"]')).not.toBe(null);
  })

  it('should have a Learn React link that opens a new page', async () => {
    await page.click('.App-link');
    expect(await page.url()).toBe('https://reactjs.org/')
  })
})

Global Setup Code

import spawnd from 'spawnd';
import cwd from 'cwd';
import http from 'http';

function serverReady() {
  return new Promise(function(resolve) {
    async function checkReady() {
      const req = http.get({
        hostname: 'localhost',
        port: 3000,
        path: '/',
      }, function (res) {
        if (res.statusCode === 200) {
          resolve();
        } else {
          return checkReady();
        }
      });
      req.on('error', function() {
        return checkReady();
      });
    }
    checkReady();
  });
}

export default async function setup() {
  console.log(`\nStarting up react server at port 3000...`);
  const server = spawnd('yarn', ['start'], { shell: true, cwd: cwd() });
  global.server = server;
  await serverReady();
  console.log('\nServer Ready');
}

Expected behavior

I expected my jest tests to show progress bar and live stats printouts like this:

jest expectation

Link to repl or repo (highly encouraged)

https://github.com/jeremygottfried/test-jest-cli

envinfo

  System:
    OS: macOS Mojave 10.14.6
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 13.6.0 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  npmPackages:
    jest: ^24.9.0 => 24.9.0 
$ [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
# => Interactive
shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
# => Login shell
@jeremygottfried jeremygottfried changed the title Has the jest progres bar been Jest Progress bar and live stats not showing up when I run tests Jan 16, 2020
@SimenB
Copy link
Member

SimenB commented Jan 20, 2020

This is due to you having only a single test meaning jest will the test run in band (meaning within the same process as the jest process), in which case we don't show the status bar until tests complete. This is on purpose, see discussion in #1782 and PR #1813. Relevant code is here:

https://github.com/facebook/jest/blob/823677901b9632dbfb9397bf5eef2d32b78527a4/packages/jest-core/src/TestScheduler.ts#L172

However, forcing the flag to be true works correctly for me - the summary is updated as the tests run. It's probably due to your tests being async, so we're able to update, while synchronous tests would lock up the process and we wouldn't be able to update the status.

Not sure what, if anything, to do here. @thymikee @jeysal @cpojer thoughts? If we don't wanna change any code we should probably document it somewhere.


@jeremygottfried in your case you can just add a second test file and the summary will appear

@andreabisello

This comment has been minimized.

@SimenB

This comment has been minimized.

@jeremygottfried
Copy link
Author

jeremygottfried commented Jan 21, 2020

Thanks @SimenB , that worked for showing the live stats and progress bar.

I agree it would be helpful to document what enables the live stats and progress bar. If the time estimate is long for a single test suite, maybe show it by default? My test suite takes around 4 minutes, which is quite a while to see RUNS path/to/my/test and nothing else.

@tinkermakar
Copy link

@SimenB @jeremygottfried sorry, what and where exactly are you setting to true to see the green bar again? I tried creating a second dummy test suit, but it did not help. Also adding --runInBand didn't help as well, although my understanding is I need it disabled, not enabled.

@jeremygottfried
Copy link
Author

@makar2 I think I just added a second test file, and --runInBand at the end of the command.

@tinkermakar
Copy link

@jeremygottfried hmm, still doesn't work for me. Maybe something else as well?

@jeremygottfried
Copy link
Author

Hi @makar2 , are you sure it's not a different issue, like a syntax error? Sometimes things fail silently.

@tinkermakar
Copy link

@jeremygottfried I am positive, tests are otherwise fine

@tinkermakar
Copy link

@SimenB any thoughts?

@julianYaman
Copy link

@jeremygottfried & @makar2 Did you find a solution for this? I also added a second file and the status showed up. My issue is now, that it doesn't count the tests of the file where I have all my async tests like @jeremygottfried.

Could this be caused by using TypeScript and therefore ts-jest and using playwright instead of puppeteer?

@DenizUgur
Copy link

This issue still continues. My project is in TypeScript and therefore I use ts-jest preset. Not sure what can I do at this moment.

versions
"jest": "^28.1.0"
"ts-jest": "^28.0.4"
"typescript": "^4.7.2"

I run my tests like this:

jest --coverage --runInBand --config jest.config.js

jest.config.js

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
	preset: "ts-jest",
	verbose: true,
	testTimeout: 60000,
	detectOpenHandles: true,
	setupFiles: ["dotenv/config"],
	testMatch: ["**/*.e2e*.ts"],
	testEnvironment: "node",
	transform: {
		"^.+\\.(t|j)sx?$": "@swc/jest",
	},
};

@spinlud
Copy link

spinlud commented Aug 23, 2022

Same here, I need --runInBand because the tests are very time sensitive and the parallel execution mess up things. Still unable to find a way to show the progress bar though (or any kind of progress output) 🙁

@doberkofler
Copy link

I'm having the same problem: #10646

@jeysal
Copy link
Contributor

jeysal commented Nov 10, 2022

I don't think this can be done without an unacceptable tradeoff I'm afraid. Running in band means there is only one process and no delegated worker processes. The Jest CLI output is controlled by the same Node VM that is also running your test. So even if we show a progress bar it would be very unreliable because the test might be running synchronous code for many seconds straight, during which we can't update the progress bar. The only way to avoid this issue would be... essentially not running in band, but with one worker. But this would destroy the whole point of running in band, which is to conserve resources (worker spawning CPU overhead, and runtime memory overhead), as well as other benefits it has, like easier debugging without subprocesses.

@jeysal jeysal changed the title Jest Progress bar and live stats not showing up when I run tests Jest Progress bar and live stats not showing up when running in band Nov 10, 2022
@jeysal
Copy link
Contributor

jeysal commented Nov 10, 2022

Because I don't see any new points that have come up since Simen's comment here, I'll close this as it's intended as a good tradeoff. But as mentioned we're open to a documentation PR that clarifies and explains this behavior.

@jeysal jeysal closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2022
@dhritzkiv
Copy link

Stupid question… is there a way to run Jest "in band" with two workers: one worker for running tests sequentially, and another worker handling the progress updates. Sorry if this doesn't make sense –my understanding of the internals is still lacklustre after all these years and I get confused about the behaviours/limitations of --runInBand, maxWorkers, maxConcurrency, etc.

@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 Dec 11, 2022
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

10 participants