I am working on a project which requires to use node with ES6 alongside Mocha. So I came across a small issue, When I export a variable from one file to another, It actually exports the entire file! However I just want the variable to be exported.
Simply said, I want the updated value of x but doesn't want foo.js to run the Test Suit(function doubleX). How can I achieve this or what is wrong with my approach?
// foo.js
import {x} from './bar.js'
console.log(x);
// bar.js
export var x = 5;
// Test Suit Function
function doubleX(){
describe("Test Suit", function(){
// Few Calculations & Updated Variable
x += x;
// Some Test Case
it("Test Case", function(){
})
})
}
// Need to run test suit by bar.js not by foo.js
doubleX();
console.log(x);
Mocha scripts:
"scripts": {
"foo": "node_modules/.bin/mocha -bail --compilers js:babel-core/register -r jsdom-global/register foo.js",
"bar": "node_modules/.bin/mocha -bail --compilers js:babel-core/register -r jsdom-global/register bar.js",
}
When I use npm run foo
Actual Output:
10
10
(node:4981) DeprecationWarning: "--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info
Test Suit
✓ Test Case
1 passing (8ms)
Expected Output:
10
console.log
statement from your bar.js file, so the actual output can't be10
twice.