mirror of https://github.com/sundowndev/http.git
fix tests
parent
f11b43eaa5
commit
a1c85de06e
|
@ -33,6 +33,7 @@
|
|||
"babel-eslint": "latest",
|
||||
"babel-jest": "latest",
|
||||
"codecov": "latest",
|
||||
"core-js": "2",
|
||||
"eslint": "latest",
|
||||
"eslint-config-standard": "latest",
|
||||
"eslint-plugin-import": "latest",
|
||||
|
|
|
@ -4,26 +4,44 @@ const defaultConfig = require('./fixture/nuxt.config')
|
|||
|
||||
jest.setTimeout(60000)
|
||||
|
||||
async function setupNuxt(config) {
|
||||
async function setupMockNuxt(config) {
|
||||
const nuxt = new Nuxt({
|
||||
...defaultConfig,
|
||||
...config
|
||||
...config,
|
||||
_ready: false
|
||||
})
|
||||
|
||||
// Spy addTemplate
|
||||
nuxt.moduleContainer.addTemplate = jest.fn(nuxt.moduleContainer.addTemplate)
|
||||
|
||||
await nuxt.ready()
|
||||
|
||||
const builder = new Builder(nuxt)
|
||||
|
||||
await builder.validatePages()
|
||||
await builder.generateRoutesAndFiles()
|
||||
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()
|
||||
|
||||
const builder = new Builder(nuxt)
|
||||
nuxt.builder = builder
|
||||
|
||||
return nuxt
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setupMockNuxt,
|
||||
setupNuxt
|
||||
}
|
||||
|
|
|
@ -1,21 +1,17 @@
|
|||
const { setupNuxt } = require('./_utils')
|
||||
const { setupMockNuxt } = require('./_utils')
|
||||
|
||||
describe('browserBaseURL', () => {
|
||||
let nuxt
|
||||
|
||||
test('setup', async () => {
|
||||
nuxt = await setupNuxt({
|
||||
beforeAll(async () => {
|
||||
nuxt = await setupMockNuxt({
|
||||
http: {
|
||||
browserBaseURL: '/test_api'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await nuxt.close()
|
||||
})
|
||||
|
||||
test('custom', () => {
|
||||
test('browserBaseURL', () => {
|
||||
expect(nuxt.moduleContainer.addTemplate).toBeDefined()
|
||||
const call = nuxt.moduleContainer.addTemplate.mock.calls.find(args => args[0].src.includes('plugin.js'))
|
||||
const options = call[0].options
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
const { setupNuxt } = require('./_utils')
|
||||
const { setupMockNuxt } = require('./_utils')
|
||||
|
||||
describe('empty config', () => {
|
||||
let nuxt
|
||||
|
||||
test('setup', async () => {
|
||||
nuxt = await setupNuxt({
|
||||
beforeAll(async () => {
|
||||
nuxt = await setupMockNuxt({
|
||||
http: {}
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await nuxt.close()
|
||||
})
|
||||
|
||||
test('preset baseURL and browserBaseURL', () => {
|
||||
expect(nuxt.moduleContainer.addTemplate).toBeDefined()
|
||||
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', () => {
|
||||
let nuxt
|
||||
|
||||
test('setup', async () => {
|
||||
beforeAll(async () => {
|
||||
nuxt = await setupNuxt()
|
||||
await nuxt.builder.build()
|
||||
await nuxt.listen(3000)
|
||||
})
|
||||
}, 60000)
|
||||
|
||||
afterAll(async () => {
|
||||
await nuxt.close()
|
||||
|
@ -18,7 +18,7 @@ describe('module', () => {
|
|||
|
||||
test('baseURL', () => {
|
||||
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
|
||||
expect(options.baseURL.toString()).toBe('http://localhost:3000/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"
|
||||
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:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.0.0.tgz#a8dbfa978d29bfc263bfb66c556d0ca924c28957"
|
||||
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:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
|
||||
|
|
Loading…
Reference in New Issue