From 1a17870b12f57e00fbb4e520e92aac41821b0e1a Mon Sep 17 00:00:00 2001 From: Eric Pizon Date: Thu, 12 May 2016 15:08:50 -0400 Subject: [PATCH] - supports configuring mocha path thru mocha.json. When mocha path is configured, it will override the default, which is in project directory. --- Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js b/Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js index 9a597e355..886948d54 100644 --- a/Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js +++ b/Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js @@ -79,8 +79,17 @@ function logError() { } function detectMocha(projectFolder) { - try { - var mochaPath = path.join(projectFolder, 'node_modules', 'mocha'); + try { + var node_modulesFolder = projectFolder; + var mochaJsonPath = path.join(node_modulesFolder, 'test', 'mocha.json'); + if (fs.existsSync(mochaJsonPath)) { + var opt = require(mochaJsonPath); + if (opt && opt.path) { + node_modulesFolder = path.resolve(projectFolder, opt.path); + } + } + + var mochaPath = path.join(node_modulesFolder, 'node_modules', 'mocha'); var Mocha = new require(mochaPath); return Mocha; } catch (ex) {