Skip to content

Commit

Permalink
test helper improvements (#4241)
Browse files Browse the repository at this point in the history
* test helper improvements

- enables `RawResult` (the result of `invokeMocha()` or `invokeMochaAsync()`) to check the exit code via `to have code` assertion
- add passed/failing/pending assertions for `RawRunResult` (the result of `runMocha()` or `runMochaAsync()`)

- expose `getSummary()`, which can be used with a `RawResult` (when not failing)
- reorganize the module a bit
- create `runMochaAsync()` and `runMochaJSONAsync()` which are like `runMocha()` and `runMochaJSON()` except return `Promise`s
- better trapping of JSON parse errors
- better default handling of `STDERR` output in subprocesses (print it instead of suppress it!)
- do not let the `DEBUG` env variable reach subprocesses _unless it was explicitly supplied_
- add an easily copy-paste-able `command` prop to summary
- add some missing docstrings

Ref: #4198

* increase timeout in watch test for CI

the same code should be in PR #4240
  • Loading branch information
boneskull committed May 4, 2020
1 parent 2509ab5 commit 240cb3d
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 113 deletions.
20 changes: 19 additions & 1 deletion test/assertions.js
Expand Up @@ -118,6 +118,24 @@ exports.mixinMochaAssertions = function(expect) {
});
}
)
.addAssertion(
'<RawRunResult> [not] to have failed [test] count <number>',
function(expect, result, count) {
expect(result.failing, '[not] to be', count);
}
)
.addAssertion(
'<RawRunResult> [not] to have passed [test] count <number>',
function(expect, result, count) {
expect(result.passing, '[not] to be', count);
}
)
.addAssertion(
'<RawRunResult> [not] to have pending [test] count <number>',
function(expect, result, count) {
expect(result.pending, '[not] to be', count);
}
)
.addAssertion('<JSONRunResult> [not] to have test count <number>', function(
expect,
result,
Expand Down Expand Up @@ -315,7 +333,7 @@ exports.mixinMochaAssertions = function(expect) {
}
)
.addAssertion(
'<RawRunResult|JSONRunResult> to have [exit] code <number>',
'<RawResult|RawRunResult|JSONRunResult> to have [exit] code <number>',
function(expect, result, code) {
expect(result.code, 'to be', code);
}
Expand Down

0 comments on commit 240cb3d

Please sign in to comment.