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 in afterAll functions are not reported. #210

Closed
johnjbarton opened this issue Jul 27, 2017 · 8 comments
Closed

Errors in afterAll functions are not reported. #210

johnjbarton opened this issue Jul 27, 2017 · 8 comments

Comments

@johnjbarton
Copy link
Contributor

Feature request

Current behavior
Errors in afterAll() still allow tests to pass.
Wanted behavior
Tests fail on errors
What is the motivation / use case for changing the behavior?
Errors are bad ;-)

The suiteDone() can take a result argument:
https://github.com/bcaudan/jasmine-spec-reporter/blob/master/src/display/execution-display.ts#L101
jasmine will report afterAll errors as a failedExpectation in that arg.

We need that to 1) report the error 2) ensure the final status is FAILED.

@johnjbarton
Copy link
Contributor Author

For test

describe('afterall errors', () => {
	afterAll(() => {
		throw new Error('error in afterAll');
	});
	it('should not pass', () => {
		expect(true).toBe(true);
	});
});

Here is the default reporter from jasmine:

./node_modules/jasmine/bin/jasmine.js afterall_throws_spec.js 
Started
.


1 spec, 1 failure
Finished in 0.01 seconds

An error was thrown in an afterAll
AfterAll Error: error in afterAll

Here is the jasmine-spec-reporter result:

[afterall]$ ./node_modules/jasmine/bin/jasmine.js afterall_throws_spec.js 
Jasmine started

  afterall errors
    ✓ should not pass

Executed 1 of 1 spec SUCCESS in 0.011 sec.
[afterall]$ 

I think this is a change in jasmine 2.5.

johnjbarton added a commit to johnjbarton/jasmine-spec-reporter that referenced this issue Jul 29, 2017
Starting in jasmine 2.5, errors in afterAll are reported to jasmineDone or suiteDone.
Add ExecutionMetrics.errors to store these errors; report them.

Fixes bcaudan#210
johnjbarton added a commit to johnjbarton/jasmine-spec-reporter that referenced this issue Jul 29, 2017
Starting in jasmine 2.5, errors in afterAll are reported to jasmineDone or suiteDone.
Add ExecutionMetrics.errors to store these errors; report them.

Fixes bcaudan#210
@bcaudan
Copy link
Owner

bcaudan commented Jul 30, 2017

nice catch

johnjbarton added a commit to johnjbarton/jasmine-spec-reporter that referenced this issue Aug 7, 2017
Starting in jasmine 2.5, errors in afterAll are reported to jasmineDone or suiteDone.
Add ExecutionMetrics.globalErrors to store these errors; report them.

Fixes bcaudan#210
bcaudan pushed a commit that referenced this issue Aug 8, 2017
Starting in jasmine 2.5, errors in afterAll are reported to jasmineDone or suiteDone.
Add ExecutionMetrics.globalErrors to store these errors; report them.

Fixes #210
@bcaudan
Copy link
Owner

bcaudan commented Aug 8, 2017

Available in [email protected]

@gvdp
Copy link

gvdp commented May 15, 2018

Hey guys, sorry to dig up an old issue, but I'm experiencing something similar.
I have an afterAll() block which throws an error, and I'm using version 4.2.1 so it is indeed being 'reported' but my node process to run the tests is still exiting with code 0 : Process finished with exit code 0.
This makes my CI pipeline thinks all tests have passed although there was an error.

Is that an issue in the spec-reporter? Or do I have to address this somewhere else?

@johnjbarton
Copy link
Contributor Author

johnjbarton commented May 15, 2018 via email

@bcaudan
Copy link
Owner

bcaudan commented May 15, 2018

@johnjbarton is right, the reporter is not responsible for determining the result or exiting the process.

I think this issue is probably solved with [email protected].
Try to upgrade your jasmine version if you are on an older one, otherwise your issue should probably be reported at https://github.com/jasmine/jasmine.

@gvdp
Copy link

gvdp commented May 16, 2018

Yeah I agree, I was wondering if maybe the reporter "swallowed" the error somehow but afterwards I tried disabling the reporter and it produced the same behaviour. I was just wondering what you guys would do in such a situation.
It's a protractor test and I found in the style guide that it's bad practice to do assertions/verifications in the afterAll() hook, so it seems to be by design that this wouldn't exit the process. For now I moved my assertions to the afterEach() hook.

@johnjbarton
Copy link
Contributor Author

Before jasmine 3.0, afterAll() errors were not always reported well and test runners may not handle these 'global' errors very well.

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

3 participants