Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract chrome-launcher to a standalone thing.
ref #2092
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
|
||
/** | ||
* THIS FILE IS A DUPLICATE OF lighthouse-core/test/global-mocha-hooks.js | ||
* Please keep them in sync. | ||
*/ | ||
|
||
/* eslint-env mocha */ | ||
let currTest; | ||
|
||
// monkey-patch all assert.* methods | ||
Object.keys(assert) | ||
.filter(key => typeof assert[key] === 'function') | ||
.forEach(key => { | ||
const _origFn = assert[key]; | ||
assert[key] = function(...args) { | ||
if (currTest) { | ||
currTest._assertions++; | ||
} | ||
return _origFn.apply(this, args); | ||
}; | ||
} | ||
); | ||
|
||
// store the count of assertions on each test's state object | ||
beforeEach(function() { | ||
// eslint-disable-next-line no-invalid-this | ||
currTest = this.currentTest; | ||
currTest._assertions = currTest._assertions || 0; | ||
}); | ||
|
||
afterEach(function() { | ||
if (currTest._assertions === 0) { | ||
throw new Error(`ZERO assertions in test: "${currTest.title}"\n${currTest.file}`); | ||
} | ||
currTest = null; | ||
}); | ||
|