Skip to content

Commit 379ca70

Browse files
test: added
1 parent bb52bfc commit 379ca70

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

lib/CachedInputFileSystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ module.exports = class CachedInputFileSystem {
581581
this._realpathBackend = createBackend(
582582
duration,
583583
this.fileSystem.realpath,
584-
this.fileSystem.realpath,
584+
this.fileSystem.realpathSync,
585585
this.fileSystem
586586
);
587587
const realpath = this._realpathBackend.provide;

test/CachedInputFileSystem.test.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,90 @@ describe("CachedInputFileSystem OperationMergerBackend ('lstat' and 'lstatSync')
165165
});
166166
});
167167

168+
describe("CachedInputFileSystem OperationMergerBackend ('realpath' and 'realpathSync')", () => {
169+
let fs;
170+
171+
beforeEach(() => {
172+
fs = new CachedInputFileSystem(
173+
{
174+
realpath: function (path, options, callback) {
175+
if (!callback) {
176+
callback = options;
177+
options = undefined;
178+
}
179+
setTimeout(
180+
() =>
181+
callback(null, {
182+
path,
183+
options
184+
}),
185+
100
186+
);
187+
},
188+
realpathSync: function (path, options) {
189+
return {
190+
path,
191+
options
192+
};
193+
}
194+
},
195+
0
196+
);
197+
});
198+
afterEach(() => {
199+
fs.purge();
200+
});
201+
202+
it("should join accesses", function (done) {
203+
fs.realpath("a", function (err, result) {
204+
expect(result).toBeDefined();
205+
result.a = true;
206+
});
207+
fs.realpath("a", function (err, result) {
208+
expect(result).toBeDefined();
209+
expect(result.a).toBeDefined();
210+
done();
211+
});
212+
});
213+
214+
it("should not join accesses with options", function (done) {
215+
fs.realpath("a", function (err, result) {
216+
expect(result).toBeDefined();
217+
218+
result.a = true;
219+
220+
expect(result).toBeDefined();
221+
expect(result.path).toEqual("a");
222+
expect(result.options).toBeUndefined();
223+
});
224+
fs.realpath("a", { options: true }, function (err, result) {
225+
expect(result).toBeDefined();
226+
expect(result.a).toBeUndefined();
227+
expect(result.path).toEqual("a");
228+
expect(result.options).toMatchObject({ options: true });
229+
done();
230+
});
231+
});
232+
233+
it("should not cache accesses", function (done) {
234+
fs.realpath("a", function (err, result) {
235+
result.a = true;
236+
fs.realpath("a", function (err, result) {
237+
expect(result.a).toBeUndefined();
238+
done();
239+
});
240+
});
241+
});
242+
243+
it("should not cache sync accesses", () => {
244+
const result = fs.realpathSync("a");
245+
result.a = true;
246+
const result2 = fs.realpathSync("a");
247+
248+
expect(result2.a).toBeUndefined();
249+
});
250+
});
251+
168252
describe("CachedInputFileSystem CacheBackend", () => {
169253
let fs;
170254

0 commit comments

Comments
 (0)