Skip to content

Commit 5cdc2ba

Browse files
author
cloudhead
committed
(api) watch mode can take arguments, fixed a couple edge cases
1 parent 9ea324f commit 5cdc2ba

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

bin/vows

+19-11
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ if (options.watch) {
119119
msg('bin', 'argv', args);
120120
msg('bin', 'options', { reporter: options.reporter.name, matcher: options.matcher });
121121

122-
if (args.length === 0) {
122+
if (args.length === 0 || options.watch) {
123123
msg('bin', 'discovering', 'folder structure');
124124
root = fs.readdirSync('.');
125125

@@ -132,7 +132,14 @@ if (args.length === 0) {
132132
}
133133
msg('bin', 'discovered', "./" + testFolder);
134134

135-
args = paths(testFolder);
135+
if (args.length === 0) {
136+
args = paths(testFolder);
137+
138+
if (options.watch) {
139+
args = args.concat(paths('lib'),
140+
paths('src'));
141+
}
142+
}
136143
}
137144

138145
if (! options.watch) {
@@ -171,7 +178,6 @@ if (! options.watch) {
171178
});
172179
});
173180
} else {
174-
msg('watcher', 'watching files in', process.cwd() + '/');
175181
//
176182
// Watch mode
177183
//
@@ -229,7 +235,7 @@ if (! options.watch) {
229235
function cursorRestore() { esc("0G") }
230236
function cursorHide() { esc("?25l") }
231237
function cursorShow() { esc("?25h") }
232-
function cleanup() { eraseLine(), cursorShow(), print('\n') }
238+
function cleanup() { eraseLine(), cursorShow(), clearInterval(timer), print('\n') }
233239

234240
//
235241
// Called when a file has been modified.
@@ -238,10 +244,10 @@ if (! options.watch) {
238244
function changed(file) {
239245
status = { honored: 0, broken: 0, errored: 0, pending: 0 };
240246

241-
msg('watcher', 'detected change in', file + '.js');
247+
msg('watcher', 'detected change in', file);
242248

243-
file = (/-(test|spec)$/.test(file) ? path.join(testFolder, file)
244-
: path.join(testFolder, file + '-' + testFolder)) + '.js';
249+
file = (/-(test|spec)\.js$/.test(file) ? path.join(testFolder, file)
250+
: path.join(testFolder, file + '-' + testFolder));
245251

246252
try {
247253
fs.statSync(file);
@@ -268,16 +274,18 @@ if (! options.watch) {
268274
});
269275
}
270276

277+
msg('watcher', 'watching', args);
278+
271279
//
272-
// Watch all relevant files in lib/ and src/,
280+
// Watch all relevant files,
273281
// and call `changed()` on change.
274282
//
275-
[].concat(paths('lib'), paths('src'), paths(testFolder)).forEach(function (p) {
283+
args.forEach(function (p) {
276284
fs.watchFile(p, function (current, previous) {
277285
if (new(Date)(current.mtime).valueOf() ===
278286
new(Date)(previous.mtime).valueOf()) { return }
279287
else {
280-
changed(path.basename(p, '.js'));
288+
changed(p);
281289
}
282290
});
283291
});
@@ -298,7 +306,7 @@ function runSuites(suites, callback) {
298306
(function run(suites, callback) {
299307
var suite = suites.shift();
300308
if (suite) {
301-
msg('runner', "running", suite.subject + ' ', true);
309+
msg('runner', "running", suite.subject + ' ', options.watch ? false : true);
302310
suite.run(options, function (result) {
303311
Object.keys(result).forEach(function (k) {
304312
results[k] += result[k];

0 commit comments

Comments
 (0)