1d7e913ee7
* Initial Refactor * Updated Tests, Added samples files, removed user stories * Add `dotenv` package * Update assertion-analyser.js Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com> * Update assertion-analyser.js Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * Update assertion-analyser.js Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com> * Remove unneeded files * Remove unneeded Code Co-authored-by: SaintPeter <rex.schrader@gmail.com> Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
86 lines
1.7 KiB
JavaScript
86 lines
1.7 KiB
JavaScript
/*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
* DO NOT EDIT THIS FILE
|
|
* For FCC testing purposes!
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const cors = require('cors');
|
|
const fs = require('fs');
|
|
const runner = require('../test-runner');
|
|
|
|
module.exports = function (app) {
|
|
|
|
app.route('/_api/server.js')
|
|
.get(function(req, res, next) {
|
|
console.log('requested');
|
|
fs.readFile(__dirname + '/server.js', function(err, data) {
|
|
if(err) return next(err);
|
|
res.send(data.toString());
|
|
});
|
|
});
|
|
app.route('/_api/routes/api.js')
|
|
.get(function(req, res, next) {
|
|
console.log('requested');
|
|
fs.readFile(__dirname + '/routes/api.js', function(err, data) {
|
|
if(err) return next(err);
|
|
res.type('txt').send(data.toString());
|
|
});
|
|
});
|
|
|
|
let error;
|
|
app.get('/_api/get-tests', cors(), function(req, res, next){
|
|
console.log(error);
|
|
if(!error && process.env.NODE_ENV === 'test') return next();
|
|
res.json({status: 'unavailable'});
|
|
},
|
|
function(req, res, next){
|
|
if(!runner.report) return next();
|
|
res.json(testFilter(runner.report, req.query.type, req.query.n));
|
|
},
|
|
function(req, res){
|
|
runner.on('done', function(report){
|
|
process.nextTick(() => res.json(testFilter(runner.report, req.query.type, req.query.n)));
|
|
});
|
|
});
|
|
};
|
|
|
|
function testFilter(tests, type, n) {
|
|
let out;
|
|
switch (type) {
|
|
case 'unit' :
|
|
out = tests.filter(t => t.context.match('Unit Tests'));
|
|
break;
|
|
case 'functional':
|
|
out = tests.filter(t => t.context.match('Functional Tests') && !t.title.match('#example'));
|
|
break;
|
|
default:
|
|
out = tests;
|
|
}
|
|
if(n !== undefined) {
|
|
return out[n] || out;
|
|
}
|
|
return out;
|
|
} |