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

QUnit tests must be async #4

Open
jakerella opened this issue Jan 22, 2018 · 0 comments
Open

QUnit tests must be async #4

jakerella opened this issue Jan 22, 2018 · 0 comments

Comments

@jakerella
Copy link

Hi! Really appreciate the script, works well so far, except that it appears all tests must be async. I used a (nearly) empty QUnit html harness (just the required scripts/elements) and a single test (see below). The harness times out with a synchronous test, but works as expected with an async test. Any ideas why or how to fix? If not, it would be good to document this restriction in the readme.

Synchronous Test file:

QUnit.test('sanity', function(assert) {
    assert.ok(true);
});

Output:

$ node qunit-puppeteer.js http://127.0.0.1:3000/test/index.html 2000
[object Object]
[object Object]
Tests timed out

Asynchronous test file:

QUnit.test('sanity', function(assert) {
    let done = assert.async();
    assert.ok(true);
    done();
});

Output:

[object Object]
.

Time: 61ms, Total: 1, Passed: 1, Failed: 0

qunit-puppeteer version: 1.0.1
Node version: 8.9.4
QUnit version: 2.5.0


As a side note, the [object Object] output is because the console passthrough is receiving an object, not text. The fix is easy, I'll submit a PR, but essentially change the console attachment to:

await page.on('console', (...params) => {
  for (let i = 0; i < params.length; ++i) {
    console.log(`${(typeof(params[i]) === 'object') ? params[i]._text : params[i]}`);
  }
});

The [object Object] output in the successful, async test using this new format results in: Running: {}

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

No branches or pull requests

1 participant