Skip to content

test: cover Node-specific paths and namespace matching - #1057

Open
appsir2016-lab wants to merge 1 commit into
debug-js:masterfrom
appsir2016-lab:tests/node-coverage
Open

appsir2016-lab wants to merge 1 commit into
debug-js:masterfrom
appsir2016-lab:tests/node-coverage

Conversation

@appsir2016-lab

Copy link
Copy Markdown

Adds 31 tests to the two existing test files. No source changes, no new dependencies, and the test:node script is unchanged. The tests added to test.js use no Node APIs; the karma suite was run locally with headless Chrome and passes (22 tests, 8 of them new).

Statement coverage of npm run test:node, measured with npx c8 --all --src src --exclude 'test*.js':

File Before After
src/node.js 58.2% 100%
src/index.js 90.0% 100%
src/common.js 94.9% 99.3%
Node-side files together 77.7% 99.7%

What is covered now:

  • The extended palette when supports-color reports level 2+, the basic palette otherwise, and the older module shape without stderr. Four tests intercept Module._load for supports-color so the branch runs regardless of whether the optional module is installed on the machine.
  • DEBUG_* environment parsing and value coercion.
  • useColors() with inspectOpts.colors set and with the TTY fallback.
  • formatArgs: colour prefix, the 256-colour escape, multi-line prefixes, the date prefix and hideDate.
  • The %o and %O formatters, including per-instance inspectOpts and colours passed to util.inspect.
  • save, load, log, per-instance inspectOpts from init, and the deprecated destroy() no-op.
  • The Electron/browser detection in src/index.js.
  • %%, a non-string first argument, Error coercion with and without a stack, wildcard backtracking and trailing wildcards, skip lists, and whitespace-separated namespaces.

Two things noticed while running the suite and left alone here:

  • xo 0.23 crashes on current Node (util.isDate is not a function, from core-assert via eslint-plugin-ava), so npm run lint needs Node 22 or lower, or a newer xo. I ran the linter on the two test files with a local shim restoring the removed util.is* helpers for the linter process only; both files are clean.
  • destroy() in src/common.js is unreachable in the Node build because src/node.js supplies its own, so its two lines stay uncovered.

Checks: npm run test:node passes with 47 tests on Node 26, and npm run test:browser passes with 22 tests in headless Chrome 152.

Adds 31 tests, no source changes. Node-side statement coverage (src/node.js, src/common.js, src/index.js) goes from 77.7% to 99.7%; src/node.js and src/index.js reach 100%.

Covered: the extended colour palette when supports-color reports level 2 or more, DEBUG_* environment parsing and value coercion, useColors TTY fallback, colour and date prefixes in formatArgs, the %o and %O formatters, save/load of process.env.DEBUG, per-instance inspectOpts, the deprecated destroy() no-op, the Electron/browser detection in the entry file, escaped %% sequences, wildcard backtracking and trailing wildcards in namespace matching, skip lists, whitespace-separated namespaces, and Error coercion with and without a stack.

Measured with: npx c8 --all --src src --exclude 'test*.js' npm run test:node

Signed-off-by: P & A Dawn works <appsir2016@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant