Skip to content

Commit

Permalink
test: added
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Mar 6, 2024
1 parent bb52bfc commit 379ca70
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/CachedInputFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ module.exports = class CachedInputFileSystem {
this._realpathBackend = createBackend(
duration,
this.fileSystem.realpath,
this.fileSystem.realpath,
this.fileSystem.realpathSync,
this.fileSystem
);
const realpath = this._realpathBackend.provide;
Expand Down
84 changes: 84 additions & 0 deletions test/CachedInputFileSystem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,90 @@ describe("CachedInputFileSystem OperationMergerBackend ('lstat' and 'lstatSync')
});
});

describe("CachedInputFileSystem OperationMergerBackend ('realpath' and 'realpathSync')", () => {
let fs;

beforeEach(() => {
fs = new CachedInputFileSystem(
{
realpath: function (path, options, callback) {
if (!callback) {
callback = options;
options = undefined;
}
setTimeout(
() =>
callback(null, {
path,
options
}),
100
);
},
realpathSync: function (path, options) {
return {
path,
options
};
}
},
0
);
});
afterEach(() => {
fs.purge();
});

it("should join accesses", function (done) {
fs.realpath("a", function (err, result) {
expect(result).toBeDefined();
result.a = true;
});
fs.realpath("a", function (err, result) {
expect(result).toBeDefined();
expect(result.a).toBeDefined();
done();
});
});

it("should not join accesses with options", function (done) {
fs.realpath("a", function (err, result) {
expect(result).toBeDefined();

result.a = true;

expect(result).toBeDefined();
expect(result.path).toEqual("a");
expect(result.options).toBeUndefined();
});
fs.realpath("a", { options: true }, function (err, result) {
expect(result).toBeDefined();
expect(result.a).toBeUndefined();
expect(result.path).toEqual("a");
expect(result.options).toMatchObject({ options: true });
done();
});
});

it("should not cache accesses", function (done) {
fs.realpath("a", function (err, result) {
result.a = true;
fs.realpath("a", function (err, result) {
expect(result.a).toBeUndefined();
done();
});
});
});

it("should not cache sync accesses", () => {
const result = fs.realpathSync("a");
result.a = true;
const result2 = fs.realpathSync("a");

expect(result2.a).toBeUndefined();
});
});

describe("CachedInputFileSystem CacheBackend", () => {
let fs;

Expand Down

0 comments on commit 379ca70

Please sign in to comment.