jest: Jest Progress bar and live stats not showing up when running in band

🐛 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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 8
  • Comments: 18 (4 by maintainers)

Most upvoted comments

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.

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) 🙁

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