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

pta reports PASS 0 before passing Zora tests finish running #188

Closed
coolaj86 opened this issue Jul 25, 2023 · 7 comments
Closed

pta reports PASS 0 before passing Zora tests finish running #188

coolaj86 opened this issue Jul 25, 2023 · 7 comments

Comments

@coolaj86
Copy link

I'm a little confused because this outputs PASS: 0 before Zora finishes running the very first test (which passes with 2 tests).

What did I do wrong?

> [email protected] test
> npx -p [email protected] -- pta 'tests/**/*.js'


  TOTAL:  0
   PASS:  0
   FAIL:  0
   SKIP:  0

TAP version 13
# inputs sort correctly
ok 1 - inputs are sorted as expected
# outputs sort correctly
ok 2 - outputs are sorted as expected

1..2
# tests 2
# pass  2
# fail  0
# skip  0
@coolaj86
Copy link
Author

I meant to post this as a pta issue.

@coolaj86 coolaj86 changed the title Reports PASS 0 when Zora tests pass pta reports PASS 0 before passing Zora tests finish running Jul 25, 2023
@lorenzofox3
Copy link
Owner

Thanks for the report. Do you have the same problem if you install pta on your machine and run it directrly (without npx) ?

@coolaj86
Copy link
Author

coolaj86 commented Jul 26, 2023

There's no difference between the two:
makes no difference whether I run npx -p pta@1 -- pta './tests/**/*.js' or pta './tests/**/*.js'.

Versions

node --version
v20.4.0

uname -srm
Darwin 22.5.0 arm64

"zora": "^5.2.0"

pta --version
(error, but it's 1.2 or so)

Install pta

# to prevent from mistakenly polluting the `package.json`:
pushd /tmp/
npm install --location=global pta@1
popd

Install Zora

npm install --save-dev zora@5

Bogo tests

./tests/test.js:

"use strict";

let Zora = require("zora");

Zora.test("sync:pass", function (t) {
  t.ok(true);
});

Zora.test("sync:fail", function (t) {
  t.ok(false);
});

Zora.test("sync:timeout", function () {
  // do nothing
});

Zora.test("async:pass", async function (t) {
  await sleep(50);
  t.ok(true);
});

Zora.test("async:fail", async function (t) {
  await sleep(50);
  t.ok(false);
});

Zora.test("async:timeout", async function () {
  await sleep(50);
  // do nothing
});

Zora.test("cb:pass", function (t) {
  let p = sleep(50).then(function () {
    t.ok(true);
  });
  return p;
});

Zora.test("cb:fail", function (t) {
  let p = sleep(50).then(function () {
    t.ok(false);
  });
  return p;
});

Zora.test("cb:timeout", function () {
  let p = sleep(50).then(function () {
    // do nothing
  });
  return p;
});

async function sleep(ms) {
  return await new Promise(function (resolve) {
    setTimeout(resolve, ms);
  });
}

Run tests

npm ci
pta 'tests/**/*.js'

Result


  TOTAL:  0
   PASS:  0
   FAIL:  0
   SKIP:  0

TAP version 13
# sync:pass
ok 1 - should be truthy
# sync:fail
not ok 2 - should be truthy
  ---
    actual: false
    expected: "truthy value"
    operator: "ok"
    at: " /private/tmp/base58check.js/tests/test.js:10:5"
  ...
# sync:timeout
# async:pass
ok 3 - should be truthy
# async:fail
not ok 4 - should be truthy
  ---
    actual: false
    expected: "truthy value"
    operator: "ok"
    at: " /private/tmp/base58check.js/tests/test.js:24:5"
  ...
# async:timeout
# cb:pass
ok 5 - should be truthy
# cb:fail
not ok 6 - should be truthy
  ---
    actual: false
    expected: "truthy value"
    operator: "ok"
    at: " /private/tmp/base58check.js/tests/test.js:41:7"
  ...
# cb:timeout

1..6
# tests 6
# pass  3
# fail  3
# skip  0

@coolaj86
Copy link
Author

Also note that zora sums the number of tests incorrectly:

# tests 6
# pass  3
# fail  3
# skip  0

There were 9 tests. 3 should have passed and 6 should have failed (3 timeouts).

@lorenzofox3
Copy link
Owner

Also note that zora sums the number of tests incorrectly:

# tests 6
# pass  3
# fail  3
# skip  0

There were 9 tests. 3 should have passed and 6 should have failed (3 timeouts).

Note quite. In TAP protocol, a "test" is actually an assertion. Your timeout cases have no assertion.

There is indeed a timeout check but it is by default 5s not 50ms. You can overwrite that value by test, or globally with an env variable (or with a command line option when using pta). see documentation

@lorenzofox3
Copy link
Owner

lorenzofox3 commented Jul 27, 2023

There's no difference between the two:
makes no difference whether I run npx -p pta@1 -- pta './tests//*.js' or pta './tests//*.js'.

I see the problem. Pta imports zora singleton to hold its reporting and load the spec files. With your setups it loads zora from a different file and therefore "hold" a different singleton (because we need a file for commonjs, es, etc..).

You can either install pta locally to your project or as you use commonjs, get the same result with basic bash command in your npm script:

ZORA_REPORTER=json node -r **/*.test.js | zr

where "zr" is zora reporter you can install npm install -g zora-reporters

@coolaj86
Copy link
Author

coolaj86 commented Sep 25, 2024

Good news!

node --experimental-require-module

In another release or two it will no longer be necessary to do import and transpile gymnastics!

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

2 participants