Skip to content

Fix the verbose tests #598

@ehmicky

Description

@ehmicky

The verbose tests are currently randomly failing.

execa/test/verbose.js

Lines 10 to 22 in 5b1a1c7

test('Prints command when "verbose" is true', async t => {
const {stdout, stderr, all} = await execa('nested.js', [JSON.stringify({verbose: true}), 'noop.js', 'test'], {all: true});
t.is(stdout, 'test');
t.is(normalizeTimestamp(stderr), `${testTimestamp} noop.js test`);
t.is(normalizeTimestamp(all), `${testTimestamp} noop.js test\ntest`);
});
test('Prints command with NODE_DEBUG=execa', async t => {
const {stdout, stderr, all} = await execa('nested.js', [JSON.stringify({}), 'noop.js', 'test'], {all: true, env: {NODE_DEBUG: 'execa'}});
t.is(stdout, 'test');
t.is(normalizeTimestamp(stderr), `${testTimestamp} noop.js test`);
t.is(normalizeTimestamp(all), `${testTimestamp} noop.js test\ntest`);
});


  verbose › Prints command when "verbose" is true

  test/verbose.js:14

   13:   t.is(normalizeTimestamp(stderr), `${testTimestamp} noop.js test`);   
   14:   t.is(normalizeTimestamp(all), `${testTimestamp} noop.js test\ntest`);
   15: });                                                                    

  Difference (- actual, + expected):

  - `test␊
  - [00:00:00.000] noop.js test`
  + `[00:00:00.000] noop.js test␊
  + test`

  › file://test/verbose.js:14:4

  verbose › Prints command with NODE_DEBUG=execa

  test/verbose.js:21

   20:   t.is(normalizeTimestamp(stderr), `${testTimestamp} noop.js test`);   
   21:   t.is(normalizeTimestamp(all), `${testTimestamp} noop.js test\ntest`);
   22: });                                                                    

  Difference (- actual, + expected):

  - `test␊
  - [00:00:00.000] noop.js test`
  + `[00:00:00.000] noop.js test␊
  + test`

  › file://test/verbose.js:21:4

This is because the verbose option prints to stderr. When the process prints to stdout, it might be printed first, even if the call to stderr was made before. This is a race condition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions