|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {closeSync, exists, fstatSync, openSync, read, unlink, unlinkSync, unwatchFile, watch, watchFile, write, writeFile} from 'fs'; |
| 9 | +import {closeSync, exists, fstatSync, openSync, read, realpath, unlink, unlinkSync, unwatchFile, watch, watchFile, write, writeFile} from 'fs'; |
10 | 10 | import url from 'url'; |
11 | 11 | import util from 'util'; |
12 | 12 |
|
@@ -41,6 +41,50 @@ describe('nodejs file system', () => { |
41 | 41 | }); |
42 | 42 | }); |
43 | 43 | }); |
| 44 | + |
| 45 | + it('has patched realpath as macroTask', (done) => { |
| 46 | + const testZoneSpec = { |
| 47 | + name: 'test', |
| 48 | + onScheduleTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): |
| 49 | + Task => { |
| 50 | + return delegate.scheduleTask(targetZone, task); |
| 51 | + } |
| 52 | + }; |
| 53 | + const testZone = Zone.current.fork(testZoneSpec); |
| 54 | + spyOn(testZoneSpec, 'onScheduleTask').and.callThrough(); |
| 55 | + testZone.run(() => { |
| 56 | + realpath('testfile', () => { |
| 57 | + expect(Zone.current).toBe(testZone); |
| 58 | + expect(testZoneSpec.onScheduleTask).toHaveBeenCalled(); |
| 59 | + done(); |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + // https://github.com/angular/angular/issues/45546 |
| 65 | + // Note that this is intentionally marked with `xit` because `realpath.native` |
| 66 | + // is patched by Bazel's `node_patches.js` and doesn't allow further patching |
| 67 | + // of `realpath.native` in unit tests. Essentially, there's no original delegate |
| 68 | + // for `realpath` because it's also patched. The code below functions correctly |
| 69 | + // in the actual production environment. |
| 70 | + xit('has patched realpath.native as macroTask', (done) => { |
| 71 | + const testZoneSpec = { |
| 72 | + name: 'test', |
| 73 | + onScheduleTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): |
| 74 | + Task => { |
| 75 | + return delegate.scheduleTask(targetZone, task); |
| 76 | + } |
| 77 | + }; |
| 78 | + const testZone = Zone.current.fork(testZoneSpec); |
| 79 | + spyOn(testZoneSpec, 'onScheduleTask').and.callThrough(); |
| 80 | + testZone.run(() => { |
| 81 | + realpath.native('testfile', () => { |
| 82 | + expect(Zone.current).toBe(testZone); |
| 83 | + expect(testZoneSpec.onScheduleTask).toHaveBeenCalled(); |
| 84 | + done(); |
| 85 | + }); |
| 86 | + }); |
| 87 | + }); |
44 | 88 | }); |
45 | 89 |
|
46 | 90 | describe('watcher related methods test', () => { |
@@ -108,6 +152,32 @@ describe('util.promisify', () => { |
108 | 152 | }); |
109 | 153 | }); |
110 | 154 |
|
| 155 | + it('fs.realpath should work with util.promisify', (done: DoneFn) => { |
| 156 | + const promisifyRealpath = util.promisify(realpath); |
| 157 | + promisifyRealpath(currentFile) |
| 158 | + .then( |
| 159 | + r => { |
| 160 | + expect(r).toBeDefined(); |
| 161 | + done(); |
| 162 | + }, |
| 163 | + err => { |
| 164 | + fail(`should not be here with error: ${err}`); |
| 165 | + }); |
| 166 | + }); |
| 167 | + |
| 168 | + it('fs.realpath.native should work with util.promisify', (done: DoneFn) => { |
| 169 | + const promisifyRealpathNative = util.promisify(realpath.native); |
| 170 | + promisifyRealpathNative(currentFile) |
| 171 | + .then( |
| 172 | + r => { |
| 173 | + expect(r).toBeDefined(); |
| 174 | + done(); |
| 175 | + }, |
| 176 | + err => { |
| 177 | + fail(`should not be here with error: ${err}`); |
| 178 | + }); |
| 179 | + }); |
| 180 | + |
111 | 181 | it('fs.read should work with util.promisify', (done: DoneFn) => { |
112 | 182 | const promisifyRead = util.promisify(read); |
113 | 183 | const fd = openSync(currentFile, 'r'); |
|
0 commit comments