Skip to content

Commit

Permalink
Completed tests for fsFileSaver
Browse files Browse the repository at this point in the history
  • Loading branch information
Luciano Mammino committed Jul 29, 2019
1 parent 29476ed commit d78953a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"proxyquire": "^2.1.1",
"tap": "^14.4.3",
"tap": "^14.5.0",
"tap-mocha-reporter": "^4.0.1"
},
"dependencies": {
Expand Down
56 changes: 28 additions & 28 deletions src/server/fsFileSaver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,31 @@ tap.test('fsFileSaver should reject if can\'t create the folder in the local fil
t.end()
})

// tap.test('fsFileSaver should reject if can\'t write data in the local filesystem', async (t) => {
// const readableStreamMock = {
// pipeline () {
// const args = [...arguments]
// const cb = args.unshift() // callback is the last argument
// for (const stream of args) {
// stream.destroy() // cleans up the passed streams
// }
// return cb(new Error(`Can't write on the filesystem`))
// }
// }
//
// const fileSaver = Proxyquire('./fsFileSaver', {
// 'readable-stream': readableStreamMock
// })
//
// const data = 'abcd'.repeat(10000)
//
// const dataStream = createReadableFromString(data)
// const savePath = os.tmpdir()
// const filename = `filerec-test-file-${~~(Math.random() * 999999)}.txt`
//
// await t.rejects(
// () => fileSaver(undefined, dataStream, savePath, filename),
// new Error(`Can't write on the filesystem`)
// )
// t.end()
// })
tap.test('fsFileSaver should reject if can\'t write data in the local filesystem', async (t) => {
const readableStreamMock = {
pipeline: function (stream1, stream2, cb) {
// cleans up the passed streams
stream1.destroy()
stream2.destroy()
// fakes an error by invoking the callback
return cb(new Error(`Can't write on the filesystem`))
}
}
readableStreamMock.pipeline['@global'] = true

const fileSaver = Proxyquire('./fsFileSaver', {
'readable-stream': readableStreamMock
})

const data = 'abcd'.repeat(10000)

const dataStream = createReadableFromString(data)
const savePath = os.tmpdir()
const filename = `filerec-test-file-${~~(Math.random() * 999999)}.txt`

await t.rejects(
() => fileSaver(undefined, dataStream, savePath, filename),
new Error(`Can't write on the filesystem`)
)
t.end()
})

0 comments on commit d78953a

Please sign in to comment.