From cd583d687ce01eaa2a39feb8a25a23fbc3619130 Mon Sep 17 00:00:00 2001 From: Isaac Murchie Date: Thu, 25 Apr 2019 07:59:02 -0400 Subject: [PATCH] Get mocha binary from npm bin --- index.js | 14 +++++++++++--- package.json | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 7c02ea5..c894e45 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,8 @@ var _ = require('lodash'), streamBuffers = require("stream-buffers"), through = require('through'), split = require('split'), - fs = require('fs'); + fs = require('fs'), + os = require('os'); require('colors'); @@ -22,6 +23,11 @@ function newStreamBuffer() { return stream; } +var getNpmBin = _.memoize(function getNpmBin () { + // this only happens once, so sync is fine + return proc.execSync('npm bin', {encoding: 'utf8'}).trim(); +}); + var SpawnMocha = function (opts) { var _this = this; opts = opts || {}; @@ -30,8 +36,10 @@ var SpawnMocha = function (opts) { }); var queue = async.queue(function (task, done) { // Setup - var bin = _.isFunction(opts.bin) ? opts.bin() : opts.bin || - join(__dirname, 'node_modules', '.bin', 'mocha'); + var bin = _.isFunction(opts.bin) + ? opts.bin() + : opts.bin + || join(getNpmBin(), os.platform === 'win32' ? 'mocha.md' : 'mocha'); var env = _.isFunction(opts.env) ? opts.env() : opts.env || process.env; env = _.clone(env); diff --git a/package.json b/package.json index 952f2e7..90a323f 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,9 @@ "husky": "^2.0.0", "vinyl": "^2.0.0" }, + "peerDependency": { + "mocha": "^6.0.0" + }, "engines": { "node": ">= 0.9.0" },