4

When my test suite completes, I need to output some stats, i. e. meta info about tests collected during test execution.

I'm trying this:

QUnit.done(() => console.log("some meta info here"))

This works when I run tests in the browser.

But when I run tests in the terminal, the console.log output is not displayed.

There's probably some debug flag, but it will enable all console.log messages and pollute the output greatly.

Instead, I need to output one specific message to the terminal, so that it's logged to CI.

PS console.log messages sent during test execution seem to make it into the terminal successfully.

PPS Using QUnit in an Ember CLI app, against Chrome headless.

Andrey Mikhaylov - lolmaus
  • 23,107
  • 6
  • 84
  • 133
  • 1
    is the done hook called in headless? (like, what if you say process.exit(123) or something? (I actually have no idea if you'd have access to process in whatever scope you're in? – NullVoxPopuli Aug 23 '18 at 09:42
  • 1
    The code is executed in the browser context, I have no access to Node stuff. – Andrey Mikhaylov - lolmaus Aug 23 '18 at 09:49
  • have you tried other log levels? like `console.warn`, `console.debug`? I wouldn't be surprised if log is filtered out of the terminal, cause of how often it's used – NullVoxPopuli Aug 23 '18 at 09:57
  • Yes, no result. The official example uses `console.log`: https://api.qunitjs.com/callbacks/QUnit.done – Andrey Mikhaylov - lolmaus Aug 23 '18 at 10:00
  • what file are you putting the QUnit.done() in? I want to give this a go. – NullVoxPopuli Aug 23 '18 at 10:18
  • 1
    It's an Ember CLI project. The file could be `tests/test-helper.js` for example. – Andrey Mikhaylov - lolmaus Aug 23 '18 at 10:48
  • anything else you can provide? I added the above line to my test-helper.js, but my linter caught this: ` 'QUnit' is not defined. (no-undef)`, so I wonder if QUnit needs to be imported? / maybe it's not global? – NullVoxPopuli Aug 23 '18 at 12:42
  • Can you add a [module `afterEach` hook](https://api.qunitjs.com/QUnit/module) and try to use `console.log` there? Trying to nail down if it's console logs being eaten, or something with the `done()` callback. If you're using Ember (I don't) then maybe you could try using the [Ember.Logger class](https://www.emberjs.com/api/ember/3.0/classes/Ember.Logger/methods/log?anchor=log) instead? – Jordan Kasper Aug 23 '18 at 13:35
  • @NullVoxPopuli QUnit must be imported like this: `import QUnit from 'qunit';`. – Andrey Mikhaylov - lolmaus Aug 23 '18 at 14:18
  • @jakerella, I'm starting to think that it's not an issue of QUnit, but rather of the Testem test runner and its integration with QUnit. As for `Ember.Logger`, it uses `console.log` internally and is deprecated. – Andrey Mikhaylov - lolmaus Aug 23 '18 at 14:19
  • Hmm... there is [this bug filed on their github repo](https://github.com/testem/testem/issues/562), but yeah, I'm pretty sure this is outside QUnit since this works in a raw example. – Jordan Kasper Aug 23 '18 at 15:26
  • That bug relates to the browser mode (with a server), my problem is about plain terminal output mode (no server). – Andrey Mikhaylov - lolmaus Aug 23 '18 at 15:54

1 Answers1

2

This was a tricky one, as I've never had a need to interact with QUnit like, this, but here are my findings each step of the way:

Attempt 1:

enter image description here That's a weird error, I thought I was passing a callback function :-\

Attempt 2:

enter image description here After looking up the documentation for Qunit.log, I could see I was using it wrong. Switching to console.log shows the beginning message -- but not the ending message.

Attempt 3:

enter image description here moduleDone will print something at the end -- but it also prints for every time you use the word module (after everything inside finishes running). So, I guess as a hack if QUnit.done never ends up working, you could keep track of the number of modules started, and modules done, make sure every started modules completes, and if that number is 0 at the end, your test suite is done?

Attempt 4

enter image description here Turns out, this is only actually helpful for if you want to know the outermost module is done, cause it seems like multiple tests don't run in parallel (which is probably better anyway for test stability).

Attempt 5

https://github.com/qunitjs/qunit/issues/1308

It looks like an issue with the testem adapter :(

NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352