tape-testing / tape

tap-producing test harness for node and browsers
MIT License
5.77k stars 307 forks source link

t.comment adds multiple new lines for multi-line strings #570

Closed EarthyOrange closed 2 years ago

EarthyOrange commented 2 years ago

Given below code:

test('test #1', (t) => {
  t.comment(
    dedent(`
      When:
       - Condition 1
       - Condition 2
    `),
  );
  // Setup Code

  t.comment('Then:');
  // Assertions
  t.end();
});

Current Output

test #1

When:

  - Condition 1

  - Condition 2

Then:
  ✓ Assertion

Expected Output

test #1

When:
  - Condition 1
  - Condition 2

Then:
  ✓ Assertion

Why is an extra new line inserted between every line of a multi-line comment? Can the excessive new line insertion be reduced?

https://github.com/substack/tape/blob/master/lib/test.js#L165

ljharb commented 2 years ago

TAP comments are meant to only be one line. It seems like a bug that it keeps the newlines at all, tbh.

EarthyOrange commented 2 years ago

The multi-line comment is useful. Can just the excess new-lines be removed?

ljharb commented 2 years ago

It would break TAP formatters - the whole point of tape is that it produces TAP-compliant output.

EarthyOrange commented 2 years ago

The current implementation is still compliant with the TAP protocol's requirement of a comment being a single line. If a multi-line comment is being detected then each line is being emitted separately as a comment.

ljharb commented 2 years ago

ah yes, you're right, we do have tests covering multiline comments. Your "current output" confused me because it omits the leading # :-)

What happens if you try:

t.comment(
    dedent(`
      When:
       - Condition 1
       - Condition 2`),
  );

in other words, remove the extra trailing newline from your string input.

EarthyOrange commented 2 years ago

I still get the Current Output mentioned in the issue description.

ljharb commented 2 years ago

That's not what I see - with this file:

var test = require('tape');
var dedent = require('dedent');

test('test #1', (t) => {
  t.comment(
    dedent(`
      When:
       - Condition 1
       - Condition 2
    `),
  );
  // Setup Code

  t.comment('Then:');
  // Assertions
  t.end();
});

whether run through node or tape, I get this output:

TAP version 13
# test #1
# When:
# - Condition 1
# - Condition 2
# Then:

1..0
# tests 0
# pass  0

# ok

Are you sure there's not something about your shell environment affecting the output? Are you perhaps using zsh and setopt has a bunch of options in it?

EarthyOrange commented 2 years ago

I am using the tap-difflet module to pretty print the results. Maybe it is printing the comments with extra new lines. I will look in to that.

ljharb commented 2 years ago

Ah, that's almost certainly the case - and explains why your "current output" is missing the leading # marks.

I'll close this for now, but will be happy to reopen if there's something actionable for tape.