-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic watcher setup #465
Basic watcher setup #465
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ var meow = require('meow'); | |
var Promise = require('bluebird'); | ||
var pkgConf = require('pkg-conf'); | ||
var isCi = require('is-ci'); | ||
var chokidar = require('chokidar'); | ||
var colors = require('./lib/colors'); | ||
var verboseReporter = require('./lib/reporters/verbose'); | ||
var miniReporter = require('./lib/reporters/mini'); | ||
|
@@ -48,6 +49,7 @@ var cli = meow([ | |
' --tap, -t Generate TAP output', | ||
' --verbose, -v Enable verbose output', | ||
' --no-cache Disable the transpiler cache', | ||
' --watch, -w Run tests when files change', | ||
'', | ||
'Examples', | ||
' ava', | ||
|
@@ -68,14 +70,16 @@ var cli = meow([ | |
'fail-fast', | ||
'verbose', | ||
'serial', | ||
'tap' | ||
'tap', | ||
'watch' | ||
], | ||
default: conf, | ||
alias: { | ||
t: 'tap', | ||
v: 'verbose', | ||
r: 'require', | ||
s: 'serial' | ||
s: 'serial', | ||
w: 'watch' | ||
} | ||
}); | ||
|
||
|
@@ -95,6 +99,7 @@ var api = new Api(cli.input.length ? cli.input : arrify(conf.files), { | |
|
||
var logger = new Logger(); | ||
logger.api = api; | ||
logger.watch = cli.flags.watch; | ||
|
||
if (cli.flags.tap) { | ||
logger.use(tapReporter()); | ||
|
@@ -112,17 +117,32 @@ api.on('error', logger.unhandledError); | |
api.on('stdout', logger.stdout); | ||
api.on('stderr', logger.stderr); | ||
|
||
api.run() | ||
.then(function () { | ||
logger.finish(); | ||
logger.exit(api.failCount > 0 || api.rejectionCount > 0 || api.exceptionCount > 0 ? 1 : 0); | ||
}) | ||
.catch(function (err) { | ||
if (err.name === 'AvaError') { | ||
console.log(' ' + colors.error(figures.cross) + ' ' + err.message); | ||
} else { | ||
console.error(colors.stack(err.stack)); | ||
} | ||
|
||
logger.exit(1); | ||
function run() { | ||
api.run() | ||
.then(function () { | ||
logger.finish(); | ||
logger.exit(api.failCount > 0 || api.rejectionCount > 0 || api.exceptionCount > 0 ? 1 : 0); | ||
}) | ||
.catch(function (err) { | ||
if (err.name === 'AvaError') { | ||
console.log(' ' + colors.error(figures.cross) + ' ' + err.message); | ||
} else { | ||
console.error(colors.stack(err.stack)); | ||
} | ||
|
||
logger.exit(1); | ||
}); | ||
} | ||
|
||
run(); | ||
|
||
var cwd = process.cwd(); | ||
var watcher = chokidar.watch(cwd, { | ||
persistent: cli.flags.watch, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think no |
||
ignored: [cwd + '/node_modules', cwd + '/.git'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may be able to specify the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also use |
||
followSymlinks: false | ||
}); | ||
|
||
watcher.on('change', function (filepath) { | ||
run(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the tests run asynchronously, you may end up starting a new batch before the previous execution has finished. It doesn't look like Also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,10 @@ Logger.prototype.exit = function (code) { | |
process.stdout.write(''); | ||
process.stderr.write(''); | ||
|
||
if (this.watch) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO you should place this guard in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
return; | ||
} | ||
|
||
// timeout required to correctly flush IO on Node.js 0.10 on Windows | ||
setTimeout(function () { | ||
process.exit(code); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be commented out. We decided to not yet expose this. #70 (comment)