-
Notifications
You must be signed in to change notification settings - Fork 3
/
MochaOnly.js
29 lines (28 loc) · 899 Bytes
/
MochaOnly.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
'use strict';
const PreCommitBase = require('./Base');
/**
* @class MochaOnly
* @extends PreCommitBase
* @classdesc Check for '.only` usage in mocha test files
*/
module.exports = class MochaOnly extends PreCommitBase {
/**
* Use grep to check for `describe.only` or `it.only` in test files
* Uses spawnPromiseOnApplicableFiles to parallelize
*
* @returns {Promise}
* @resolves {string|string[]} 'pass' or a tuple of 'fail' and a message
* @rejects {Error} An Error thrown or emitted while running the hook
*/
run() {
return new Promise((resolve, reject) => {
this.spawnPromiseOnApplicableFiles().then((result) => {
if (result.stdout.toString().trim()) {
return resolve(['fail', 'A .only found in mocha test file:\n' + result.stdout.toString()]);
} else {
return resolve('pass');
}
}, reject);
});
}
};