Skip to content

Commit

Permalink
Extract chrome-launcher to a standalone thing.
Browse files Browse the repository at this point in the history
ref #2092
  • Loading branch information
samccone committed May 13, 2017
1 parent 9c06fc1 commit 9b7b9b4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 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;
});

0 comments on commit 9b7b9b4

Please sign in to comment.