Jest: Console buffer not flushed before process exits

Created on 5 May 2019  路  3Comments  路  Source: facebook/jest

馃悰 Bug Report

Because there's no documented way to abort tests if setup in beforeAll fails (#6695), I tried to process.exit(). This works, but it turns out it's impossible to log any errors (which had lead to the setup failing).

To Reproduce

Run this test with or without circus:

beforeAll(() => {
  if ('something failed') {
    const e = 'here is the error message that is not logged';


    console.error('Error:', e);
    process.exit(1);
  }
});

test('your test suite must contain at least one test', () => {
});

Expected behavior

I expect the console.error output to be visible in the terminal. Instead, I see this:

image

Link to repl or repo (highly encouraged)

https://repl.it/repls/JuniorJumboOmnipage

Bug Report Needs Repro Needs Triage

Most helpful comment

This is expected behaviour. You call process.exit, so it exits. Not sure if it makes sense for us to try to do any more work here.

Not sure this answers the original issue. The issue is that, as a developer, I would expect that console.error displays the message to the console before the process exits. Is that not expected behavior?

All 3 comments

This is expected behaviour. You call process.exit, so it exits. Not sure if it makes sense for us to try to do any more work here.

Seems like we might have a bug with failing lifecycle hooks though, need to investigate

This is expected behaviour. You call process.exit, so it exits. Not sure if it makes sense for us to try to do any more work here.

Not sure this answers the original issue. The issue is that, as a developer, I would expect that console.error displays the message to the console before the process exits. Is that not expected behavior?

@brandonchinn178: thanks for reviving this. I'm not super familiar with Node buffering and internals, but it seems there's generally a problem with logging anything before process.exit(). See for example this bug in Winston and this one in the Bristol logger.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gustavjf picture gustavjf  路  3Comments

kentor picture kentor  路  3Comments

StephanBijzitter picture StephanBijzitter  路  3Comments

withinboredom picture withinboredom  路  3Comments

ianp picture ianp  路  3Comments