-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.js
52 lines (40 loc) · 1.22 KB
/
core.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
process.env.ENVIRONMENT = process.env.ENVIRONMENT || 'testing';
process.env.HIDE_ARGUMENTS = true;
const Jasmine = require('jasmine');
const path = require('path');
const fs = require('fs');
/**
* Core function that will execute a set of jasmine sets.
*
* @param {string} type The type of testing to do.
* @param {object} config The object configuration for the jasmine spec.
* @returns {Promise.<void>}
*/
const promiseFn = (type, config) => {
if (typeof config === 'string') {
config = {
'spec_dir': `test/${config}`,
'spec_files': ['*.js', '**/*.js']
};
}
return new Promise((resolve, reject) => {
fs.exists(path
// jscs:disable
.normalize(process.cwd() + '/' + config['spec_dir']), exists => {
// jscs:enable
if (!exists) {
console.log(`No ${type} found`);
return resolve();
}
const jasmine = new Jasmine();
jasmine.loadConfig(Object.assign({
'spec_dir': 'test',
'spec_files': []
}, config));
console.log(`\nRunning ${type} (test/${config['spec_dir']}/*.js)`);
jasmine.onComplete(passed => passed ? resolve(passed) : reject(passed));
jasmine.execute();
});
});
};
module.exports = promiseFn;