This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Patch captureStackTrace/prepareStackTrace to ZoneAwareError, pa…
…tch process.nextTick, fix removeAllListeners bug (#516) * fix long-stack-trace zone will not render correctly when reject a promise * fix issue #484 and #491, patch EventEmitter.once and removeAllListeners * add event emitter once test case * prependlistener should add listener at the beginning of the listener array. add test cases for prepend listener and once. * use newest fetch to test * patch process.nextTick * restore ZoneAwareError captureStackTrace function * move captureStackTrace test into node * use hasOwnProperty for check captureStackTrace exist or not * change var to const * add process.spec.ts into node_tests.ts target * add done in process.spec.ts * change var to let * add nexttick order case * add prepareStackTrace callback to ZoneAwareError * fix when EventEmitter removeAllListeners has no event type parameter, should remove all listeners * change some var to let/const, remove unnecessary cancelTask call * modify testcases * remove typo * use zone.scheduleMicrotask to patch process.nextTick * forget use let/const again * add comment to removeAllListeners patch, and remove useCapturing parameter cause it is not needed * update fetch to 2.0.1
- Loading branch information
1 parent
94c33d1
commit c36c0bc
Showing
8 changed files
with
226 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
describe('ZoneAwareError', () => { | ||
// If the environment does not supports stack rewrites, then these tests will fail | ||
// and there is no point in running them. | ||
if (!Error['stackRewrite']) return; | ||
|
||
it ('should have all properties from NativeError', () => { | ||
let obj: any = new Object(); | ||
Error.captureStackTrace(obj); | ||
expect(obj.stack).not.toBeUndefined(); | ||
}); | ||
|
||
it ('should support prepareStackTrace', () => { | ||
(<any>Error).prepareStackTrace = function(error, stack) { | ||
return stack; | ||
} | ||
let obj: any = new Object(); | ||
Error.captureStackTrace(obj); | ||
expect(obj.stack[0].getFileName()).not.toBeUndefined(); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
describe('process related test', () => { | ||
let zoneA, result; | ||
beforeEach(() => { | ||
zoneA = Zone.current.fork({name: 'zoneA'}); | ||
result = []; | ||
}); | ||
it('process.nextTick callback should in zone', (done) => { | ||
zoneA.run(function() { | ||
process.nextTick(() => { | ||
expect(Zone.current.name).toEqual('zoneA'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('process.nextTick should be excuted before macroTask and promise', (done) => { | ||
zoneA.run(function() { | ||
setTimeout(() => { | ||
result.push('timeout'); | ||
}, 0); | ||
process.nextTick(() => { | ||
result.push('tick'); | ||
}); | ||
setTimeout(() => { | ||
expect(result).toEqual(['tick', 'timeout']); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it ('process.nextTick should be treated as microTask', (done) => { | ||
let zoneTick = Zone.current.fork({ | ||
name: 'zoneTick', | ||
onScheduleTask: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): Task => { | ||
result.push( | ||
{ | ||
callback: 'scheduleTask', | ||
targetZone: targetZone.name, | ||
task: task.source | ||
}); | ||
return parentZoneDelegate.scheduleTask(targetZone, task); | ||
}, | ||
onInvokeTask: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task, applyThis?: any, applyArgs?: any): any => { | ||
result.push( | ||
{ | ||
callback: 'invokeTask', | ||
targetZone: targetZone.name, | ||
task: task.source | ||
}); | ||
return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs); | ||
} | ||
}); | ||
zoneTick.run(() => { | ||
process.nextTick(() => { | ||
result.push('tick'); | ||
}); | ||
}); | ||
setTimeout(() => { | ||
expect(result.length).toBe(3); | ||
expect(result[0]).toEqual( | ||
{ | ||
callback: 'scheduleTask', | ||
targetZone: 'zoneTick', | ||
task: 'nextTick' | ||
}); | ||
expect(result[1]).toEqual( | ||
{ | ||
callback: 'invokeTask', | ||
targetZone: 'zoneTick', | ||
task: 'nextTick' | ||
} | ||
); | ||
done(); | ||
}); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters