Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better synchronization in
@babel/cli
interactive tests
- Loading branch information
1 parent
67006b4
commit 606d25f
Showing
3 changed files
with
82 additions
and
43 deletions.
There are no files selected for viewing
50 changes: 36 additions & 14 deletions
50
...est/fixtures/babel/dir --out-dir --watch --verbose with external dependencies/executor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,47 @@ | ||
const fs = require("fs"); | ||
const assert = require("assert"); | ||
|
||
// Wait for the initial build | ||
sleep(300); | ||
// For Node.js <= 10 | ||
if (!assert.match) assert.match = (val, re) => assert(re.test(val)); | ||
|
||
logFile("lib/index.js"); | ||
logFile("lib/main.js"); | ||
const run = (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\)\./); | ||
|
||
fs.writeFileSync("./file.txt", "Updated!"); | ||
logFile("lib/index.js"); | ||
logFile("lib/main.js"); | ||
|
||
// Wait for the new build | ||
sleep(300); | ||
fs.writeFileSync("./file.txt", "Updated!"); | ||
|
||
logFile("lib/index.js"); | ||
logFile("lib/main.js"); | ||
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"); | ||
})(); | ||
|
||
run.next(); | ||
|
||
process.stdin.on("data", function listener(chunk) { | ||
const str = String(chunk).trim(); | ||
if (!str) return; | ||
|
||
console.log(str); | ||
|
||
if (run.next(str).done) { | ||
process.exit(0); | ||
} | ||
}); | ||
|
||
function logFile(file) { | ||
console.log("EXECUTOR", file, JSON.stringify(fs.readFileSync(file, "utf8"))); | ||
} | ||
|
||
function sleep(ms) { | ||
const arr = new Int32Array(new SharedArrayBuffer(4)); | ||
arr[0] = 0; | ||
Atomics.wait(arr, 0, 0, ms); | ||
} | ||
setTimeout(() => { | ||
console.error("EXECUTOR TIMEOUT"); | ||
process.exit(1); | ||
}, 5000); |
44 changes: 30 additions & 14 deletions
44
...abel-cli/test/fixtures/babel/dir --out-dir --watch with external dependencies/executor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,41 @@ | ||
const fs = require("fs"); | ||
const assert = require("assert"); | ||
|
||
// Wait for the initial build | ||
sleep(300); | ||
// For Node.js <= 10 | ||
if (!assert.match) assert.match = (val, re) => assert(re.test(val)); | ||
|
||
logFile("lib/index.js"); | ||
logFile("lib/main.js"); | ||
const run = function* () { | ||
assert.match(yield, /Successfully compiled 2 files with Babel \(\d+ms\)\./); | ||
|
||
fs.writeFileSync("./file.txt", "Updated!"); | ||
logFile("lib/index.js"); | ||
logFile("lib/main.js"); | ||
|
||
// Wait for the new build | ||
sleep(300); | ||
fs.writeFileSync("./file.txt", "Updated!"); | ||
|
||
logFile("lib/index.js"); | ||
logFile("lib/main.js"); | ||
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) { | ||
const str = String(chunk).trim(); | ||
if (!str) return; | ||
|
||
console.log(str); | ||
|
||
if (run.next(str).done) { | ||
process.exit(0); | ||
} | ||
}); | ||
|
||
function logFile(file) { | ||
console.log("EXECUTOR", file, JSON.stringify(fs.readFileSync(file, "utf8"))); | ||
} | ||
|
||
function sleep(ms) { | ||
const arr = new Int32Array(new SharedArrayBuffer(4)); | ||
arr[0] = 0; | ||
Atomics.wait(arr, 0, 0, ms); | ||
} | ||
setTimeout(() => { | ||
console.error("EXECUTOR TIMEOUT"); | ||
process.exit(1); | ||
}, 5000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters