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

Global failure: Trying to do a test run with zero assertions fails #1405

Closed
jayjayjpg opened this issue Sep 4, 2019 · 4 comments
Closed
Assignees
Labels
Component: Core For module, test, hooks, and runner. help welcome Type: Bug

Comments

@jayjayjpg
Copy link
Contributor

jayjayjpg commented Sep 4, 2019

Tell us about your runtime:

  • QUnit version: 2.7.1
  • What environment are you running QUnit in? (e.g., browser, Node): Both happening in browser and Node env. Browser: Chrome Version 77.0.3865.56, Node v10.5
  • How are you running QUnit? (e.g., script, testem, Grunt): Ember QUnit / testem, Node v10.5.0

What are you trying to do?

I try to run a test set, e.g. a filtered test set using the --filter of the QUnit CLI, that contains zero assertions. Each test case that contains zero assertions is marked as such using assert.expect(0).

Why are you trying to do this?

Sometimes I want to write tests which use another assertion library, making the use of QUnit's assert obsolete. This might make filtered test runs using --filter or --module impossible for certain test sets.

Code that reproduces the problem:

Please check out the minimal reproduction of the issue here.

When in the reproduction repository, only running

qunit

will run both test files in the test directory. You should see that the test run passes:

Screenshot 2019-09-04 at 15 26 07


To reproduce the error, run

qunit --filter="fail"

You should see that one test file was run, but that the test run fails with not ok global failure:

Screenshot 2019-09-04 at 15 25 56


If you have any relevant configuration information, please include that here:

What did you expect to happen?

I expect a test run that contains zero assertions to pass without a global failure error as long as I declare these tests with the assert.expect(0) method as assertionless.

What actually happened?

When trying to run a test and the test run happens to contain in total zero assertions, the run will fail with a global failure error. The number of tests run will be displayed as passed and one additional failing assertion is displayed in the test output.

jayjayjpg added a commit to jayjayjpg/zero-assert that referenced this issue Sep 4, 2019
@jayjayjpg jayjayjpg changed the title Global failure: Trying to do a test run with zero assertions in total leads to a global error Sep 4, 2019
@Krinkle Krinkle self-assigned this Jun 20, 2020
@Krinkle Krinkle added the Component: Core For module, test, hooks, and runner. label Jun 20, 2020
@Krinkle
Copy link
Member

Krinkle commented Jun 20, 2020

Thanks for reporting this. When a test suite contains actual tests, but uses assert.expect(0) that should still be counted as a test indeed.

@jayjayjpg
Copy link
Contributor Author

@Krinkle That's awesome, thank you for reproducing this. If I can help with contributing, feel free to let me know!

@Krinkle
Copy link
Member

Krinkle commented Jun 20, 2020

@jayjayjpg Patch is welcome! What it comes down to is that we currently determine "No tests run" based on assertions.

Look around for stats, to find the three relevent spots for this issue:

  • core.js: Defines the running count of assertions.
  • test.js: Adds assertions length to the running count.
  • processing-queue.js: Checks the count after all is said and done, to decide whether to throw.

I would recommend adding a count of tests alongside it, and use that for this purpose instead.

@jayjayjpg
Copy link
Contributor Author

@Krinkle Thank you for the details! I just provided a first PR over at #1449 - feel free to let me know if this requires any further changes to be merged and I can iterate on it

@Krinkle Krinkle assigned jayjayjpg and unassigned Krinkle Jun 22, 2020
@Krinkle Krinkle mentioned this issue Jul 21, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core For module, test, hooks, and runner. help welcome Type: Bug
2 participants