Skip to content

Commit

Permalink
squash: adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LiviaMedeiros committed Sep 22, 2023
1 parent 7d40cb5 commit 27a0ad9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,17 @@ function openAsBlob(path, options, callback) {
validateObject(options, 'options');
const type = options.type || '';
validateString(type, 'options.type');
validateFunction(callback, 'cb');

let blob;
let cbError = null;
try {
blob = createBlobFromFilePath(pathModule.toNamespacedPath(path), { type });
} catch (err) {
// Permission errors should be thrown instead of being passed to callback
if (err.code === 'ERR_ACCESS_DENIED') {
throw err;
}
cbError = err;
}
callback(cbError, blob);
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/permission/fs-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const regularFile = __filename;
// fs.openAsBlob
{
assert.throws(() => {
fs.openAsBlob(blockedFile);
fs.openAsBlob(blockedFile, () => {});
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemRead',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-blob-file-backed.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
const { TextDecoder } = require('util');
const {
writeFileSync,
openAsBlob,
promises: { openAsBlob },
} = require('fs');

const {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-permission-fs-supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const supportedApis = [
...syncAndAsyncAPI('mkdir'),
...syncAndAsyncAPI('mkdtemp'),
...syncAndAsyncAPI('open'),
'openAsBlob',
...syncAndAsyncAPI('openAsBlob'),
...syncAndAsyncAPI('mkdtemp'),
...syncAndAsyncAPI('readdir'),
...syncAndAsyncAPI('readFile'),
Expand Down

0 comments on commit 27a0ad9

Please sign in to comment.