From 9b7b9b4b76974f100fdb57f6bdd4f4b93924054f Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Sat, 13 May 2017 12:30:08 -0700 Subject: [PATCH] Extract chrome-launcher to a standalone thing. ref #2092 --- chrome-launcher/test/global-mocha-hooks.js | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 chrome-launcher/test/global-mocha-hooks.js diff --git a/chrome-launcher/test/global-mocha-hooks.js b/chrome-launcher/test/global-mocha-hooks.js new file mode 100644 index 000000000000..8cdd95ff568c --- /dev/null +++ b/chrome-launcher/test/global-mocha-hooks.js @@ -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; +}); +