parent
8de925c4c2
commit
1dc1ef6091
1 changed files with 15 additions and 1 deletions
|
@ -1,9 +1,22 @@
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { net, session, ClientRequest } from 'electron'
|
import { net as originalNet, session, ClientRequest } from 'electron'
|
||||||
import * as http from 'http'
|
import * as http from 'http'
|
||||||
import * as url from 'url'
|
import * as url from 'url'
|
||||||
import { AddressInfo } from 'net'
|
import { AddressInfo } from 'net'
|
||||||
|
|
||||||
|
const outstandingRequests: ClientRequest[] = []
|
||||||
|
const net: {request: (typeof originalNet)['request']} = {
|
||||||
|
request: (...args) => {
|
||||||
|
const r = originalNet.request(...args)
|
||||||
|
outstandingRequests.push(r)
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const abortOutstandingRequests = () => {
|
||||||
|
outstandingRequests.forEach(r => r.abort())
|
||||||
|
outstandingRequests.length = 0
|
||||||
|
}
|
||||||
|
|
||||||
const kOneKiloByte = 1024
|
const kOneKiloByte = 1024
|
||||||
const kOneMegaByte = kOneKiloByte * kOneKiloByte
|
const kOneMegaByte = kOneKiloByte * kOneKiloByte
|
||||||
|
|
||||||
|
@ -57,6 +70,7 @@ respondOnce.toSingleURL = (fn: http.RequestListener) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('net module', () => {
|
describe('net module', () => {
|
||||||
|
afterEach(abortOutstandingRequests)
|
||||||
describe('HTTP basics', () => {
|
describe('HTTP basics', () => {
|
||||||
it('should be able to issue a basic GET request', (done) => {
|
it('should be able to issue a basic GET request', (done) => {
|
||||||
respondOnce.toSingleURL((request, response) => {
|
respondOnce.toSingleURL((request, response) => {
|
||||||
|
|
Loading…
Reference in a new issue