From 9ed8f3497c517bc534e637567c3a3a19c013e2dc Mon Sep 17 00:00:00 2001 From: Andrew Shanks Date: Wed, 3 Oct 2018 22:39:45 +0100 Subject: [PATCH] refactor: remove usage of assert from cache.js [#973] (#1043) * refactor: remove usage of assert from cache.js [#973] * refactor: remove usage of assert from no_proxy.spec.js [#973] * refactor: remove usage of assert from cache.js [#973] --- test/functional/uplinks/cache.js | 8 ++--- test/unit/api/no_proxy.spec.js | 51 ++++++++++++++++---------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/test/functional/uplinks/cache.js b/test/functional/uplinks/cache.js index cf36e7f14..db23b3f4c 100644 --- a/test/functional/uplinks/cache.js +++ b/test/functional/uplinks/cache.js @@ -1,6 +1,6 @@ import fs from 'fs'; import path from 'path'; -import assert from 'assert'; +import crypto from 'crypto'; import {readFile} from '../lib/test.utils'; import {HTTP_STATUS} from "../../../src/lib/constants"; import {TARBALL} from '../config.functional'; @@ -35,7 +35,7 @@ export default function (server, server2, server3) { beforeAll(function () { const pkg = require('../fixtures/package')(PKG_GH131); - pkg.dist.shasum = createTarballHash().update(getBinary()).digest('hex'); + pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex'); return server.putVersion(PKG_GH131, '0.0.1', pkg) .status(HTTP_STATUS.CREATED) @@ -52,7 +52,7 @@ export default function (server, server2, server3) { }); test('should be caching packages from uplink server1', () => { - assert.equal(isCached(PKG_GH131, TARBALL), true); + expect(isCached(PKG_GH131, TARBALL)).toEqual(true); }); beforeAll(function () { @@ -85,7 +85,7 @@ export default function (server, server2, server3) { }); test('must not be caching packages from uplink server2', () => { - assert.equal(isCached(PKG_GH1312, TARBALL), false); + expect(isCached(PKG_GH1312, TARBALL)).toEqual(false); }); }); diff --git a/test/unit/api/no_proxy.spec.js b/test/unit/api/no_proxy.spec.js index f8e9327d0..30854e936 100644 --- a/test/unit/api/no_proxy.spec.js +++ b/test/unit/api/no_proxy.spec.js @@ -1,4 +1,3 @@ -import assert from 'assert'; import Storage from '../../../src/lib/up-storage'; require('../../../src/lib/logger').setup([]); @@ -11,78 +10,78 @@ function setupProxy(host, config, mainconfig) { describe('Use proxy', () => { test('should work fine without proxy', () => { let x = setupProxy('http://x/x', {}, {}); - assert.equal(x.proxy, null); + expect(x.proxy).toEqual(undefined); }); test('local config should take priority', () => { let x = setupProxy('http://x/x', {http_proxy: '123'}, {http_proxy: '456'}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); }); test('no_proxy is invalid', () => { let x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: false}, {}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: null}, {}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: []}, {}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: ''}, {}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); }); test('no_proxy - simple/include', () => { let x = setupProxy('http://localhost', {http_proxy: '123'}, {no_proxy: 'localhost'}); - assert.equal(x.proxy, undefined); + expect(x.proxy).toEqual(undefined); }); test('no_proxy - simple/not', () => { let x = setupProxy('http://localhost', {http_proxy: '123'}, {no_proxy: 'blah'}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); }); test('no_proxy - various, single string', () => { let x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: 'blah'}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); x = setupProxy('http://blah.blah', {}, {http_proxy: '123', no_proxy: 'blah'}); - assert.equal(x.proxy, null); + expect(x.proxy).toEqual(undefined); x = setupProxy('http://blahblah', {}, {http_proxy: '123', no_proxy: '.blah'}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); x = setupProxy('http://blah.blah', {http_proxy: '123', no_proxy: '.blah'}, {}); - assert.equal(x.proxy, null); + expect(x.proxy).toEqual(undefined); x = setupProxy('http://blah', {http_proxy: '123', no_proxy: '.blah'}, {}); - assert.equal(x.proxy, null); + expect(x.proxy).toEqual(undefined); x = setupProxy('http://blahh', {http_proxy: '123', no_proxy: 'blah'}, {}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); }); test('no_proxy - various, array', () => { let x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); x = setupProxy('http://blah.blah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'}); - assert.equal(x.proxy, null); + expect(x.proxy).toEqual(undefined); x = setupProxy('http://blah.foo', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'}); - assert.equal(x.proxy, null); + expect(x.proxy).toEqual(undefined); x = setupProxy('http://foo.baz', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); x = setupProxy('http://blah.blah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']}); - assert.equal(x.proxy, null); + expect(x.proxy).toEqual(undefined); }); test('no_proxy - hostport', () => { let x = setupProxy('http://localhost:80', {http_proxy: '123'}, {no_proxy: 'localhost'}); - assert.equal(x.proxy, null); + expect(x.proxy).toEqual(undefined); x = setupProxy('http://localhost:8080', {http_proxy: '123'}, {no_proxy: 'localhost'}); - assert.equal(x.proxy, null); + expect(x.proxy).toEqual(undefined); }); test('no_proxy - secure', () => { let x = setupProxy('https://something', {http_proxy: '123'}, {}); - assert.equal(x.proxy, null); + expect(x.proxy).toEqual(undefined); x = setupProxy('https://something', {https_proxy: '123'}, {}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); x = setupProxy('https://something', {http_proxy: '456', https_proxy: '123'}, {}); - assert.equal(x.proxy, '123'); + expect(x.proxy).toEqual('123'); }); });