diff --git a/tests/base/local_wiki.js b/tests/base/local_wiki.js index 84c9cb7..f8cc132 100644 --- a/tests/base/local_wiki.js +++ b/tests/base/local_wiki.js @@ -1,8 +1,10 @@ const { Mwn, log, expect, assert, sinon, verifyTokenAndSiteInfo } = require('./test_base'); +const localApiUrl = 'http://localhost:8080/api.php'; + const baseConfig = { silent: true, - apiUrl: 'http://localhost:8080/api.php', + apiUrl: localApiUrl, password: '12345678901234567890123456789012', userAgent: 'mwn (https://github.com/siddharthvp/mwn)', defaultParams: { @@ -30,4 +32,4 @@ async function setup() { async function teardown() {} // Export everything -module.exports = { Mwn, bot, bot2, log, expect, assert, sinon, setup, teardown }; +module.exports = { Mwn, bot, bot2, localApiUrl, log, expect, assert, sinon, setup, teardown }; diff --git a/tests/core.test.js b/tests/core.test.js index d8059e0..36c7c9c 100644 --- a/tests/core.test.js +++ b/tests/core.test.js @@ -4,7 +4,7 @@ const { MwnError } = require('../build/error'); const nock = require('nock'); const { expect, Mwn } = require('./base/test_base'); -const { bot, setup, teardown, sinon } = require('./base/local_wiki'); +const { bot, setup, teardown, sinon, localApiUrl } = require('./base/local_wiki'); describe('core', function () { this.timeout(5000); @@ -50,7 +50,7 @@ describe('core', function () { it('honours method passed in custom options', async function () { sinon.spy(Request.prototype, 'handlePost'); sinon.spy(Request.prototype, 'handleGet'); - let scope = nock('http://localhost:8080/api.php').post(/.*?/).times(1).reply(200, '{}'); + let scope = nock(localApiUrl).post(/.*?/).times(1).reply(200, '{}'); await bot.request({ action: 'query' }, { method: 'post' }); expect(Request.prototype.handlePost).to.have.been.calledOnce; expect(Request.prototype.handleGet).to.not.have.been.called; @@ -65,7 +65,7 @@ describe('core', function () { after('teardown', teardown); it('logs on network errors and retries them', async function () { - nock('http://localhost:8080/api.php', { allowUnmocked: true }).get(/.*?/).times(1).reply(500, 'body', {}); + nock(localApiUrl, { allowUnmocked: true }).get(/.*?/).times(1).reply(500, 'body', {}); sinon.spy(console, 'log'); await expect(bot.query({ action: 'query' })).to.be.eventually.deep.eq({ batchcomplete: true }); expect(console.log).to.have.been.calledTwice; diff --git a/tests/errors.test.js b/tests/errors.test.js index c0f8136..ef6594c 100644 --- a/tests/errors.test.js +++ b/tests/errors.test.js @@ -1,6 +1,6 @@ 'use strict'; -const { sinon, bot, bot2, expect, setup, teardown } = require('./base/local_wiki'); +const { sinon, bot, bot2, expect, setup, teardown, localApiUrl } = require('./base/local_wiki'); const nock = require('nock'); const { Request, Response } = require('../build/core'); const utils = require('../build/utils'); @@ -151,5 +151,5 @@ describe('testing for error recoveries', function () { }); function mockApi(times, body, headers) { - nock('http://localhost:8080/api.php', { allowUnmocked: true }).get(/.*?/).times(times).reply(200, body, headers); + nock(localApiUrl, { allowUnmocked: true }).get(/.*?/).times(times).reply(200, body, headers); }