node icon indicating copy to clipboard operation
node copied to clipboard

test: update tap reporter version to 14

Open anonrig opened this issue 2 years ago • 17 comments

Fixes https://github.com/nodejs/node/issues/44040 according to TAP specification available on http://testanything.org/tap-version-14-specification.html

Example test:

const test = require('node:test');
const assert = require('node:assert');

test('top-level test 1', async (t) => {
  await t.test('level 1.1', () => {});
});

test('top-level test 2', () => {});

Produced output:

TAP version 14
# Subtest: top-level test 1
    ok 1 - level 1.1
      ---
      duration_ms: 0.001925209
      ...
    1..1
ok 1 - top-level test 1
  ---
  duration_ms: 0.002924375
  ...
ok 2 - top-level test 2
  ---
  duration_ms: 0.000044334
  ...
1..2
# tests 2
# pass 2
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 0.031293292

anonrig avatar Jul 29 '22 13:07 anonrig

How well does this play with tap parsers such as https://www.npmjs.com/package/tap-mocha-reporter ? It was originally introduced since tap parsers did not relate to nested tests as nested See https://github.com/nodejs/node/pull/43417

MoLow avatar Jul 29 '22 13:07 MoLow

Thanks for the question @MoLow. Here's the output using tap-mocha-reporter

➜  node git:(fix/tap-v14) ✗ ./out/Release/node ./tap-test.js | tap-mocha-reporter spec
(node:66047) ExperimentalWarning: The test runner is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

top-level test 1
  ✓ level 1.1
  ✓ top-level test 2

  2 passing (5ms)

anonrig avatar Jul 29 '22 13:07 anonrig

@MoLow here is a screenshot comparing all 3 scenarios:

  1. current output (https://github.com/nodejs/node/issues/44040)
  2. node-tap
  3. changes from this PR

I think we are good! WDYT?

image

manekinekko avatar Jul 29 '22 14:07 manekinekko

@MoLow here is a screenshot comparing all 3 scenarios:

  1. current output (test_runner: update output TAP format to follow TAP 14 specs #44040)
  2. node-tap
  3. changes from this PR

I think we are good! WDYT?

image

Well only the first example looks correct to me. Top level test 2 should not be under top level test 1, or am I missing anything?

MoLow avatar Jul 29 '22 14:07 MoLow

@anonrig specs 14 state that subtests need to be terminated by a test point.

TAP version 14
# Subtest: subtest name      <<< start of subtest
     ...
ok 1 - subtest name          <<< end of subtest (could be ok or not ok)

manekinekko avatar Jul 29 '22 14:07 manekinekko

Actually this is related to Tap 14 and how tap-mocha-reporter does not handle tap 14 grammar correctly. If we want to support tap 14 we need to ignore this, since it is not backward compatible according to the specification

Since TAP13 specifies that non-TAP output should be ignored or provided directly to the user, and indented Test Points and Plans are non-TAP according to TAP13, only the terminating correlated test point will be interpreted by most TAP13 Harnesses. Thus, they will usually report the overall subtest result correctly, even if they lack the details about the results of the subtest

anonrig avatar Jul 29 '22 14:07 anonrig

Thanks for investigating this @anonrig! I agree we should ignore the mocha report case (unless there is a requirement I am not aware of).

@MoLow the upcoming built-in TAP parser (#43525) is built on top of TAP 14. In most cases, TAP 14 is backward compatible with TAP13. I suggest we focus on TAP 14 and then later add TAP 13 specifics (if needed).

manekinekko avatar Jul 29 '22 14:07 manekinekko

/cc @nodejs/test_runner

aduh95 avatar Jul 29 '22 19:07 aduh95

@manekinekko can the built-in parser support both TAP 13 and TAP 14? I think until we have a built-in solution for human-readable output, we should try and support the human-readable use case with ecosystem packages such as tap-mocha-reporter work

MoLow avatar Jul 30 '22 19:07 MoLow

I guess the answer is yes. The parser will need to implement both strategies. The current implementation will need some major refactoring but it's manageable.

However, the current TAP 14 support is not 100% complete. I'd say we are 95%. Local pragmas support needs some twerking. Diagnostic data is parsed as raw data (not yaml).

manekinekko avatar Jul 31 '22 16:07 manekinekko

Local pragmas support needs some twerking.

Sorry for this unproductive comment, but I hope you meant to say tweaking 😄

cjihrig avatar Jul 31 '22 20:07 cjihrig

Should we produce different tap output according to different flags? What is the best alternative for producing 2 (or more) different tap versions for the test runner?

anonrig avatar Jul 31 '22 21:07 anonrig

Local pragmas support needs some twerking.

Sorry for this unproductive comment, but I hope you meant to say tweaking 😄

OMG!! Sorry about the typo. I definitely meant "tweaking" 😂

manekinekko avatar Aug 02 '22 08:08 manekinekko

Should we produce different tap output according to different flags? What is the best alternative for producing 2 (or more) different tap versions for the test runner?

According to specs, TAP 14 must be backwards compatible with TAP 13.

manekinekko avatar Aug 02 '22 08:08 manekinekko

I reverted my subtest print changes and just left the tap version print change and updated the tests. If there are any other changes required, I'll be happy to resolve @manekinekko

anonrig avatar Aug 02 '22 12:08 anonrig

@anonrig it seems some tests are broken now, would you mind checking it?

ErickWendel avatar Aug 08 '22 18:08 ErickWendel

Updated the last commit and forced pushed with the unhandled test case pointing to version 13. @ErickWendel

anonrig avatar Aug 08 '22 19:08 anonrig

@manekinekko apologies for the OTT - how are you getting tap-mocha-reporter working with the node test runner output?

mattfysh avatar Nov 26 '22 06:11 mattfysh