Skip to content

Commit 7c9420f

Browse files
authored
Merge pull request #104 from ConsenSys/fix-103
url.URL -> URL
2 parents 931c534 + e4ee448 commit 7c9420f

File tree

7 files changed

+32
-20
lines changed

7 files changed

+32
-20
lines changed

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const url = require('url')
1+
var URL
2+
URL = URL || require('url').URL
23

34
const requester = require('./lib/requester')
45
const simpleRequester = require('./lib/simpleRequester')
@@ -34,7 +35,7 @@ class Client {
3435
throw 'Please provide an Ethereum address and a password.'
3536
}
3637

37-
const apiUrl = new url.URL(inputApiUrl)
38+
const apiUrl = new URL(inputApiUrl)
3839
if (!apiUrl.hostname) {
3940
throw new TypeError(`${inputApiUrl} is not a valid URL`)
4041
}
@@ -343,7 +344,7 @@ module.exports.mythXToolUse = (toolNames, inputApiUrl = defaultApiUrl) => {
343344
}
344345

345346
module.exports.Client = Client
346-
module.exports.defaultApiUrl = new url.URL(defaultApiUrl)
347+
module.exports.defaultApiUrl = new URL(defaultApiUrl)
347348
module.exports.defaultApiHost = defaultApiUrl
348349
module.exports.defaultApiVersion = defaultApiVersion
349350
module.exports.defaultInitialDelay = defaultInitialDelay

lib/util.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const url = require('url')
1+
var URL
2+
URL = URL || require('url').URL
23

34
/**
45
* Wait for the specified time.
@@ -10,6 +11,6 @@ exports.timer = async time =>
1011
new Promise(resolve => setTimeout(resolve, time))
1112

1213
exports.joinUrl = (base, path) => {
13-
const u = new url.URL(path, base)
14+
const u = new URL(path, base)
1415
return u.href
1516
}

test/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
var URL
2+
URL = URL || require('url').URL
3+
14
const armlet = require('../index')
25
const Client = require('../index').Client
36
const sinon = require('sinon')
4-
const url = require('url')
57
const HttpErrors = require('http-errors')
68
require('chai')
79
.use(require('chai-as-promised'))
@@ -64,7 +66,7 @@ describe('main module', () => {
6466
it('initialize apiUrl to the given value', () => {
6567
const instance = new Client({ ethAddress, password }, apiUrl)
6668

67-
instance.apiUrl.should.be.deep.equal(new url.URL(apiUrl))
69+
instance.apiUrl.should.be.deep.equal(new URL(apiUrl))
6870
})
6971

7072
describe('instances should', () => {
@@ -168,7 +170,7 @@ describe('main module', () => {
168170
describe('functionality', () => {
169171
const uuid = 'analysis-uuid'
170172
const issues = ['issue1', 'issue2']
171-
const parsedApiUrl = new url.URL(apiUrl)
173+
const parsedApiUrl = new URL(apiUrl)
172174
const refreshToken = 'refresh-token'
173175
const accessToken = 'access-token'
174176

test/lib/analysisPoller.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
var URL
2+
URL = URL || require('url').URL
3+
14
const nock = require('nock')
2-
const url = require('url')
35
const sinon = require('sinon')
46
require('chai')
57
.use(require('chai-as-promised'))
@@ -10,7 +12,7 @@ const util = require('../../lib/util')
1012

1113
describe('analysisPoller', () => {
1214
describe('#do', () => {
13-
const apiUrl = new url.URL('https://api.mythx.io')
15+
const apiUrl = new URL('https://api.mythx.io')
1416
const validApiKey = 'valid-api-key'
1517
const uuid = 'my-uuid'
1618
const statusUrl = `/v1/analyses/${uuid}`

test/lib/login.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
var URL
2+
URL = URL || require('url').URL
3+
14
const nock = require('nock')
2-
const url = require('url')
35
require('chai')
46
.use(require('chai-as-promised'))
57
.should()
@@ -9,7 +11,7 @@ const login = require('../../lib/login')
911
describe('login', () => {
1012
describe('#do', () => {
1113
const apiUrl = 'https://localhost:3100'
12-
const parsedApiUrl = new url.URL(apiUrl)
14+
const parsedApiUrl = new URL(apiUrl)
1315
const ethAddress = '0x74B904af705Eb2D5a6CDc174c08147bED478a60d'
1416
const password = 'password'
1517
const auth = { ethAddress, password }
@@ -31,7 +33,7 @@ describe('login', () => {
3133
.post(loginPath, auth)
3234
.reply(200, jsonTokens)
3335

34-
const parsedApiUrlHttp = new url.URL('http://localhost:3100')
36+
const parsedApiUrlHttp = new URL('http://localhost:3100')
3537
await login.do(ethAddress, password, parsedApiUrlHttp)
3638
.should.eventually.deep.equal(jsonTokens)
3739
})

test/lib/refresh.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
var URL
2+
URL = URL || require('url').URL
3+
14
const nock = require('nock')
2-
const url = require('url')
35
require('chai')
46
.use(require('chai-as-promised'))
57
.should()
@@ -9,7 +11,7 @@ const refresh = require('../../lib/refresh')
911
describe('refresh', () => {
1012
describe('#do', () => {
1113
const apiUrl = 'https://localhost:3100'
12-
const parsedApiUrl = new url.URL(apiUrl)
14+
const parsedApiUrl = new URL(apiUrl)
1315
const refreshPath = '/v1/auth/refresh'
1416
const expiredRefreshToken = 'expiredRefresh'
1517
const expiredAccessToken = 'expiredAccess'

test/lib/requester.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
var URL
2+
URL = URL || require('url').URL
3+
14
const nock = require('nock')
2-
const url = require('url')
35
require('chai')
46
.use(require('chai-as-promised'))
57
.should()
@@ -8,9 +10,9 @@ const requester = require('../../lib/requester')
810

911
describe('requester', () => {
1012
describe('#do', () => {
11-
const defaultApiUrl = new url.URL('https://api.mythx.io')
12-
const httpApiUrl = new url.URL('http://localhost:3100')
13-
const httpsApiUrl = new url.URL('https://localhost:3100')
13+
const defaultApiUrl = new URL('https://api.mythx.io')
14+
const httpApiUrl = new URL('http://localhost:3100')
15+
const httpsApiUrl = new URL('https://localhost:3100')
1416

1517
const validApiKey = 'valid-api-key'
1618
const uuid = 'my-uuid'
@@ -72,7 +74,7 @@ describe('requester', () => {
7274
})
7375

7476
it('should reject on api server connection failure', async () => {
75-
const invalidApiHostname = new url.URL('http://not-a-valid-hostname')
77+
const invalidApiHostname = new URL('http://not-a-valid-hostname')
7678

7779
await requester.do(data, validApiKey, invalidApiHostname).should.be.rejectedWith(Error)
7880
})

0 commit comments

Comments
 (0)