-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtest.js
68 lines (57 loc) · 2.06 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* global describe, it */
require('source-map-support').install();
('use strict');
/** *****************************************************************************
* This framework allows for each piece of middleware to run its own tests
* The individual pieces of middleware will place their tests in the following location:
* src/middleware/<your middleware>/test/test.js
* To run tests use 'npm test'
* If you want to run an individual test, use npm test --yourtest
***************************************************************************** */
const path = require('path');
const walk = require('fs-walk');
const winston = require('winston');
const config = require('./server/config');
const npmArgs = JSON.parse(process.env.npm_config_argv);
const tests = [];
// Setup logger
const filename = path.join(__dirname, `./${config.testLogFileName}`);
const logger = new winston.Logger({
level: 'debug',
transports: [new winston.transports.Console(), new winston.transports.File({ filename })],
});
logger.info('Test initialized.');
const testArg = npmArgs.cooked[1] && npmArgs.cooked[1].split('--')[1].toLowerCase();
function addTests(basedir, filename) {
const basedirArray = basedir.split('/');
if (filename === 'test.js') {
if (
// If no test variable is passed
npmArgs.cooked.length <= 1 ||
// or the test variable matches the current directory
testArg === basedirArray[basedirArray.length - 2].toLowerCase()
) {
// add the test to our test array
const filepath = path.join(__dirname, `${basedir}/${filename}`);
tests.push(require(filepath));
}
}
}
// Collect the test file from each middleware module
walk.walkSync('./server', (basedir, filename) => {
addTests(basedir, filename);
});
walk.walkSync('./bots', (basedir, filename) => {
addTests(basedir, filename);
});
// Run each middleware test
describe('Server Tests', function middlewareTest() {
this.timeout(config.virtualDelay * 4);
for (let i = 0; i < tests.length; i++) {
try {
tests[i]();
} catch (ex) {
logger.error(ex);
}
}
});