Move onLine to utilities
This way it can be used by the tests when spawning code-server on a random port to look for the address.
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import * as cp from "child_process"
|
||||
import { generateUuid } from "../../../src/common/util"
|
||||
import * as util from "../../../src/node/util"
|
||||
|
||||
describe("getEnvPaths", () => {
|
||||
@ -397,3 +399,38 @@ describe("sanitizeString", () => {
|
||||
expect(util.sanitizeString(" ")).toBe("")
|
||||
})
|
||||
})
|
||||
|
||||
describe("onLine", () => {
|
||||
// Spawn a process that outputs anything given on stdin.
|
||||
let proc: cp.ChildProcess | undefined
|
||||
|
||||
beforeAll(() => {
|
||||
proc = cp.spawn("node", ["-e", 'process.stdin.setEncoding("utf8");process.stdin.on("data", console.log)'])
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
proc?.kill()
|
||||
})
|
||||
|
||||
it("should call with individual lines", async () => {
|
||||
const size = 100
|
||||
const received = new Promise<string[]>((resolve) => {
|
||||
const lines: string[] = []
|
||||
util.onLine(proc!, (line) => {
|
||||
lines.push(line)
|
||||
if (lines.length === size) {
|
||||
resolve(lines)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const expected: string[] = []
|
||||
for (let i = 0; i < size; ++i) {
|
||||
expected.push(generateUuid(i))
|
||||
}
|
||||
|
||||
proc?.stdin?.write(expected.join("\n"))
|
||||
|
||||
expect(await received).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user