I understand module.export
and require
mannner:
Requiring external js file for mocha testing
Although it\'s pretty usable as long a
UPDATE: FINAL ANSWER:
My previous answer is invalid since eval(code);
is not useful for variables.
Fortunately, node
has a strong mehod - vm
http://nodejs.org/api/vm.html
However, according to the doc,
The vm module has many known issues and edge cases. If you run into issues or unexpected behavior, please consult the open issues on GitHub. Some of the biggest problems are described below.
so, although this works on the surface, extra care needed for such an purpose like testing...
var expect = require('chai')
.expect;
var fs = require('fs');
var vm = require('vm');
var path = './app.js';
var code = fs.readFileSync(path);
vm.runInThisContext(code);
describe('SpaceTime', function()
{
describe('brabra', function()
{
it('MEMORY === "MEMORY"',
function()
{
expect(MEMORY)
.to.equal('MEMORY');
})
});
});
AFTER ALL; The best way I found in this case is to write the test mocha code in the same file.