-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Location is not working as expected for --config #3818
Comments
my .mocharc.js configuration file is in another node artifact which I am basically using in this e2e project. |
Is the path |
yes, the path is correct and was using absolute path. I have updated the description above. |
Is I'm quite sure (I don't know macOS) that |
tried your suggestion and still getting the same issue.
/Users/ajadeja/git_test/ace-ilp-lib/node_modules/mocha/lib/cli/config.js:63 Error: failed to parse ./node_modules/ace-api-testlib/lib/.mocharc.js: Error: Cannot find module './node_modules/ace-api-testlib/lib/.mocharc.js' |
Adding "./" to the beginning will have no effect (doesn't hurt or help). Run this from same location as your command above. $ pwd
$ ls -al node_modules/ace-api-testlib/lib/.mocharc.js Relatively certain the List the possibilities... $ find node_modules -name ".mocharc*" |
The path above is relative. Absolute paths on UN*X begin with a slash character |
@plroebuck I got the below output for the commands you requested to execute |
you left out the most important -- |
@plroebuck Sorry here it is Just FYI: I have my project open in Webstorm, and I am running an npm command from Webstorm Project Terminal |
$ which mocha
$ cat package.json
$ cat node_modules/ace-api-testlib/lib/.mocharc.js |
@plroebuck C02Q383EG8WP:ace-ilp-lib ajadeja$ which mocha let allureResultsOutdir = process.env.OUTDIR ? path.join(process.env.OUTDIR, 'allure-results') : 'target/allure-results'; module.exports = { |
Quick test with absolute path... "scripts": {
"test": "mocha --no-opts --config '/Users/ajadeja/git_test/ace-ilp-lib/node_modules/ace-api-testlib/lib/.mocharc.js' --reporter mocha-allure-reporter",
"report": "allure generate target/allure-results --clean -o allure-report"
}, $ npm test |
Does "ace-ilp-lib" contain a Mocha config file you're trying to avoid? |
No but if I put in ace-ilp-lib it works since that's the default path |
Yes this one works, but I can not give this path, as location of ace-ilp-lib is end users' choice |
Works means it ran your tests as expected, or it didn't immediately blow up? |
it ran tests as expected |
Out of curiosity, why are you putting the Mocha config files in the "lib" directory to begin with? |
|
@plroebuck that's fine, I know now that we should give absolute path here. I will try to find other ways for my requirement. Thanks for your help |
So:
Still kinda lost on why put the Mocha config file in the "lib" directory. |
oh will it? I tried putting in ace-api-testlib/.mocharc.js and it was not working. If I keep in ace-api-testlib/.mocharc.js what will be my path for --config file? |
Some of my concern is also that "node_modules/ace-api-testlib/lib/.mocharc.js" turns around and |
Suggest: $ cat package.json
{
"name": "ace-ilp-lib",
"version": "1.0.9",
"description": "Provides basic test framework support, including session management, logging, test data management",
"main": "index.js",
"dependencies": {
"ace-api-testlib": "~1.0.7"
},
"devDependencies": {
"allure-commandline": "^2.9.0",
"mocha": "^6.0.2",
"mocha-allure-reporter": "^1.4.0"
},
"files": [
"lib",
"test"
],
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
"pretest": "rm -rf allure-results",
"pwd": "pwd",
"report": "allure generate target/allure-results --clean -o allure-report && allure open allure-report",
"test": "mocha --config ./node_modules/ace-api-testlib/.mocharc.js"
},
"repository": {
"type": "git",
"url": "https://stash.intralinks.com/scm/ace/ace-ilp-lib.git"
},
"author": "ace-api",
"license": "ISC"
} |
Tried the suggestion which gives same as original error
/Users/ajadeja/git_test/ace-ilp-lib/node_modules/mocha/lib/cli/config.js:63 Error: failed to parse ./node_modules/ace-api-testlib/.mocharc.js: Error: Cannot find module './node_modules/ace-api-testlib/.mocharc.js' |
$ cat node_modules/ace-api-testlib/.mocharc.js 'use strict';
const path = require('path');
const FIFTY_SECS = 50000;
const allureArtifactsDir = process.env.OUTDIR
? path.join(process.env.OUTDIR, 'allure-results')
: 'target/allure-results';
module.exports = {
timeout: FIFTY_SECS,
file: path.resolve('./node_modules/ace-api-testlib/test/mocha.global.js'),
opts: false,
reporter: 'mocha-allure-reporter',
reporterOption: [ 'targetDir=' + allureArtifactsDir ]
}; |
gives same error as given above |
What's in "./node_modules/ace-api-testlib/mocha.global.js"? |
global hooks configuration for e2e tests |
You have |
I deleted the global mocha, still gives same error |
$ cat node_modules/ace-api-testlib/package.json | grep version |
C02Q383EG8WP:ace-ilp-lib ajadeja$ cat node_modules/ace-api-testlib/package.json | grep version |
Figured out your issue... I think anyway. const parsers = (exports.parsers = {
yaml: filepath =>
require('js-yaml').safeLoad(fs.readFileSync(filepath, 'utf8')),
js: filepath => require(filepath),
json: filepath =>
JSON.parse(
require('strip-json-comments')(fs.readFileSync(filepath, 'utf8'))
)
}); The other parsers are reading the config file directly, so relative path is straightforward. But your JS config file is handled by So rather than: "scripts": {
"test": "mocha --config ./node_modules/ace-api-testlib/.mocharc.js"
}, instead use the even shorter: "scripts": {
"test": "mocha --config ace-api-testlib/.mocharc.js"
}, Used this recipe for testing. There were additional changes needed to get your setup (as I understand it anyway) to work. |
Yes this works as expected.. thanks |
Everything working now? Hope recipe helped. If no further questions, please close the issue. Thx |
Yes, recipe helped. Everything works now. Closing the issue. |
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
Steps to Reproduce
Expected behavior: [What you expect to happen]
config file should load from the given custom location
Actual behavior: [What actually happens]
Getting issue as below
/Users/ajadeja/git_test/ace-ilp-lib/node_modules/mocha/lib/cli/config.js:63
throw new Error(
failed to parse ${filepath}: ${err}
);^
Error: failed to parse node_modules/ace-api-testlib/lib/.mocharc.js: Error: Cannot find module 'node_modules/ace-api-testlib/lib/.mocharc.js'
at exports.loadConfig.filepath (/Users/ajadeja/git_test/ace-ilp-lib/node_modules/mocha/lib/cli/config.js:63:11)
at loadRc (/Users/ajadeja/git_test/ace-ilp-lib/node_modules/mocha/lib/cli/options.js:229:21)
at loadOptions (/Users/ajadeja/git_test/ace-ilp-lib/node_modules/mocha/lib/cli/options.js:299:20)
at Object. (/Users/ajadeja/git_test/ace-ilp-lib/node_modules/mocha/bin/mocha:29:14)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
npm ERR! code ELIFECYCLE
Reproduces how often: [What percentage of the time does it reproduce?]
Versions
The output of
mocha --version
andnode node_modules/.bin/mocha --version
:% mocha --version
6.0.2
The output of
node --version
:% node --version
v8.11.1
Your operating system
Your shell (e.g., bash, zsh, PowerShell, cmd): bash
Your browser and version (if running browser tests):
Any third-party Mocha-related modules (and their versions):
Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version):
Additional Information
The text was updated successfully, but these errors were encountered: