Skip to content

Commit 47c2d1f

Browse files
author
cloudhead
committed
(new) support multiple test suites per file
1 parent bb9a5af commit 47c2d1f

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

bin/vows

+20-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var options = {
2222
watch: false
2323
};
2424

25-
var suites = [];
25+
var files = [];
2626

2727
// Get rid of process runner
2828
// ('node' in most cases)
@@ -82,6 +82,7 @@ msg('bin', 'argv', args);
8282
msg('bin', 'options', { reporter: options.reporter.name, matcher: options.matcher });
8383

8484
if (args.length === 0) {
85+
msg('bin', 'discovering', 'folder structure');
8586
root = fs.readdirSync('.');
8687

8788
if (root.indexOf('test') !== -1) {
@@ -91,6 +92,7 @@ if (args.length === 0) {
9192
} else {
9293
abort("runner", "couldn't find test folder");
9394
}
95+
msg('bin', 'discovered', "./" + testFolder);
9496

9597
args = paths(testFolder);
9698
}
@@ -114,12 +116,11 @@ if (! options.watch) {
114116
};
115117
reporter.reset = function () { _reporter.reset && _reporter.reset() };
116118

117-
suites = args.map(function (a) {
118-
a = path.join(process.cwd(), a.replace(/\.js$/, ''));
119-
msg('runner', "loading", a);
120-
return require(a).vows;
119+
files = args.map(function (a) {
120+
return path.join(process.cwd(), a.replace(/\.js$/, ''));
121121
});
122-
runSuites(suites, function (results) {
122+
123+
runSuites(importSuites(files), function (results) {
123124
!options.verbose && _reporter.print('\n');
124125
msg('runner', 'finish');
125126
_reporter.report(['finish', results], {
@@ -210,17 +211,16 @@ if (! options.watch) {
210211
file = null;
211212
}
212213

213-
var suites = (/-(test|spec)\.js$/.test(file) ? [file] : paths(testFolder)).map(function (p) {
214+
var files = (/-(test|spec)\.js$/.test(file) ? [file] : paths(testFolder)).map(function (p) {
214215
return path.join(process.cwd(), p.replace(/\.js$/, ''));
215216
}).map(function (p) {
216217
delete(require.main.moduleCache[p]);
217218
return p;
218219
});
219220

220-
msg('watcher', 'loading', suites);
221221
running ++;
222222

223-
runSuites(suites.map(function (s) { return require(s).vows }), function (results) {
223+
runSuites(importSuites(files), function (results) {
224224
delete(results.time);
225225
print(console.result(results).join('') + '\n\n');
226226
lastRun = new(Date);
@@ -272,6 +272,17 @@ function runSuites(suites, callback) {
272272
})(suites, callback);
273273
}
274274

275+
function importSuites(files) {
276+
msg(options.watcher ? 'watcher' : 'runner', 'loading', files);
277+
278+
return files.reduce(function (suites, f) {
279+
var obj = require(f);
280+
return suites.concat(Object.keys(obj).map(function (s) {
281+
return obj[s];
282+
}));
283+
}, [])
284+
}
285+
275286
//
276287
// Recursively traverse a hierarchy, returning
277288
// a list of all relevant .js files.

lib/vows/suite.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ this.Suite.prototype = new(function () {
262262
if (require.main === module) {
263263
return this.run();
264264
} else {
265-
return module.exports.vows = this;
265+
return module.exports[this.subject] = this;
266266
}
267267
};
268268
});

0 commit comments

Comments
 (0)