|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +require('../common'); |
| 4 | +constfixtures=require('../common/fixtures'); |
| 5 | +constpath=require('path'); |
| 6 | +constfs=require('fs'); |
| 7 | +constassert=require('assert'); |
| 8 | + |
| 9 | +consttmpdir=require('../common/tmpdir'); |
| 10 | +tmpdir.refresh(); |
| 11 | + |
| 12 | +conststreamOpts=['open','close']; |
| 13 | +constwriteStreamOptions=[...streamOpts,'write']; |
| 14 | +constreadStreamOptions=[...streamOpts,'read']; |
| 15 | +constoriginalFs={ fs }; |
| 16 | + |
| 17 | +{ |
| 18 | +constfile=path.join(tmpdir.path,'write-end-test0.txt'); |
| 19 | + |
| 20 | +writeStreamOptions.forEach((fn)=>{ |
| 21 | +constoverrideFs=Object.assign({},originalFs.fs,{[fn]: null}); |
| 22 | +if(fn==='write')overrideFs.writev=null; |
| 23 | + |
| 24 | +constopts={ |
| 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 | +constfile=path.join(tmpdir.path,'write-end-test0.txt'); |
| 41 | +constoverrideFs=Object.assign({},originalFs.fs,{writev: 'not a fn'}); |
| 42 | +constopts={ |
| 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 | +constfile=fixtures.path('x.txt'); |
| 58 | +readStreamOptions.forEach((fn)=>{ |
| 59 | +constoverrideFs=Object.assign({},originalFs.fs,{[fn]: null}); |
| 60 | +constopts={ |
| 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 | +} |
0 commit comments