-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
64 lines (56 loc) · 1.4 KB
/
index.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
require('buffer');
var path = require('path');
var through = require('through');
var util = require('gulp-util');
var path = require('path');
var File = util.File;
var PluginError = util.PluginError;
var mochaSuite = function(opts) {
var pre = new Buffer('require(\'./');
var post = new Buffer('\');');
var buffer = [];
if(!opts) {
opts = {};
}
if(!opts.testDir) {
opts.testDir = './test';
}
if(!opts.suiteFile) {
opts.suiteFile = 'suite.js';
}
function contents(file) {
var filePath = path.relative(opts.testDir, file.path);
if (opts.startWith) {
var remove = filePath.split(opts.startWith + path.sep)[0];
filePath = '../' + filePath.replace(remove, '');
}
if (opts.addPrefix) {
filePath = opts.addPrefix + '/' + filePath;
}
buffer.push(
pre,
new Buffer(filePath),
post,
new Buffer(util.linefeed)
);
}
function end() {
var self = this;
var suite;
if(buffer.length === 0) {
this.emit('error', new PluginError(
'gulp-mocha-browserify-sweet', util.colors.red('No specs in suite.')
));
}
suite = new File({
cwd: '.',
base: opts.testDir,
path: path.join('.', opts.testDir, opts.suiteFile),
contents: Buffer.concat(buffer)
});
self.emit('data', suite);
self.emit('end');
}
return through(contents, end);
};
module.exports = mochaSuite;