Question presented to candidate: "A small internal service needs tests, but you're hesitant to add Jest or Mocha as dependencies just for that. Is there a real alternative that ships with Node itself, and is it actually production-capable or just a toy?"
What a strong answer should cover:
node:testis a built-in test runner, stable since Node 20 — genuinely nonpm installrequired at all to write and run real tests, directly answering the prompt's core concern.- 📌 Verified, not assumed: a real
.test.jsfile, run withnode --testand zero dependencies installed, genuinely reported 1 pass, 1 fail — the deliberately failing test produced a realAssertionErrorwith an actual diff (5 !== 999), and the overall process genuinely exited with a real non-zero (1) exit code — directly usable as a real CI pass/fail gate, not merely a toy demonstration. - The core API shape is genuinely familiar to anyone who has used Jest or Mocha:
test(),describe(),assert(Node's own built-innode:assert/strict, or a custom assertion library if preferred), async test support,before/afterhooks — the same conceptual shape, not a fundamentally different testing philosophy to learn. - 📌 Verified, not assumed:
node:testalso ships built-in mocking (mock.fn,t.mock.timers,t.mock.method) with no separate library needed — real, directly demonstrated in this bank's dedicated mocking question, including genuinely fast-forwarding a real 10-second timer without any real waiting. - The honest, precise scope:
node:testgenuinely covers the core testing needs (assertions, mocking, async, hooks, a real CI-usable exit code, built-in code coverage via--experimental-test-coverage) — but Jest specifically still leads in some areas not built intonode:testat all, most notably snapshot testing and a mature ecosystem of framework-specific integrations (React Testing Library's Jest-specific matchers, for instance) — a precise answer names this gap rather than claiming feature parity.
Clarifying questions expected:
- "Does this project need snapshot testing, or framework-specific test matchers that assume Jest specifically?" — the most concrete gap where
node:testgenuinely doesn't yet match Jest's ecosystem. - "Is minimizing dependencies (the prompt's stated concern) a hard requirement, or just a mild preference that a well-justified Jest/Mocha addition could still satisfy?" — shapes how much weight the zero-install benefit should actually carry.
Code / implementation expected: Yes — a real node --test run showing a genuine pass, a genuine failure with a real diff, and a real CI-relevant exit code is the concrete, convincing proof that this is production-capable, not a toy.