How to pass the values from terminal for mocha test?

568 views
Skip to first unread message

jyo rani

unread,
Nov 2, 2020, 4:30:50 PM11/2/20
to Mocha
I have to create ci for my mocha test to run on the stage environment and need to paratemeterize the value? can any one help with that?

i tried this 


test.js

const BASE_URL = process.env.BASE_URL
console.log(BASE_URL);

package.json

"test": "mocha test BASE_URL=$BASE_URL --timeout 30000",
 
terminal command to run test

BASE_URL=http://localhost:8000 npm run test

/node_modules/mocha/lib/utils.js:634
        throw new Error("cannot resolve path (or pattern) '" + path + "'");
        ^

Error: cannot resolve path (or pattern) 'BASE_URL=http://localhost:8000'



Vlad GURDIGA

unread,
Nov 3, 2020, 3:02:11 AM11/3/20
to Mocha
Hi jsel! 👋

To set the environment variable for the mocha process, they should go before the name of the program: 🤓

BASE_URL=$BASE_URL mocha test --timeout 30000

Good luck! 🙂
Reply all
Reply to author
Forward
0 new messages