| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,73 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const fixtures = require('../common/fixtures'); | ||
| 5 | + const path = require('path'); | ||
| 6 | + const fs = require('fs'); | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + | ||
| 9 | + const tmpdir = require('../common/tmpdir'); | ||
| 10 | + tmpdir.refresh(); | ||
| 11 | + | ||
| 12 | + const streamOpts = ['open', 'close']; | ||
| 13 | + const writeStreamOptions = [...streamOpts, 'write']; | ||
| 14 | + const readStreamOptions = [...streamOpts, 'read']; | ||
| 15 | + const originalFs = { fs }; | ||
| 16 | + | ||
| 17 | + { | ||
| 18 | + const file = path.join(tmpdir.path, 'write-end-test0.txt'); | ||
| 19 | + | ||
| 20 | + writeStreamOptions.forEach((fn) => { | ||
| 21 | + const overrideFs = Object.assign({}, originalFs.fs, { [fn]: null }); | ||
| 22 | + if (fn === 'write') overrideFs.writev = null; | ||
| 23 | + | ||
| 24 | + const opts = { | ||
| 25 | + fs: overrideFs | ||
| 26 | + }; | ||
| 27 | + assert.throws( | ||
| 28 | + () => fs.createWriteStream(file, opts), { | ||
| 29 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 30 | + name: 'TypeError', | ||
| 31 | + message: `The "options.fs.${fn}" property must be of type function. ` + | ||
| 32 | + 'Received null' | ||
| 33 | + }, | ||
| 34 | + `createWriteStream options.fs.${fn} should throw if isn't a function` | ||
| 35 | + ); | ||
| 36 | + }); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + { | ||
| 40 | + const file = path.join(tmpdir.path, 'write-end-test0.txt'); | ||
| 41 | + const overrideFs = Object.assign({}, originalFs.fs, { writev: 'not a fn' }); | ||
| 42 | + const opts = { | ||
| 43 | + fs: overrideFs | ||
| 44 | + }; | ||
| 45 | + assert.throws( | ||
| 46 | + () => fs.createWriteStream(file, opts), { | ||
| 47 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 48 | + name: 'TypeError', | ||
| 49 | + message: 'The "options.fs.writev" property must be of type function. ' + | ||
| 50 | + 'Received type string (\'not a fn\')' | ||
| 51 | + }, | ||
| 52 | + 'createWriteStream options.fs.writev should throw if isn\'t a function' | ||
| 53 | + ); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + { | ||
| 57 | + const file = fixtures.path('x.txt'); | ||
| 58 | + readStreamOptions.forEach((fn) => { | ||
| 59 | + const overrideFs = Object.assign({}, originalFs.fs, { [fn]: null }); | ||
| 60 | + const opts = { | ||
| 61 | + fs: overrideFs | ||
| 62 | + }; | ||
| 63 | + assert.throws( | ||
| 64 | + () => fs.createReadStream(file, opts), { | ||
| 65 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 66 | + name: 'TypeError', | ||
| 67 | + message: `The "options.fs.${fn}" property must be of type function. ` + | ||
| 68 | + 'Received null' | ||
| 69 | + }, | ||
| 70 | + `createReadStream options.fs.${fn} should throw if isn't a function` | ||
| 71 | + ); | ||
| 72 | + }); | ||
| 73 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments