Skip to content

Commit 48538c8

Browse files
authored
Merge pull request #292 from sverweij/bugfix/correctly-call-statsync-when-there-are-no-options
fix: correctly call fs.statSync when there are no options
2 parents c4aa24d + 3643452 commit 48538c8

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

lib/SyncAsyncFileSystemDecorator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function SyncAsyncFileSystemDecorator(fs) {
3434
this.stat = (arg, options, callback) => {
3535
let result;
3636
try {
37-
result = fs.statSync(arg, options);
37+
result = callback ? fs.statSync(arg, options) : fs.statSync(arg);
3838
} catch (e) {
3939
return (callback || options)(e);
4040
}

test/SyncAsyncFileSystemDecorator.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
const should = require("should");
6+
const SyncAsyncFileSystemDecorator = require("../lib/SyncAsyncFileSystemDecorator");
7+
8+
describe("SyncAsyncFileSystemDecorator stat", function () {
9+
it("should use options when they're provided", function (done) {
10+
const decoratedFs = new SyncAsyncFileSystemDecorator(fs);
11+
decoratedFs.stat(
12+
path.join(__dirname, "fixtures", "decorated-fs", "exists.js"),
13+
{ bigint: true },
14+
function (error, result) {
15+
should(error).be.null();
16+
should(result).have.properties(["size", "birthtime"]);
17+
should(result.size).be.of.type("bigint");
18+
done();
19+
}
20+
);
21+
});
22+
23+
it("should work correctly when no options provided", function (done) {
24+
const decoratedFs = new SyncAsyncFileSystemDecorator(fs);
25+
decoratedFs.stat(
26+
path.join(__dirname, "fixtures", "decorated-fs", "exists.js"),
27+
function (error, result) {
28+
should(error).be.null();
29+
should(result).have.properties(["size", "birthtime"]);
30+
should(result.size).be.of.type("number");
31+
done();
32+
}
33+
);
34+
});
35+
});

test/fixtures/decorated-fs/exists.js

Whitespace-only changes.

0 commit comments

Comments
 (0)