I got a (mini) express app. basically just showing coverage results. in it I have:
app.get('/coverage', function(req, res) {
fs.readFile(path.join(__dirname, '/coverage', 'PhantomJS 1.9.2 (Linux)', 'lcov-report', 'index.html'), 'utf8', function(err, content) {
if(!err) {
res.send(content);
} else {
res.setHeader({ status: '404' });
res.send('');
}
});
});
My problem is that the test runner, while creating the test coverage report can change the folder path, can be Phantom 1.9.3 or something similiar. So I guess I need to build the path with somekind of wildcard in the middle (between coverage and lcov-report).
How can this be achieved?
Natively in Node you can't, but you may use a 3rd party module for this purpose.
For example, using the glob module:
I haven't tested it, but I suppose it's gonna work!
and don't forget to handle errors, kids!