Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Upgrade Mocha to ^7.1.1 #204

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Config = require("./lib/config");
const TransactionWatcher = require("./lib/transactionWatcher");
const GasTable = require("./lib/gasTable");
const SyncRequest = require("./lib/syncRequest");
const mochaStats = require("./lib/mochaStats");

/**
* Based on the Mocha 'Spec' reporter. Watches an Ethereum test suite run
Expand All @@ -22,7 +23,14 @@ const SyncRequest = require("./lib/syncRequest");
*/
function Gas(runner, options) {
// Spec reporter
Base.call(this, runner);
Base.call(this, runner, options);

// Initialize stats for Mocha 6+ epilogue
if (!runner.stats) {
mochaStats(runner);
this.stats = runner.stats;
}

const self = this;

let indents = 0;
Expand Down
37 changes: 37 additions & 0 deletions lib/mochaStats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* This file adapted from mocha's stats-collector
* https://github.com/mochajs/mocha/blob/54475eb4ca35a2c9044a1b8c59a60f09c73e6c01/lib/stats-collector.js#L1-L83
*/
const Date = global.Date;

/**
* Provides stats such as test duration, number of tests passed / failed etc., by
* listening for events emitted by `runner`.
*/
function mochaStatsCollector(runner) {
const stats = {
suites: 0,
tests: 0,
passes: 0,
pending: 0,
failures: 0
};

if (!runner) throw new Error("Missing runner argument");

runner.stats = stats;

runner.on("pass", () => stats.passes++);
runner.on("fail", () => stats.failures++);
runner.on("pending", () => stats.pending++);
runner.on("test end", () => stats.tests++);

runner.once("start", () => (stats.start = new Date()));

runner.once("end", function() {
stats.end = new Date();
stats.duration = stats.end - stats.start;
});
}

module.exports = mochaStatsCollector;
2 changes: 1 addition & 1 deletion mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"fs-readdir-recursive": "^1.1.0",
"lodash": "^4.17.14",
"markdown-table": "^1.1.3",
"mocha": "^5.2.0",
"mocha": "^7.1.1",
"req-cwd": "^2.0.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.5",
Expand Down
Loading