|
1 | 1 | import { expect } from 'chai' |
2 | | -import { net, session, ClientRequest } from 'electron' |
| 2 | +import { net as originalNet, session, ClientRequest } from 'electron' |
3 | 3 | import * as http from 'http' |
4 | 4 | import * as url from 'url' |
5 | 5 | import { AddressInfo } from 'net' |
6 | 6 |
|
| 7 | +const outstandingRequests: ClientRequest[] = [] |
| 8 | +const net: {request: (typeof originalNet)['request']} = { |
| 9 | + request: (...args) => { |
| 10 | + const r = originalNet.request(...args) |
| 11 | + outstandingRequests.push(r) |
| 12 | + return r |
| 13 | + } |
| 14 | +} |
| 15 | +const abortOutstandingRequests = () => { |
| 16 | + outstandingRequests.forEach(r => r.abort()) |
| 17 | + outstandingRequests.length = 0 |
| 18 | +} |
| 19 | + |
7 | 20 | const kOneKiloByte = 1024 |
8 | 21 | const kOneMegaByte = kOneKiloByte * kOneKiloByte |
9 | 22 |
|
@@ -57,6 +70,7 @@ respondOnce.toSingleURL = (fn: http.RequestListener) => { |
57 | 70 | } |
58 | 71 |
|
59 | 72 | describe('net module', () => { |
| 73 | + afterEach(abortOutstandingRequests) |
60 | 74 | describe('HTTP basics', () => { |
61 | 75 | it('should be able to issue a basic GET request', (done) => { |
62 | 76 | respondOnce.toSingleURL((request, response) => { |
|
0 commit comments