@ -19,7 +19,9 @@ describe('ZoneAwareError', () => {
|
||||
|
||||
it('should support prepareStackTrace', () => {
|
||||
const originalPrepareStackTrace = (<any>Error).prepareStackTrace;
|
||||
(<any>Error).prepareStackTrace = function(error: Error, stack: string) { return stack; };
|
||||
(<any>Error).prepareStackTrace = function(error: Error, stack: string) {
|
||||
return stack;
|
||||
};
|
||||
let obj: any = new Object();
|
||||
Error.captureStackTrace(obj);
|
||||
expect(obj.stack[0].getFileName()).not.toBeUndefined();
|
||||
@ -28,7 +30,9 @@ describe('ZoneAwareError', () => {
|
||||
|
||||
it('should not add additional stacktrace from Zone when use prepareStackTrace', () => {
|
||||
const originalPrepareStackTrace = (<any>Error).prepareStackTrace;
|
||||
(<any>Error).prepareStackTrace = function(error: Error, stack: string) { return stack; };
|
||||
(<any>Error).prepareStackTrace = function(error: Error, stack: string) {
|
||||
return stack;
|
||||
};
|
||||
let obj: any = new Object();
|
||||
Error.captureStackTrace(obj);
|
||||
expect(obj.stack.length).not.toBe(0);
|
||||
|
@ -16,7 +16,9 @@ describe('node console', () => {
|
||||
}
|
||||
});
|
||||
|
||||
beforeEach(() => { log.length = 0; });
|
||||
beforeEach(() => {
|
||||
log.length = 0;
|
||||
});
|
||||
|
||||
it('console methods should run in root zone', () => {
|
||||
zone.run(() => {
|
||||
|
@ -28,11 +28,17 @@ describe('nodejs EventEmitter', () => {
|
||||
expect(value).toBe('test value');
|
||||
}
|
||||
|
||||
function listenerA() { zoneResults.push('A'); }
|
||||
function listenerA() {
|
||||
zoneResults.push('A');
|
||||
}
|
||||
|
||||
function listenerB() { zoneResults.push('B'); }
|
||||
function listenerB() {
|
||||
zoneResults.push('B');
|
||||
}
|
||||
|
||||
function shouldNotRun() { fail('this listener should not run'); }
|
||||
function shouldNotRun() {
|
||||
fail('this listener should not run');
|
||||
}
|
||||
|
||||
it('should register listeners in the current zone', () => {
|
||||
zoneA.run(() => {
|
||||
@ -68,12 +74,19 @@ describe('nodejs EventEmitter', () => {
|
||||
});
|
||||
});
|
||||
it('should return all listeners for an event', () => {
|
||||
zoneA.run(() => { emitter.on('test', expectZoneA); });
|
||||
zoneB.run(() => { emitter.on('test', shouldNotRun); });
|
||||
zoneA.run(() => {
|
||||
emitter.on('test', expectZoneA);
|
||||
});
|
||||
zoneB.run(() => {
|
||||
emitter.on('test', shouldNotRun);
|
||||
});
|
||||
expect(emitter.listeners('test')).toEqual([expectZoneA, shouldNotRun]);
|
||||
});
|
||||
it('should return empty array when an event has no listeners',
|
||||
() => { zoneA.run(() => { expect(emitter.listeners('test')).toEqual([]); }); });
|
||||
it('should return empty array when an event has no listeners', () => {
|
||||
zoneA.run(() => {
|
||||
expect(emitter.listeners('test')).toEqual([]);
|
||||
});
|
||||
});
|
||||
it('should prepend listener by order', () => {
|
||||
zoneA.run(() => {
|
||||
emitter.on('test', listenerA);
|
||||
@ -136,8 +149,9 @@ describe('nodejs EventEmitter', () => {
|
||||
emitter.on('removeListener', function(type: string, handler: any) {
|
||||
zoneResults.push('remove' + type);
|
||||
});
|
||||
emitter.on(
|
||||
'newListener', function(type: string, handler: any) { zoneResults.push('new' + type); });
|
||||
emitter.on('newListener', function(type: string, handler: any) {
|
||||
zoneResults.push('new' + type);
|
||||
});
|
||||
emitter.on('test', shouldNotRun);
|
||||
emitter.removeListener('test', shouldNotRun);
|
||||
expect(zoneResults).toEqual(['newtest', 'removetest']);
|
||||
@ -171,7 +185,9 @@ describe('nodejs EventEmitter', () => {
|
||||
});
|
||||
it('should not enter endless loop when register uncaughtException to process', () => {
|
||||
require('domain');
|
||||
zoneA.run(() => { process.on('uncaughtException', function() {}); });
|
||||
zoneA.run(() => {
|
||||
process.on('uncaughtException', function() {});
|
||||
});
|
||||
});
|
||||
it('should be able to addEventListener with symbol eventName', () => {
|
||||
zoneA.run(() => {
|
||||
|
@ -25,7 +25,9 @@ describe('nodejs file system', () => {
|
||||
const zoneASpec = {
|
||||
name: 'A',
|
||||
onScheduleTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
|
||||
Task => { return delegate.scheduleTask(targetZone, task); }
|
||||
Task => {
|
||||
return delegate.scheduleTask(targetZone, task);
|
||||
}
|
||||
};
|
||||
const zoneA = Zone.current.fork(zoneASpec);
|
||||
spyOn(zoneASpec, 'onScheduleTask').and.callThrough();
|
||||
@ -42,7 +44,9 @@ describe('nodejs file system', () => {
|
||||
const zoneASpec = {
|
||||
name: 'A',
|
||||
onScheduleTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
|
||||
Task => { return delegate.scheduleTask(targetZone, task); }
|
||||
Task => {
|
||||
return delegate.scheduleTask(targetZone, task);
|
||||
}
|
||||
};
|
||||
|
||||
it('fs.watch has been patched as eventTask', (done) => {
|
||||
@ -56,7 +60,9 @@ describe('nodejs file system', () => {
|
||||
expect(zoneASpec.onScheduleTask).toHaveBeenCalled();
|
||||
expect(Zone.current.name).toBe('A');
|
||||
watcher.close();
|
||||
unlink('testfile', () => { done(); });
|
||||
unlink('testfile', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
writeFile('testfile', 'test new content', () => {});
|
||||
});
|
||||
@ -74,7 +80,9 @@ describe('nodejs file system', () => {
|
||||
expect(zoneASpec.onScheduleTask).toHaveBeenCalled();
|
||||
expect(Zone.current.name).toBe('A');
|
||||
unwatchFile('testfile');
|
||||
unlink('testfile', () => { done(); });
|
||||
unlink('testfile', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
writeFile('testfile', 'test new content', () => {});
|
||||
});
|
||||
@ -92,7 +100,9 @@ describe('util.promisify', () => {
|
||||
expect(r).toBe(true);
|
||||
done();
|
||||
},
|
||||
err => { fail(`should not be here with error: ${err}`); });
|
||||
err => {
|
||||
fail(`should not be here with error: ${err}`);
|
||||
});
|
||||
});
|
||||
|
||||
it('fs.read should work with util.promisify', (done: DoneFn) => {
|
||||
|
@ -8,12 +8,16 @@
|
||||
const http = require('http');
|
||||
describe('http test', () => {
|
||||
it('http.request should be patched as eventTask', (done) => {
|
||||
const server = http.createServer((req: any, res: any) => { res.end(); });
|
||||
const server = http.createServer((req: any, res: any) => {
|
||||
res.end();
|
||||
});
|
||||
server.listen(9999, () => {
|
||||
const zoneASpec = {
|
||||
name: 'A',
|
||||
onScheduleTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
|
||||
Task => { return delegate.scheduleTask(targetZone, task); }
|
||||
Task => {
|
||||
return delegate.scheduleTask(targetZone, task);
|
||||
}
|
||||
};
|
||||
const zoneA = Zone.current.fork(zoneASpec);
|
||||
spyOn(zoneASpec, 'onScheduleTask').and.callThrough();
|
||||
@ -22,7 +26,9 @@ describe('http test', () => {
|
||||
http.request({hostname: 'localhost', port: '9999', method: 'GET'}, (res: any) => {
|
||||
expect(Zone.current.name).toEqual('A');
|
||||
expect(zoneASpec.onScheduleTask).toHaveBeenCalled();
|
||||
server.close(() => { done(); });
|
||||
server.close(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
req.end();
|
||||
});
|
||||
|
@ -24,8 +24,12 @@ describe('process related test', () => {
|
||||
});
|
||||
it('process.nextTick should be executed before macroTask and promise', (done) => {
|
||||
zoneA.run(function() {
|
||||
setTimeout(() => { result.push('timeout'); }, 0);
|
||||
process.nextTick(() => { result.push('tick'); });
|
||||
setTimeout(() => {
|
||||
result.push('timeout');
|
||||
}, 0);
|
||||
process.nextTick(() => {
|
||||
result.push('tick');
|
||||
});
|
||||
setTimeout(() => {
|
||||
expect(result).toEqual(['tick', 'timeout']);
|
||||
done();
|
||||
@ -35,18 +39,24 @@ describe('process related test', () => {
|
||||
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);
|
||||
}
|
||||
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');
|
||||
});
|
||||
});
|
||||
zoneTick.run(() => { process.nextTick(() => { result.push('tick'); }); });
|
||||
setTimeout(() => {
|
||||
expect(result.length).toBe(3);
|
||||
expect(result[0]).toEqual(
|
||||
@ -66,7 +76,9 @@ describe('process related test', () => {
|
||||
process.removeListener('unhandledRejection', listener);
|
||||
};
|
||||
process.on('unhandledRejection', listener);
|
||||
const p = new Promise((resolve, reject) => { throw new Error('promise error'); });
|
||||
const p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
expect(hookSpy).toHaveBeenCalledWith(p, 'promise error');
|
||||
@ -84,9 +96,13 @@ describe('process related test', () => {
|
||||
done();
|
||||
};
|
||||
process.on('rejectionHandled', listener);
|
||||
const p = new Promise((resolve, reject) => { throw new Error('promise error'); });
|
||||
const p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
});
|
||||
|
||||
setTimeout(function() { p.catch(reason => {}); }, 10);
|
||||
setTimeout(function() {
|
||||
p.catch(reason => {});
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
||||
@ -104,7 +120,9 @@ describe('process related test', () => {
|
||||
};
|
||||
process.on('unhandledRejection', listener1);
|
||||
process.on('unhandledRejection', listener2);
|
||||
const p = new Promise((resolve, reject) => { throw new Error('promise error'); });
|
||||
const p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
expect(hookSpy.calls.count()).toBe(2);
|
||||
|
@ -16,7 +16,9 @@ describe('node timer', () => {
|
||||
expect(value).toEqual('value');
|
||||
done();
|
||||
},
|
||||
error => { fail(`should not be here with error: ${error}.`); });
|
||||
error => {
|
||||
fail(`should not be here with error: ${error}.`);
|
||||
});
|
||||
});
|
||||
|
||||
it('util.promisify should work with setImmediate', (done: DoneFn) => {
|
||||
@ -26,6 +28,8 @@ describe('node timer', () => {
|
||||
expect(value).toEqual('value');
|
||||
done();
|
||||
},
|
||||
error => { fail(`should not be here with error: ${error}.`); });
|
||||
error => {
|
||||
fail(`should not be here with error: ${error}.`);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user