issue-tracker/test-runner.js
Mrugesh Mohapatra 1d7e913ee7
feat: Update Boilerplate to match Refactored User Stories (#15)
* 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>
2020-11-18 14:10:43 -08:00

106 lines
2.1 KiB
JavaScript

/*
*
*
*
*
*
*
*
*
*
*
*
* DO NOT EDIT THIS FILE
* For FCC testing purposes!
*
*
*
*
*
*
*
*
*
*
*
*/
const analyser = require('./assertion-analyser');
const EventEmitter = require('events').EventEmitter;
const Mocha = require('mocha'),
fs = require('fs'),
path = require('path');
const mocha = new Mocha();
let testDir = './tests'
// Add each .js file to the mocha instance
fs.readdirSync(testDir).filter(function(file){
// Only keep the .js files
return file.substr(-3) === '.js';
}).forEach(function(file){
mocha.addFile(
path.join(testDir, file)
);
});
let emitter = new EventEmitter();
emitter.run = function() {
let tests = [];
let context = "";
let separator = ' -> ';
// Run the tests.
try {
let runner = mocha.ui('tdd').run()
.on('test end', function(test) {
// remove comments
let body = test.body.replace(/\/\/.*\n|\/\*.*\*\//g, '');
// collapse spaces
body = body.replace(/\s+/g,' ');
let obj = {
title: test.title,
context: context.slice(0, -separator.length),
state: test.state,
// body: body,
assertions: analyser(body)
};
tests.push(obj);
})
.on('end', function() {
emitter.report = tests;
emitter.emit('done', tests)
})
.on('suite', function(s) {
context += (s.title + separator);
})
.on('suite end', function(s) {
context = context.slice(0, -(s.title.length + separator.length))
})
} catch(e) {
throw(e);
}
};
module.exports = emitter;
/*
* Mocha.runner Events:
* can be used to build a better custom report
*
* - `start` execution started
* - `end` execution complete
* - `suite` (suite) test suite execution started
* - `suite end` (suite) all tests (and sub-suites) have finished
* - `test` (test) test execution started
* - `test end` (test) test completed
* - `hook` (hook) hook execution started
* - `hook end` (hook) hook complete
* - `pass` (test) test passed
* - `fail` (test, err) test failed
* - `pending` (test) test pending
*/