Skip to content

npm test fails when colours are enabled #1228

Open

Description

@richardlau

Running npm test (with Node.js 26.12.1) in a terminal on Linux x64 is failing due to ANSI escapes in the output (i.e. colours are enabled).

✖ failing tests:

test at test/unit/ci_preflight_cli.test.js:190:3
✖ prints only the number of unfinished and queued PR jobs (316.653064ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  actual expected

  '\x1B[33m3\x1B[39m\n'

      at TestContext.<anonymous> (file:///home/local/rlau/sandbox/github/node-core-utils/test/unit/ci_preflight_cli.test.js:205:12)
      at Test.runInAsyncScope (node:async_hooks:226:14)
      at Test.run (node:internal/test_runner/test:1402:25)
      at Test.start (node:internal/test_runner/test:1262:17)
      at node:internal/test_runner/test:1903:71
      at node:internal/per_context/primordials:505:82
      at new Promise (<anonymous>)
      at new SafePromise (node:internal/per_context/primordials:479:3)
      at node:internal/per_context/primordials:505:9
      at Array.map (<anonymous>) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: '\x1B[33m3\x1B[39m\n',
    expected: '3\n',
    operator: 'strictEqual',
    diff: 'simple'
  }

test at test/unit/ci_preflight_cli.test.js:209:3
✖ includes running PR builds when the waiting queue is empty (309.199536ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  actual expected

  '\x1B[33m20\x1B[39m\n'

      at TestContext.<anonymous> (file:///home/local/rlau/sandbox/github/node-core-utils/test/unit/ci_preflight_cli.test.js:217:12)
      at Test.runInAsyncScope (node:async_hooks:226:14)
      at Test.run (node:internal/test_runner/test:1402:25)
      at Suite.processPendingSubtests (node:internal/test_runner/test:974:18)
      at Test.postRun (node:internal/test_runner/test:1542:19)
      at Test.run (node:internal/test_runner/test:1467:12)
      at async Promise.all (index 0)
      at async Suite.run (node:internal/test_runner/test:1905:7)
      at async Test.processPendingSubtests (node:internal/test_runner/test:974:7) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: '\x1B[33m20\x1B[39m\n',
    expected: '20\n',
    operator: 'strictEqual',
    diff: 'simple'
  }

test at test/unit/ci_preflight_cli.test.js:222:3
✖ combines queued and working PR builds without double counting transitions (315.872432ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  actual expected

  '\x1B[33m4\x1B[39m\n'

      at TestContext.<anonymous> (file:///home/local/rlau/sandbox/github/node-core-utils/test/unit/ci_preflight_cli.test.js:242:12)
      at Test.runInAsyncScope (node:async_hooks:226:14)
      at Test.run (node:internal/test_runner/test:1402:25)
      at Suite.processPendingSubtests (node:internal/test_runner/test:974:18)
      at Test.postRun (node:internal/test_runner/test:1542:19)
      at Test.run (node:internal/test_runner/test:1467:12)
      at async Suite.processPendingSubtests (node:internal/test_runner/test:974:7) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: '\x1B[33m4\x1B[39m\n',
    expected: '4\n',
    operator: 'strictEqual',
    diff: 'simple'
  }

test at test/unit/ci_preflight_cli.test.js:247:5
✖ prints zero for a valid queue with no PR jobs: [] (315.205079ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  actual expected

  '\x1B[33m0\x1B[39m\n'

      at TestContext.<anonymous> (file:///home/local/rlau/sandbox/github/node-core-utils/test/unit/ci_preflight_cli.test.js:250:14)
      at Test.runInAsyncScope (node:async_hooks:226:14)
      at Test.run (node:internal/test_runner/test:1402:25)
      at Suite.processPendingSubtests (node:internal/test_runner/test:974:18)
      at Test.postRun (node:internal/test_runner/test:1542:19)
      at Test.run (node:internal/test_runner/test:1467:12)
      at async Suite.processPendingSubtests (node:internal/test_runner/test:974:7) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: '\x1B[33m0\x1B[39m\n',
    expected: '0\n',
    operator: 'strictEqual',
    diff: 'simple'
  }

test at test/unit/ci_preflight_cli.test.js:247:5
✖ prints zero for a valid queue with no PR jobs: [{"task":{"url":"https://ci.nodejs.org/job/node-test-commit/"}}] (309.745672ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  actual expected

  '\x1B[33m0\x1B[39m\n'

      at TestContext.<anonymous> (file:///home/local/rlau/sandbox/github/node-core-utils/test/unit/ci_preflight_cli.test.js:250:14)
      at Test.runInAsyncScope (node:async_hooks:226:14)
      at Test.run (node:internal/test_runner/test:1402:25)
      at Suite.processPendingSubtests (node:internal/test_runner/test:974:18)
      at Test.postRun (node:internal/test_runner/test:1542:19)
      at Test.run (node:internal/test_runner/test:1467:12)
      at async Suite.processPendingSubtests (node:internal/test_runner/test:974:7) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: '\x1B[33m0\x1B[39m\n',
    expected: '0\n',
    operator: 'strictEqual',
    diff: 'simple'
  }

Tests pass if run with colours disabled, e.g.

NODE_DISABLE_COLORS=1 npm test

Activity

  1. Sagar07Kr commented on Oct 29, 2026

    @Sagar07Kr

    I looked into this. The failing test is test/unit/ci_preflight_cli.test.js, and the cause is in bin/ncu-ci.js line 626: console.log(await getPRWorkload(request)). That value is a number, and console.log formats numbers with util.inspect, which colours them yellow when colours are forced. So stdout becomes \x1b[33m3\x1b[39m\n instead of 3\n.

    Printing it as a string instead should fix it without changing the normal output.

    Could you please assign this issue to me?

  2. richardlau commented on Oct 29, 2026

    @richardlau
    MemberAuthor

    We don't assign issues, but please open a pull request if you have something to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions