Skip to content

Commit

Permalink
test: add watcher setup waiting time
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Feb 18, 2022
1 parent d638da9 commit b187b0d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Expand Up @@ -4,15 +4,16 @@ const assert = require("assert");
// For Node.js <= 10
if (!assert.match) assert.match = (val, re) => assert(re.test(val));

const run = (function* () {
const run = (async function* () {
let files = [yield, yield].sort();
assert.match(files[0], /src[\\/]index.js -> lib[\\/]index.js/);
assert.match(files[1], /src[\\/]main.js -> lib[\\/]main.js/);
assert.match(yield, /Successfully compiled 2 files with Babel \(\d+ms\)\./);

logFile("lib/index.js");
logFile("lib/main.js");

// wait 200ms for watcher setup
await new Promise(resolve => setTimeout(resolve, 200));
fs.writeFileSync("./file.txt", "Updated!");

files = [yield, yield].sort();
Expand All @@ -29,7 +30,7 @@ run.next();
const batchedStrings = [];
let batchId = 0;

process.stdin.on("data", function listener(chunk) {
process.stdin.on("data", async function listener(chunk) {
const str = String(chunk).trim();
if (!str) return;

Expand All @@ -50,7 +51,7 @@ process.stdin.on("data", function listener(chunk) {
console.log(str);
}

if (run.next(str).done) {
if ((await run.next(str)).done) {
process.exit(0);
}
});
Expand Down
Expand Up @@ -2,5 +2,5 @@
"args": ["src", "--out-dir", "lib", "--watch", "--verbose"],
"noBabelrc": true,
"noDefaultPlugins": true,
"minNodeVersion": 8
"minNodeVersion": 10
}
Expand Up @@ -4,29 +4,30 @@ const assert = require("assert");
// For Node.js <= 10
if (!assert.match) assert.match = (val, re) => assert(re.test(val));

const run = function* () {
const run = (async function* () {
assert.match(yield, /Successfully compiled 2 files with Babel \(\d+ms\)\./);

logFile("lib/index.js");
logFile("lib/main.js");

// wait 200ms for watcher setup
await new Promise(resolve => setTimeout(resolve, 200));
fs.writeFileSync("./file.txt", "Updated!");

assert.match(yield, /Successfully compiled 2 files with Babel \(\d+ms\)\./);

logFile("lib/index.js");
logFile("lib/main.js");
}();
})();

run.next();

process.stdin.on("data", function listener(chunk) {
process.stdin.on("data", async function listener(chunk) {
const str = String(chunk).trim();
if (!str) return;

console.log(str);

if (run.next(str).done) {
if ((await run.next(str)).done) {
process.exit(0);
}
});
Expand Down
Expand Up @@ -2,5 +2,5 @@
"args": ["src", "--out-dir", "lib", "--watch"],
"noBabelrc": true,
"noDefaultPlugins": true,
"minNodeVersion": 8
"minNodeVersion": 10
}

0 comments on commit b187b0d

Please sign in to comment.