From 5e919381eb9e0472bc4b0f5b95a62b5deb3d71de Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 13 Aug 2017 18:17:38 +0430 Subject: [PATCH] coverage --- lib/index.js | 15 +++++++++------ test/axios.test.js | 11 +++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/index.js b/lib/index.js index ac31950..af4f931 100755 --- a/lib/index.js +++ b/lib/index.js @@ -3,13 +3,14 @@ const path = require('path') const { hostname } = require('os') const { URL } = require('whatwg-url') -const port = process.env.PORT || process.env.npm_package_config_nuxt_port || 3000 -let host = process.env.HOST || process.env.npm_package_config_nuxt_host || 'localhost' -if (host === '0.0.0.0') { - host = hostname() -} - module.exports = function nuxtAxios (moduleOptions) { + const port = process.env.PORT || process.env.npm_package_config_nuxt_port || 3000 + let host = process.env.HOST || process.env.npm_package_config_nuxt_host || 'localhost' + /* istanbul ignore if */ + if (host === '0.0.0.0') { + host = hostname() + } + // Apply defaults const defaults = { baseURL: `http://${host}:${port}/api`, @@ -23,10 +24,12 @@ module.exports = function nuxtAxios (moduleOptions) { const options = Object.assign({}, defaults, this.options.axios, moduleOptions) // Override env + /* istanbul ignore if */ if (process.env.API_URL) { options.baseURL = process.env.API_URL } + /* istanbul ignore if */ if (process.env.API_URL_BROWSER) { options.browserBaseURL = process.env.API_URL_BROWSER } diff --git a/test/axios.test.js b/test/axios.test.js index f923a64..328b8c9 100644 --- a/test/axios.test.js +++ b/test/axios.test.js @@ -1,10 +1,11 @@ -process.env.PORT = '5060' +jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000 +process.env.PORT = process.env.PORT || 5060 +process.env.NODE_ENV = 'production' + const { Nuxt, Builder } = require('nuxt') const axios = require('axios') const config = require('./fixture/nuxt.config') -process.env.NODE_ENV = 'production' - const url = path => `http://localhost:${process.env.PORT}${path}` describe('axios module', () => { @@ -12,8 +13,6 @@ describe('axios module', () => { let addTemplate beforeAll(async () => { - jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000 - config.modules.unshift(function () { addTemplate = this.addTemplate = jest.fn(this.addTemplate) }) @@ -31,7 +30,7 @@ describe('axios module', () => { let call = addTemplate.mock.calls.find(args => args[0].src.includes('plugin.template.js')) expect(call).toBeDefined() let options = call[0].options - expect(options.baseURL.toString()).toBe('http://localhost:5060/test_api') + expect(options.baseURL.toString()).toBe(`http://localhost:${process.env.PORT}/test_api`) expect(options.browserBaseURL.toString()).toBe('/test_api') })