Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the two trailing line breaks from the console output #18

Open
prantlf opened this issue Feb 11, 2021 · 2 comments · May be fixed by #19
Open

Remove the two trailing line breaks from the console output #18

prantlf opened this issue Feb 11, 2021 · 2 comments · May be fixed by #19

Comments

@prantlf
Copy link

prantlf commented Feb 11, 2021

Why did you add the two trailing line breaks? They add an unnecessary white space to the log from a complete build & test phases. For example:

$ node test
test • • ✓ 2


$

If you have multiple test suites, it gets worse:

$ node test
test1 • • ✓ 2


test2 • • ✓ 2


$

How about removing the two line breaks to achieve the following output?

$ node test
test • • ✓ 2
$

$ node test
test1 • • ✓ 2
test2 • • ✓ 2
$
@prantlf
Copy link
Author

prantlf commented Feb 11, 2021

I noticed to other formatting issues. This is an example of a failed test:

$ node test
test

! test1

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:


  assert.ok(false)

    at Object.fn (/Users/ferdipr/Sources/github/baretest/test/index.js:7:10)
    at Function.self.run (/Users/ferdipr/Sources/github/baretest/baretest.js:30:20)
    at /Users/ferdipr/Sources/github/baretest/test/index.js:16:14
    at Object.<anonymous> (/Users/ferdipr/Sources/github/baretest/test/index.js:17:3)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47$

Notice that there are two empty lines after the line starting with "AssertionError". Also, notice that the next terminal prompt does not start on a new line, but right after the last character of the stack trace.

How about removing the one empty line after the error message and introducing a line break after a failed test? The output would look like this:

$ node test
test

! test1

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(false)

    at Object.fn (/Users/ferdipr/Sources/github/baretest/test/index.js:7:10)
    at Function.self.run (/Users/ferdipr/Sources/github/baretest/baretest.js:30:20)
    at /Users/ferdipr/Sources/github/baretest/test/index.js:16:14
    at Object.<anonymous> (/Users/ferdipr/Sources/github/baretest/test/index.js:17:3)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47
$

@prantlf
Copy link
Author

prantlf commented Feb 11, 2021

Real-world examples with #17 and #19 merged:

A failure:

# node test
attr • • • • • • ✓ 6
dasherize • • • ✓ 3
empty •

! removes all children

AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

'' !== '1'

    at Object.fn (/Users/ferdipr/Sources/github/bacom/test/empty.test.js:16:10)
    at Function.self.run (/Users/ferdipr/Sources/github/baretest/baretest.js:30:20)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async /Users/ferdipr/Sources/github/bacom/test/index.js:11:10
render • • ✓ 2
$ echo $?
1

A success:

$ node test
attr • • • • • • ✓ 6
dasherize • • • ✓ 3
empty • • ✓ 2
render • • ✓ 2
$ echo $?
0

And how ugly was the test suite to get rid of the two empty lines and introduce a line break after a failure:

const tests = [
  require('./attr.test'),
  require('./dasherize.test'),
  require('./empty.test'),
  require('./render.test')
];

(async () => {
  console.info = () => {} // avoid line breaks between suites
  for (const test of tests) {
    if (!await test.run()) console.log() // avoid continuing on the same line
  }
})()

And how better it looks with the changes referred to above:

const tests = [
  require('./attr.test'),
  require('./dasherize.test'),
  require('./empty.test'),
  require('./render.test')
];

(async () => {
  for (const test of tests) await test.run()
})()

Or even shortened to this:

(async () => {
  await require('./attr.test').run()
  await require('./dasherize.test').run()
  await require('./empty.test').run()
  await require('./render.test').run()
})()

Not mentioning the need to repeat the workaround in each test fixture, which can be executed alone:

if (module === require.main) {
  console.info = () => {} // avoid line breaks between suites
  if (!await test.run()) console.log() // avoid continueing on the same line
} else {
  module.exports = test
}

With the mentioned changes merged the fixtures include only two lines:

if (module === require.main) test.run()
else module.exports = test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant