chore(fs/test): test createOutputStream
This commit is contained in:
parent
ee5f3fc68d
commit
ba35f51459
@ -40,6 +40,7 @@
|
||||
"@babel/plugin-proposal-function-bind": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"@babel/preset-flow": "^7.0.0",
|
||||
"async-iterator-to-stream": "^1.1.0",
|
||||
"babel-plugin-lodash": "^3.3.2",
|
||||
"cross-env": "^5.1.3",
|
||||
"dotenv": "^6.1.0",
|
||||
|
@ -1,7 +1,10 @@
|
||||
/* eslint-env jest */
|
||||
|
||||
import 'dotenv/config'
|
||||
import asyncIteratorToStream from 'async-iterator-to-stream'
|
||||
import getStream from 'get-stream'
|
||||
import { fromCallback } from 'promise-toolbox'
|
||||
import { pipeline } from 'readable-stream'
|
||||
import { tmpdir } from 'os'
|
||||
|
||||
import { getHandler } from '.'
|
||||
@ -23,6 +26,9 @@ const unsecureRandomBytes = n => {
|
||||
}
|
||||
|
||||
const TEST_DATA = unsecureRandomBytes(1024)
|
||||
const createTestDataStream = asyncIteratorToStream(function*() {
|
||||
yield TEST_DATA
|
||||
})
|
||||
|
||||
const rejectionOf = p =>
|
||||
p.then(
|
||||
@ -67,6 +73,25 @@ handlers.forEach(url => {
|
||||
handler.prefix = prefix
|
||||
})
|
||||
|
||||
describe('#createOutputStream()', () => {
|
||||
it('returns a writable stream', async () => {
|
||||
const stream = await handler.createOutputStream('file')
|
||||
await fromCallback(cb => pipeline(createTestDataStream(), stream, cb))
|
||||
await expect(await handler.readFile('file')).toEqual(TEST_DATA)
|
||||
})
|
||||
|
||||
it('works on an opened files', async () => {
|
||||
const fd = await handler.openFile('file', 'wx')
|
||||
try {
|
||||
const stream = await handler.createOutputStream(fd)
|
||||
await fromCallback(cb => pipeline(createTestDataStream(), stream, cb))
|
||||
} finally {
|
||||
await handler.closeFile(fd)
|
||||
}
|
||||
await expect(await handler.readFile('file')).toEqual(TEST_DATA)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#createReadStream()', () => {
|
||||
it(`should return a stream`, async () => {
|
||||
await handler.outputFile('file', TEST_DATA)
|
||||
|
@ -1468,7 +1468,7 @@ async-foreach@^0.1.3:
|
||||
resolved "https://registry.yarnpkg.com/async-foreach/-/async-foreach-0.1.3.tgz#36121f845c0578172de419a97dbeb1d16ec34542"
|
||||
integrity sha1-NhIfhFwFeBct5Bmpfb6x0W7DRUI=
|
||||
|
||||
async-iterator-to-stream@^1.0.1, async-iterator-to-stream@^1.0.2:
|
||||
async-iterator-to-stream@^1.0.1, async-iterator-to-stream@^1.0.2, async-iterator-to-stream@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/async-iterator-to-stream/-/async-iterator-to-stream-1.1.0.tgz#02ce9031de5efb36b2a5e82a0e280318cfd1a6eb"
|
||||
integrity sha512-ddF3u7ipixenFJsYCKqVR9tNdkIzd2j7JVg8QarqkfUl7UTR7nhJgc1Q+3ebP/5DNFhV9Co9F47FJjGpdc0PjQ==
|
||||
|
Loading…
Reference in New Issue
Block a user