UNPKG

703 BJavaScriptView Raw
1
2var child = require("child_process")
3, fs = require("fs")
4, describe = require("./").describe
5
6describe.onend = function() {
7 if (!describe.conf.watch) return
8
9 var tick
10 , cmd = process.argv[0]
11 , argv = process.execArgv.concat(process.argv.slice(1)).filter(function(arg) {
12 return arg !== "--watch"
13 })
14
15 Object.keys(require.cache).forEach(watch)
16
17 function watch(name) {
18 fs.watch(name, watchFn).name = name
19 }
20 function watchFn(ev) {
21 if (ev == "rename") {
22 this.close()
23 setTimeout(watch, 5, this.name)
24 }
25 clearTimeout(tick)
26 tick = setTimeout(runAgain, 10)
27 }
28 function runAgain() {
29 try {
30 child.spawn(cmd, argv, { stdio: "inherit" })
31 } catch(e) {
32 console.error(e)
33 }
34 }
35}
36
37