| 1 |
const fs = require("fs"); |
| 2 |
const assert = require("assert"); |
| 3 |
const readline = require("readline"); |
| 4 |
|
| 5 |
|
| 6 |
if (!assert.match) assert.match = (val, re) => assert(re.test(val)); |
| 7 |
|
| 8 |
const run = (async function* () { |
| 9 |
assert.match(yield, /Successfully compiled 2 files with Babel \(\d+ms\)\./); |
| 10 |
|
| 11 |
assert.equal(yield, "The watcher is ready."); |
| 12 |
|
| 13 |
logFile("lib/index.js"); |
| 14 |
logFile("lib/main.js"); |
| 15 |
|
| 16 |
fs.writeFileSync("./file.txt", "Updated!"); |
| 17 |
|
| 18 |
assert.match(yield, /Successfully compiled 2 files with Babel \(\d+ms\)\./); |
| 19 |
|
| 20 |
logFile("lib/index.js"); |
| 21 |
logFile("lib/main.js"); |
| 22 |
})(); |
| 23 |
|
| 24 |
run.next(); |
| 25 |
|
| 26 |
const rl = readline.createInterface(process.stdin); |
| 27 |
|
| 28 |
rl.on("line", async function listener(str) { |
| 29 |
if (!str) return; |
| 30 |
|
| 31 |
console.log(str); |
| 32 |
|
| 33 |
if ((await run.next(str)).done) { |
| 34 |
process.exit(0); |
| 35 |
} |
| 36 |
}); |
| 37 |
|
| 38 |
function logFile(file) { |
| 39 |
console.log("EXECUTOR", file, JSON.stringify(fs.readFileSync(file, "utf8"))); |
| 40 |
} |
| 41 |
|
| 42 |
setTimeout(() => { |
| 43 |
console.error("EXECUTOR TIMEOUT"); |
| 44 |
process.exit(1); |
| 45 |
}, 5000); |