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

Support reporting errors in afterAll. #214

Merged
merged 1 commit into from
Aug 8, 2017

Conversation

johnjbarton
Copy link
Contributor

Starting in jasmine 2.5, errors in afterAll are reported to jasmineDone or suiteDone.
Add ExecutionMetrics.errors to store these errors; report them.

Fixes #210

@codecov
Copy link

codecov bot commented Jul 29, 2017

Codecov Report

Merging #214 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #214   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          14     14           
  Lines         416    450   +34     
  Branches       55     61    +6     
=====================================
+ Hits          416    450   +34
Impacted Files Coverage Δ
src/display/execution-display.ts 100% <100%> (ø) ⬆️
src/spec-reporter.ts 100% <100%> (ø) ⬆️
src/execution-metrics.ts 100% <100%> (ø) ⬆️
src/display/summary-display.ts 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8af52a...dc176a6. Read the comment docs.

Copy link
Owner

@bcaudan bcaudan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these afterAll errors are not spec errors, I think we should not used the spec failed method to display them.
It generates this kind of output:

  suite
    ✓ should pass
    ✗ suite
      - Error: suite afterAll error

  Top level suite
    ✗ Non-spec failure
      - Error: top level suite afterAll error

I would be in favor of something like:

  suite
    ✓ should pass
  AfterAll error: suite afterAll error

AfterAll error: top level suite afterAll error

What do you think?

@@ -14,6 +14,7 @@ export class ExecutionMetrics {
public skippedSpecs = 0;
public totalSpecsDefined = 0;
public executedSpecs = 0;
public errors: CustomReporterResult[] = [];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In jasmine default reporter, this kind of error is specific to afterAll error, what about naming it afterAllErrors instead of errors?
Then, the summary report should also be something like * AfterAll Errors *

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning to cheat and use the same mechanism in karma-jasmine, for global errors.

In karma-jasmine, global errors have to be passed from the browser back to the server, then reported via the karma-reporter. Our reporter translates karma API into jasmine calls then into jasmine-spec-reporter. The jasmineDone() api provides a path to report global errors.

That case need not concern you, so my only other question is whether there could be other errors in future? The jasmineDone()/suiteDone() reporting path is not specific to afterAll(), but then again I don't know of any other possible errors.

Not a big deal, so decide and I will follow up.

Copy link
Owner

@bcaudan bcaudan Aug 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with this approach, I'm in favor of naming it globalErrors or globalFailures though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


private errorSummary(error: CustomReporterResult, index: number): void {
this.logger.log(`${index}) ${error.fullName}`);
if (this.configuration.summary.displayErrorMessages) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These errors are not related to failed assertion, I would be in favor of always displayed it for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@johnjbarton
Copy link
Contributor Author

For a case like

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

We see:

Jasmine started

  an error in describe callback
    ✓ should not pass
    ✗ encountered a declaration exception
      - Error: describe error

**************************************************
*                    Failures                    *
**************************************************

1) an error in describe callback encountered a declaration exception
  - Error: describe error

Executed 2 of 2 specs (1 FAILED) in 0.011 sec.

So jasmine chose to create a new spec and attach the error to it. Does that change your thinking?

Not a big deal to me, but I do think that nesting (indenting) the suite error under the suite makes sense, but it could be w/o the x for example.

(I will follow up in one week after my vacation).

@bcaudan
Copy link
Owner

bcaudan commented Aug 6, 2017

I was not aware of this behavior.
I am ok to keep the display as is for now.

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
@johnjbarton
Copy link
Contributor Author

I think I addressed your concerns, if not let me know.

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

Successfully merging this pull request may close these issues.

2 participants