'Export variable in Mocha test
To shed some light on what i'm trying to do is: after the test below is ran I get the report.json generated and the token I generated in the before hook and send the report to another api for it to process.
I have a mocha test in which I generate a token and I need this token generate to be shared with another js file.
var token = 'un_assigned';
describe('Comparison', function () {
token = 'sin asignar';
before(function (done) {
getToken('app', function (response) {
token = response.token;
done();
})
});
files.forEach(function (file) {
it('Comparing ' + file, function (done) {
const id = file.split('./screenshots/')[1];
compare(file, id, token, function (response) {
expect(response.TestPassed).to.be.true;
done();
});
});
});
after(function (done) {
done();
})
});
exports.tokenApi = function getToken(){
console.log(token);
return token;
};
After the test is ran I need to pass the generate token to another JS file so I can process the mocha report. I tried using exports but when I call my function it calls my test. I'm a JS noob is there something im missing ?.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
