I want start tests on each get request and store status to local db. Tests starts only on first request
var express = require('express');
var path = require('path');
var Mocha = require('mocha');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var app = express();
app.use(morgan('dev'));
app.use(bodyParser.json());
app.get('/api/github/serviceX', function (req, res) {
var mocha = new Mocha({
timeout:60000,
});
mocha.addFile('test/serviceX.js');
var passed = [];
var failed = [];
mocha.run(function () {
console.log(passed.length + ' Tests Passed');
passed.forEach(function(testName){
console.log('Passed:', testName);
});
console.log("\n"+failed.length + ' Tests Failed');
failed.forEach(function(testName){
console.log('Failed:', testName);
});
store("serviceX", [passed, failed]);
res.send(200, format(passed, failed);
}).on('fail', function(test){
failed.push(test);
}).on('pass', function(test){
passed.push(test);
});
});
First request runs good
4 passing (10s) 4 Tests Passed 0 Tests Failed
Second and next requests does not starts tests
0 passing (0ms)
0 Tests Passed
0 Tests Failed
Aucun commentaire:
Enregistrer un commentaire