forked from bazel-contrib/rules_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(builtin): patched methods accept Buffer and URL types
The node specification for `fs` methods lists possible types for `path` as string | Buffer | URL. However, because the `path.resolve` and `path.dirname` methods only accept strings, the patched `fs` methods errored if the path arg was a Buffer or URL. This would occur when calling `fs.rm`, for example.
- Loading branch information
Alek
committed
Aug 30, 2024
1 parent
55eab9f
commit 75e0a3e
Showing
3 changed files
with
120 additions
and
16 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
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
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,76 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']); | ||
|
||
describe('node fs function does not throw:', () => { | ||
const files = runfiles.resolvePackageRelative('dir_output') | ||
const filesBuf = Buffer.from(files); | ||
const filesUrl = new URL('file://' + files); | ||
const doNothingCallback = () => {} | ||
|
||
// listed in order of appearance in the patch file | ||
it('lstat', () => { | ||
expect(() => fs.lstat(files, doNothingCallback)).not.toThrow(); | ||
expect(() => fs.lstat(filesBuf, doNothingCallback)).not.toThrow(); | ||
expect(() => fs.lstat(filesUrl, doNothingCallback)).not.toThrow(); | ||
}); | ||
|
||
it('realpath', () => { | ||
expect(() => fs.realpath(files, undefined, doNothingCallback)).not.toThrow(); | ||
expect(() => fs.realpath(filesBuf, undefined, doNothingCallback)).not.toThrow(); | ||
expect(() => fs.realpath(filesUrl, undefined, doNothingCallback)).not.toThrow(); | ||
}); | ||
|
||
it('realpath.native', () => { | ||
expect(() => fs.realpath.native(files, undefined, doNothingCallback)).not.toThrow(); | ||
expect(() => fs.realpath.native(filesBuf, undefined, doNothingCallback)).not.toThrow(); | ||
expect(() => fs.realpath.native(filesUrl, undefined, doNothingCallback)).not.toThrow(); | ||
}); | ||
|
||
it('readlink', () => { | ||
expect(() => fs.readlink(files, undefined, doNothingCallback)).not.toThrow(); | ||
expect(() => fs.readlink(filesBuf, undefined, doNothingCallback)).not.toThrow(); | ||
expect(() => fs.readlink(filesUrl, undefined, doNothingCallback)).not.toThrow(); | ||
}); | ||
|
||
it('lstatSync', () => { | ||
expect(() => fs.lstatSync(files)).not.toThrow(); | ||
expect(() => fs.lstatSync(filesBuf)).not.toThrow(); | ||
expect(() => fs.lstatSync(filesUrl)).not.toThrow(); | ||
}); | ||
|
||
it('realpathSync', () => { | ||
expect(() => fs.realpathSync(files)).not.toThrow(); | ||
expect(() => fs.realpathSync(filesBuf)).not.toThrow(); | ||
expect(() => fs.realpathSync(filesUrl)).not.toThrow(); | ||
}); | ||
|
||
it('realpathSync.native', () => { | ||
expect(() => fs.realpathSync.native(files)).not.toThrow(); | ||
expect(() => fs.realpathSync.native(filesBuf)).not.toThrow(); | ||
expect(() => fs.realpathSync.native(filesUrl)).not.toThrow(); | ||
}); | ||
|
||
it('readlinkSync', () => { | ||
const symlinkPath = path.join(files, 'symlink'); | ||
fs.symlinkSync(files, symlinkPath); | ||
const symlinkPathBuf = Buffer.from(symlinkPath); | ||
const symlinkPathUrl = new URL(`file://${symlinkPath}`); | ||
expect(() => fs.readlinkSync(symlinkPath)).not.toThrow(); | ||
expect(() => fs.readlinkSync(symlinkPathBuf)).not.toThrow(); | ||
expect(() => fs.readlinkSync(symlinkPathUrl)).not.toThrow(); | ||
}); | ||
|
||
it('readdir', () => { | ||
expect(() => fs.readdir(files, undefined, doNothingCallback)).not.toThrow(); | ||
expect(() => fs.readdir(filesBuf, undefined, doNothingCallback)).not.toThrow(); | ||
expect(() => fs.readdir(filesUrl, undefined, doNothingCallback)).not.toThrow(); | ||
}); | ||
|
||
it('readdirSync', () => { | ||
expect(() => fs.readdirSync(files)).not.toThrow(); | ||
expect(() => fs.readdirSync(filesBuf)).not.toThrow(); | ||
expect(() => fs.readdirSync(filesUrl)).not.toThrow(); | ||
}); | ||
|
||
}); |