mirror of https://github.com/sundowndev/http.git
fix tests
parent
f11b43eaa5
commit
a1c85de06e
|
@ -33,6 +33,7 @@
|
||||||
"babel-eslint": "latest",
|
"babel-eslint": "latest",
|
||||||
"babel-jest": "latest",
|
"babel-jest": "latest",
|
||||||
"codecov": "latest",
|
"codecov": "latest",
|
||||||
|
"core-js": "2",
|
||||||
"eslint": "latest",
|
"eslint": "latest",
|
||||||
"eslint-config-standard": "latest",
|
"eslint-config-standard": "latest",
|
||||||
"eslint-plugin-import": "latest",
|
"eslint-plugin-import": "latest",
|
||||||
|
|
|
@ -4,26 +4,44 @@ const defaultConfig = require('./fixture/nuxt.config')
|
||||||
|
|
||||||
jest.setTimeout(60000)
|
jest.setTimeout(60000)
|
||||||
|
|
||||||
async function setupNuxt(config) {
|
async function setupMockNuxt(config) {
|
||||||
const nuxt = new Nuxt({
|
const nuxt = new Nuxt({
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
...config
|
...config,
|
||||||
|
_ready: false
|
||||||
})
|
})
|
||||||
|
|
||||||
// Spy addTemplate
|
|
||||||
nuxt.moduleContainer.addTemplate = jest.fn(nuxt.moduleContainer.addTemplate)
|
nuxt.moduleContainer.addTemplate = jest.fn(nuxt.moduleContainer.addTemplate)
|
||||||
|
|
||||||
|
await nuxt.ready()
|
||||||
|
|
||||||
const builder = new Builder(nuxt)
|
const builder = new Builder(nuxt)
|
||||||
|
|
||||||
await builder.validatePages()
|
await builder.validatePages()
|
||||||
await builder.generateRoutesAndFiles()
|
await builder.generateRoutesAndFiles()
|
||||||
nuxt.builder = builder
|
nuxt.builder = builder
|
||||||
|
|
||||||
|
return nuxt
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupNuxt(config) {
|
||||||
|
const nuxt = new Nuxt({
|
||||||
|
...defaultConfig,
|
||||||
|
...config,
|
||||||
|
_ready: false
|
||||||
|
})
|
||||||
|
|
||||||
|
jest.spyOn(nuxt.moduleContainer, 'addTemplate')
|
||||||
|
|
||||||
await nuxt.ready()
|
await nuxt.ready()
|
||||||
|
|
||||||
|
const builder = new Builder(nuxt)
|
||||||
|
nuxt.builder = builder
|
||||||
|
|
||||||
return nuxt
|
return nuxt
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
setupMockNuxt,
|
||||||
setupNuxt
|
setupNuxt
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,17 @@
|
||||||
const { setupNuxt } = require('./_utils')
|
const { setupMockNuxt } = require('./_utils')
|
||||||
|
|
||||||
describe('browserBaseURL', () => {
|
describe('browserBaseURL', () => {
|
||||||
let nuxt
|
let nuxt
|
||||||
|
|
||||||
test('setup', async () => {
|
beforeAll(async () => {
|
||||||
nuxt = await setupNuxt({
|
nuxt = await setupMockNuxt({
|
||||||
http: {
|
http: {
|
||||||
browserBaseURL: '/test_api'
|
browserBaseURL: '/test_api'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
test('browserBaseURL', () => {
|
||||||
await nuxt.close()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('custom', () => {
|
|
||||||
expect(nuxt.moduleContainer.addTemplate).toBeDefined()
|
expect(nuxt.moduleContainer.addTemplate).toBeDefined()
|
||||||
const call = nuxt.moduleContainer.addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js'))
|
const call = nuxt.moduleContainer.addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js'))
|
||||||
const options = call[0].options
|
const options = call[0].options
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
const { setupNuxt } = require('./_utils')
|
const { setupMockNuxt } = require('./_utils')
|
||||||
|
|
||||||
describe('empty config', () => {
|
describe('empty config', () => {
|
||||||
let nuxt
|
let nuxt
|
||||||
|
|
||||||
test('setup', async () => {
|
beforeAll(async () => {
|
||||||
nuxt = await setupNuxt({
|
nuxt = await setupMockNuxt({
|
||||||
http: {}
|
http: {}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await nuxt.close()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('preset baseURL and browserBaseURL', () => {
|
test('preset baseURL and browserBaseURL', () => {
|
||||||
expect(nuxt.moduleContainer.addTemplate).toBeDefined()
|
expect(nuxt.moduleContainer.addTemplate).toBeDefined()
|
||||||
const call = nuxt.moduleContainer.addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js'))
|
const call = nuxt.moduleContainer.addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js'))
|
||||||
|
|
|
@ -6,11 +6,11 @@ const url = path => `http://localhost:3000${path}`
|
||||||
describe('module', () => {
|
describe('module', () => {
|
||||||
let nuxt
|
let nuxt
|
||||||
|
|
||||||
test('setup', async () => {
|
beforeAll(async () => {
|
||||||
nuxt = await setupNuxt()
|
nuxt = await setupNuxt()
|
||||||
await nuxt.builder.build()
|
await nuxt.builder.build()
|
||||||
await nuxt.listen(3000)
|
await nuxt.listen(3000)
|
||||||
})
|
}, 60000)
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
|
@ -18,7 +18,7 @@ describe('module', () => {
|
||||||
|
|
||||||
test('baseURL', () => {
|
test('baseURL', () => {
|
||||||
expect(nuxt.moduleContainer.addTemplate).toBeDefined()
|
expect(nuxt.moduleContainer.addTemplate).toBeDefined()
|
||||||
const call = nuxt.moduleContainer.addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js'))
|
const call = nuxt.moduleContainer.addTemplate.calls.find(args => args[0].src.includes('plugin.js'))
|
||||||
const options = call[0].options
|
const options = call[0].options
|
||||||
expect(options.baseURL.toString()).toBe('http://localhost:3000/test_api')
|
expect(options.baseURL.toString()).toBe('http://localhost:3000/test_api')
|
||||||
expect(options.browserBaseURL.toString()).toBe('/test_api')
|
expect(options.browserBaseURL.toString()).toBe('/test_api')
|
||||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -2915,16 +2915,16 @@ core-js-pure@3.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.0.0.tgz#a5679adb4875427c8c0488afc93e6f5b7125859b"
|
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.0.0.tgz#a5679adb4875427c8c0488afc93e6f5b7125859b"
|
||||||
integrity sha512-yPiS3fQd842RZDgo/TAKGgS0f3p2nxssF1H65DIZvZv0Od5CygP8puHXn3IQiM/39VAvgCbdaMQpresrbGgt9g==
|
integrity sha512-yPiS3fQd842RZDgo/TAKGgS0f3p2nxssF1H65DIZvZv0Od5CygP8puHXn3IQiM/39VAvgCbdaMQpresrbGgt9g==
|
||||||
|
|
||||||
|
core-js@2, core-js@^2.6.5:
|
||||||
|
version "2.6.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.5.tgz#44bc8d249e7fb2ff5d00e0341a7ffb94fbf67895"
|
||||||
|
integrity sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A==
|
||||||
|
|
||||||
core-js@3.0.0:
|
core-js@3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.0.0.tgz#a8dbfa978d29bfc263bfb66c556d0ca924c28957"
|
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.0.0.tgz#a8dbfa978d29bfc263bfb66c556d0ca924c28957"
|
||||||
integrity sha512-WBmxlgH2122EzEJ6GH8o9L/FeoUKxxxZ6q6VUxoTlsE4EvbTWKJb447eyVxTEuq0LpXjlq/kCB2qgBvsYRkLvQ==
|
integrity sha512-WBmxlgH2122EzEJ6GH8o9L/FeoUKxxxZ6q6VUxoTlsE4EvbTWKJb447eyVxTEuq0LpXjlq/kCB2qgBvsYRkLvQ==
|
||||||
|
|
||||||
core-js@^2.6.5:
|
|
||||||
version "2.6.5"
|
|
||||||
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.5.tgz#44bc8d249e7fb2ff5d00e0341a7ffb94fbf67895"
|
|
||||||
integrity sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A==
|
|
||||||
|
|
||||||
core-util-is@1.0.2, core-util-is@~1.0.0:
|
core-util-is@1.0.2, core-util-is@~1.0.0:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
|
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
|
||||||
|
|
Loading…
Reference in New Issue