2019-05-31 11:56:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2019-05-31 11:56:07 -04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
const http = require('http');
|
|
|
|
describe('http test', () => {
|
|
|
|
it('http.request should be patched as eventTask', (done) => {
|
2020-04-13 19:40:21 -04:00
|
|
|
const server = http.createServer((req: any, res: any) => {
|
|
|
|
res.end();
|
|
|
|
});
|
2019-05-31 11:56:07 -04:00
|
|
|
server.listen(9999, () => {
|
|
|
|
const zoneASpec = {
|
|
|
|
name: 'A',
|
|
|
|
onScheduleTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
|
2020-04-13 19:40:21 -04:00
|
|
|
Task => {
|
|
|
|
return delegate.scheduleTask(targetZone, task);
|
|
|
|
}
|
2019-05-31 11:56:07 -04:00
|
|
|
};
|
|
|
|
const zoneA = Zone.current.fork(zoneASpec);
|
|
|
|
spyOn(zoneASpec, 'onScheduleTask').and.callThrough();
|
|
|
|
zoneA.run(() => {
|
|
|
|
const req =
|
|
|
|
http.request({hostname: 'localhost', port: '9999', method: 'GET'}, (res: any) => {
|
|
|
|
expect(Zone.current.name).toEqual('A');
|
|
|
|
expect(zoneASpec.onScheduleTask).toHaveBeenCalled();
|
2020-04-13 19:40:21 -04:00
|
|
|
server.close(() => {
|
|
|
|
done();
|
|
|
|
});
|
2019-05-31 11:56:07 -04:00
|
|
|
});
|
|
|
|
req.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|