1
0
mirror of synced 2025-12-19 18:11:23 -05:00
Files
blitz/packages/file-pipeline/src/helpers/idle-handler/idle-handler.test.ts
Justin Hall b3814fc7c0 Standardize prettier options across all Blitz code bases (#703)
Co-authored-by: Brandon Bayer <b@bayer.ws> (meta)
2020-06-19 09:33:57 +07:00

36 lines
924 B
TypeScript

import {createIdleHandler} from "."
import {pipeline, through} from "../../streams"
import {testStreamItems} from "../../test-utils"
import {IDLE, READY} from "../../events"
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
describe("idlehander", () => {
it("should fire the idle event", async () => {
// Setup an input stream
const input = through.obj()
const bus = through.obj()
// setup the test pipeline
const idleHandler = createIdleHandler(bus, 100)
pipeline(input, idleHandler.stream)
const arr = [1, 2, 3, 4]
for (const item of arr) {
input.write(item)
}
await sleep(150)
for (const item of arr) {
input.write(item)
}
input.write("ready")
await sleep(150)
for (const item of arr) {
input.write(item)
}
await testStreamItems(bus, [{type: IDLE}, {type: READY}, {type: IDLE}], (a) => a)
})
})