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

Errors reported on the top suite aren't displayed #16

Open
sgravrock opened this issue Aug 28, 2021 · 0 comments
Open

Errors reported on the top suite aren't displayed #16

sgravrock opened this issue Aug 28, 2021 · 0 comments

Comments

@sgravrock
Copy link

This script produces four errors at the level of the top suite:

const Jasmine = require('jasmine');
const JasmineConsoleReporter = require('jasmine-console-reporter');

const jasmine = new Jasmine();
const reporter = new JasmineConsoleReporter();
jasmine.clearReporters();
jasmine.addReporter(reporter);

beforeAll(function() {
	throw new Error('a beforeAll exception');
});

it('causes errors after the spec is done', async function() {
	Promise.reject(new Error('an unhandled rejection "in" a spec'));
	setTimeout(function() {
		throw new Error('an async failure after the spec finished');
	});
});

afterAll(function(done) {
	// Ensure that the late failures above happen before the suite finishes
	setTimeout(done, 1000);
	throw new Error('an afterAll exception');
});

jasmine.execute();

When I run it, jasmine-console-reporter reports an overall result of "failed" but doesn't show any particulars:

$ node --version
v16.0.0
$ node test.js 

Executing 1 defined specs...
Running in random order... (seed: 24753)

Test Suites & Specs:

✔ causes errors after the spec is done (1ms)

>> Done!


Summary:

❌  Failed
Suites:  0 of 0
Specs:   1 of 1
Expects: 0 (none executed)
Finished in 0.006 seconds

If I comment out the jasmine.clearReporters and jasmine.addReporter calls, Jasmine's default console reporter displays the failures:

$ node test.js 
Randomized with seed 16079
Started
.


Suite error: undefined
  Message:
    Error: a beforeAll exception
  Stack:
    Error: a beforeAll exception
        at UserContext.<anonymous> (/path/to/test.js:12:8)
        at <Jasmine>
        at processImmediate (node:internal/timers:464:21)
  Message:
    Unhandled promise rejection: Error: an unhandled rejection "in" a spec
  Stack:
    Error: an unhandled rejection "in" a spec
        at UserContext.<anonymous> (/path/to/test.js:16:17)
        at <Jasmine>
        at processImmediate (node:internal/timers:464:21)
  Message:
    Uncaught exception: Error: an async failure after the spec finished
  Stack:
    Error: an async failure after the spec finished
        at Timeout._onTimeout (/path/to/test.js:18:9)
        at listOnTimeout (node:internal/timers:557:17)
        at processTimers (node:internal/timers:500:7)
  Message:
    Error: an afterAll exception
  Stack:
    Error: an afterAll exception
        at UserContext.<anonymous> (/path/to/test.js:25:8)
        at <Jasmine>
        at processImmediate (node:internal/timers:464:21)

1 spec, 0 failures
Finished in 0.006 seconds
Randomized with seed 16079 (jasmine --random=true --seed=16079)

Likewise, jasmine-console-reporter displays them if I wrap everything in a describe:

$ node test.js 

Executing 1 defined specs...
Running in random order... (seed: 41097)

Test Suites & Specs:

1. a suite
   ✔ causes errors after the spec is done (1ms)

>> Done!


Summary:

❌  Failed
Suites:  1 of 1
Specs:   1 of 1
Expects: 0 (none executed)
Finished in 0.008 seconds


>> An error was thrown in an afterAll
   Error: a beforeAll exception
       at UserContext.<anonymous> /path/to/test.js:11:8
       at <Jasmine>
       at processImmediate node:internal/timers:464:21
>> An error was thrown in an afterAll
   Unhandled promise rejection: Error: an unhandled rejection "in" a spec
       at UserContext.<anonymous> /path/to/test.js:15:17
       at <Jasmine>
       at processImmediate node:internal/timers:464:21
>> An error was thrown in an afterAll
   Uncaught exception: Error: an async failure after the spec finished
       at Timeout._onTimeout /path/to/test.js:17:9
       at listOnTimeout node:internal/timers:557:17
       at processTimers node:internal/timers:500:7
>> An error was thrown in an afterAll
   Error: an afterAll exception
       at UserContext.<anonymous> /path/to/test.js:24:8
       at <Jasmine>
       at processImmediate node:internal/timers:464:21

Top suite failures are relatively common even when all specs are wrapped in a describe. They can happen when there's a top-level beforeAll or afterAll. Unhandled exceptions and promise rejections that happen after a spec signals completion are also commonly routed to the top suite, especially in small test suites, although that's highly sensitive to timing.

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