1

Node.js Test-runner / TAP Protocol

So I really like the idea of Node.js using its own test-runner, and I like the idea of it using the Tap protocol. The only issue I have, is sometimes while developing my tests (using Mocha &/or Jest) I like to view the actual and expected, even when all test have passed, IDK about other people, but there has been more than one occassion where I was getting false positives, which ends up causing me a headache, as I continue with my work, just to figure out that I am working on a system that is flawed (at this point I get angry delete everything to a practical point in my tests) and have to re write a bunch of code. To avoid this pit-fall, I have learned to read test results

"Actual" & "Expected" values as a way of verifying that the tests are in fact passing for all the right reasons (constrained by the arguments that I intended them to be at any given moment in the test).

Let me say this while I am thinking it: "Jest & Mocha are overly verbose" On the other hand, the tap protocol seems to be, "not verbose enough"

I would like to have control over what tests print when they are sucessfull. To be more specific, I would like to be able to print the ACTUAL/EXPECTED values of a test even when its successful (not all, just the ones I specify)...

Does the tap protocol define (or allow) the printing of Actual/expected values for successful tests? &/or is it possible to specify certain tests to print their actual/expected results, even when the test is successful, using the "Node test-runner" API?

JΛYDΞV
  • 8,532
  • 3
  • 51
  • 77
  • _"does the tap protocol define a way for printing tests that succeeded"_. In the first output example on the TAP webpage, it's showing both "ok" and "not ok" cases, so the answer seems to be "yes, it does". – robertklep Aug 11 '22 at 17:23
  • It shows it printing successful tests when another test has failed, but not when all tests have succeeded. To be clear, I assume it does, but I couldn't find out how to do. I was hopping someone would know a bit about this topic, and could explain how to force print the results of a test, even if no tests around it fail. – JΛYDΞV Aug 14 '22 at 04:05
  • "I want some tests to print every time I execute my test suite, regardless if they failed or succeeded". [For me they do](https://gist.github.com/robertklep/b9d31ed844b464e330b02d5c2800347e). But they don't print expected & actual values in case of success (at least not with `assert`), which I think is your actual question? – robertklep Aug 14 '22 at 05:43
  • Yea, I needed to edit the question, it wasn't exactly clear. Great interpretation skills on your part though. That is exactly what I am asking. – JΛYDΞV Aug 14 '22 at 17:19

1 Answers1

0

I had similar question, so TAP specification generally shows how subtests should be printed

and after a little research I found this article

now I checked the latest lts version (v18.14.1) of node at 2023-02-21 and I wrote a dummy test.

import { describe, it } from 'node:test';
import * as assert from 'assert';

describe(`As a User`, () => {
  it(`should send a message to receiver`, () => {
    assert.deepEqual({ a: { b: { c: 'abc' } } }, { a: { b: { c: 'abc' } } });
  });
});

I used ts-node to run it

> node -v && node --require ts-node/register --test communication.test.ts

v18.14.1
TAP version 13
# Subtest: /Users/user/projects/communication.test.ts
    # Subtest: As a User
        # Subtest: should send a message to receiver
        ok 1 - should send a message to receiver
          ---
          duration_ms: 0.465333
          ...
        1..1
    ok 1 - As a User
      ---
      duration_ms: 1.365375
      ...
    1..1
ok 1 - /Users/user/projects/communication.test.ts
  ---
  duration_ms: 404.991583
  ...
1..1
# tests 1
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 405.751958

So try the latest lts node or if you don't care about the future try a custom test reporter which may give you a better control on the output which is available since v19.6.0