From b187b0d730a249cbf046ffd93610d4693f75bc78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 18 Feb 2022 12:18:13 -0500 Subject: [PATCH] test: add watcher setup waiting time --- .../executor.js | 9 +++++---- .../options.json | 2 +- .../executor.js | 11 ++++++----- .../options.json | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch --verbose with external dependencies/executor.js b/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch --verbose with external dependencies/executor.js index 06acdf07b0cf..fcf460a0347b 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch --verbose with external dependencies/executor.js +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch --verbose with external dependencies/executor.js @@ -4,7 +4,7 @@ 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/); @@ -12,7 +12,8 @@ const run = (function* () { 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(); @@ -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; @@ -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); } }); diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch --verbose with external dependencies/options.json b/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch --verbose with external dependencies/options.json index 6fc02e90636e..b29801fb5518 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch --verbose with external dependencies/options.json +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch --verbose with external dependencies/options.json @@ -2,5 +2,5 @@ "args": ["src", "--out-dir", "lib", "--watch", "--verbose"], "noBabelrc": true, "noDefaultPlugins": true, - "minNodeVersion": 8 + "minNodeVersion": 10 } diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch with external dependencies/executor.js b/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch with external dependencies/executor.js index 474cd214405c..29730dc333e3 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch with external dependencies/executor.js +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch with external dependencies/executor.js @@ -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); } }); diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch with external dependencies/options.json b/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch with external dependencies/options.json index 290c3dcabb24..bb43a72b2540 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch with external dependencies/options.json +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --watch with external dependencies/options.json @@ -2,5 +2,5 @@ "args": ["src", "--out-dir", "lib", "--watch"], "noBabelrc": true, "noDefaultPlugins": true, - "minNodeVersion": 8 + "minNodeVersion": 10 }