Skip to content

Commit 613d0f1

Browse files
committed
unpatch: Restore the original require('fs').unpatch so multiple virtual fs implementations can layer over each other.
1 parent 733f1e8 commit 613d0f1

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/GitWrappedFs.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,17 @@ GitWrappedFs.patchInPlace = function (fs) {
197197
gitWrappedFs = new GitWrappedFs();
198198
_.extend(fs, gitWrappedFs);
199199
fs.unpatch = function () {
200+
if ('unpatch' in fsShallowCopy) {
201+
fs.unpatch = fsShallowCopy.unpatch;
202+
} else {
203+
delete fs.unpatch;
204+
}
200205
Object.keys(gitWrappedFs).forEach(function (propertyName) {
201206
if (propertyName in fsShallowCopy) {
202207
fs[propertyName] = fsShallowCopy[propertyName];
203208
} else {
204209
delete fs[propertyName];
205210
}
206211
});
207-
delete fs.unpatch;
208212
};
209213
};

test/GitWrappedFs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ describe('GitWrappedFs', function () {
145145

146146
describe('patching the built-in fs module "in-place"', function () {
147147
var originalReadFile = require('fs').readFile;
148+
require('fs').unpatch = 123;
148149
before(function () {
149150
GitWrappedFs.patchInPlace();
150151
});
@@ -177,8 +178,8 @@ describe('GitWrappedFs', function () {
177178

178179
after(function () {
179180
require('fs').unpatch();
180-
expect(require('fs'), 'not to have key', 'unpatch');
181181
expect(require('fs').readFile, 'to be', originalReadFile);
182+
expect(require('fs').unpatch, 'to equal', 123);
182183
});
183184
});
184185
});

0 commit comments

Comments
 (0)