-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for options.fs in fs streams
PR-URL: #33185 Reviewed-By: Adrian Estrada <edsadr@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
- Loading branch information
1 parent
edf75e4
commit 1766514
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const assert = require('assert'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
const streamOpts = ['open', 'close']; | ||
const writeStreamOptions = [...streamOpts, 'write']; | ||
const readStreamOptions = [...streamOpts, 'read']; | ||
const originalFs = { fs }; | ||
|
||
{ | ||
const file = path.join(tmpdir.path, 'write-end-test0.txt'); | ||
|
||
writeStreamOptions.forEach((fn) => { | ||
const overrideFs = Object.assign({}, originalFs.fs, { [fn]: null }); | ||
if (fn === 'write') overrideFs.writev = null; | ||
|
||
const opts = { | ||
fs: overrideFs | ||
}; | ||
assert.throws( | ||
() => fs.createWriteStream(file, opts), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError', | ||
message: `The "options.fs.${fn}" property must be of type function. ` + | ||
'Received null' | ||
}, | ||
`createWriteStream options.fs.${fn} should throw if isn't a function` | ||
); | ||
}); | ||
} | ||
|
||
{ | ||
const file = path.join(tmpdir.path, 'write-end-test0.txt'); | ||
const overrideFs = Object.assign({}, originalFs.fs, { writev: 'not a fn' }); | ||
const opts = { | ||
fs: overrideFs | ||
}; | ||
assert.throws( | ||
() => fs.createWriteStream(file, opts), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError', | ||
message: 'The "options.fs.writev" property must be of type function. ' + | ||
'Received type string (\'not a fn\')' | ||
}, | ||
'createWriteStream options.fs.writev should throw if isn\'t a function' | ||
); | ||
} | ||
|
||
{ | ||
const file = fixtures.path('x.txt'); | ||
readStreamOptions.forEach((fn) => { | ||
const overrideFs = Object.assign({}, originalFs.fs, { [fn]: null }); | ||
const opts = { | ||
fs: overrideFs | ||
}; | ||
assert.throws( | ||
() => fs.createReadStream(file, opts), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError', | ||
message: `The "options.fs.${fn}" property must be of type function. ` + | ||
'Received null' | ||
}, | ||
`createReadStream options.fs.${fn} should throw if isn't a function` | ||
); | ||
}); | ||
} |