2018-10-25 15:40:55 +00:00
|
|
|
import * as imports from '../../src/imports'
|
2018-10-25 07:43:42 +00:00
|
|
|
import Command from '../../src/command'
|
|
|
|
|
2018-10-25 15:40:55 +00:00
|
|
|
jest.mock('../../src/imports', () => {
|
|
|
|
return {
|
|
|
|
core: jest.fn().mockImplementation(() => ({
|
|
|
|
Nuxt: function () {}
|
|
|
|
})),
|
|
|
|
builder: jest.fn().mockImplementation(() => ({
|
|
|
|
Builder: function () {}
|
|
|
|
})),
|
|
|
|
generator: jest.fn().mockImplementation(() => ({
|
|
|
|
Generator: function () {}
|
|
|
|
})),
|
|
|
|
webpack: jest.fn().mockImplementation(() => ({
|
|
|
|
BundleBuilder: function () {}
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-25 07:43:42 +00:00
|
|
|
export const mockGetNuxt = (options, implementation) => {
|
|
|
|
Command.prototype.getNuxt = jest.fn().mockImplementationOnce(() => {
|
|
|
|
return Object.assign({
|
|
|
|
hook: jest.fn(),
|
|
|
|
options
|
|
|
|
}, implementation || {})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mockGetBuilder = (ret) => {
|
|
|
|
const build = jest.fn().mockImplementationOnce(() => {
|
|
|
|
return ret
|
|
|
|
})
|
|
|
|
|
|
|
|
Command.prototype.getBuilder = jest.fn().mockImplementationOnce(() => {
|
|
|
|
return { build }
|
|
|
|
})
|
|
|
|
|
|
|
|
return build
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mockGetGenerator = (ret) => {
|
|
|
|
const generate = jest.fn()
|
|
|
|
if (ret) {
|
|
|
|
generate.mockImplementationOnce(() => {
|
|
|
|
return ret
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
Command.prototype.getGenerator = jest.fn().mockImplementationOnce(() => {
|
|
|
|
return { generate }
|
|
|
|
})
|
|
|
|
|
|
|
|
return generate
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mockGetNuxtStart = (ssr) => {
|
|
|
|
const listen = jest.fn().mockImplementationOnce(() => {
|
|
|
|
return Promise.resolve()
|
|
|
|
})
|
|
|
|
|
|
|
|
mockGetNuxt({
|
|
|
|
rootDir: '.',
|
|
|
|
render: {
|
|
|
|
ssr
|
|
|
|
}
|
|
|
|
}, {
|
2018-10-30 20:42:53 +00:00
|
|
|
server: {
|
|
|
|
listen,
|
2018-11-08 09:15:56 +00:00
|
|
|
listeners: []
|
2018-10-30 20:42:53 +00:00
|
|
|
}
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|
|
|
|
|
2018-11-08 09:15:56 +00:00
|
|
|
return { listen }
|
2018-10-25 07:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const mockGetNuxtConfig = () => {
|
|
|
|
const spy = jest.fn()
|
|
|
|
Command.prototype.getNuxtConfig = spy
|
|
|
|
return spy
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mockNuxt = (implementation) => {
|
|
|
|
const Nuxt = function () {}
|
|
|
|
Object.assign(Nuxt.prototype, {
|
|
|
|
hook(type, fn) {
|
|
|
|
if (type === 'watch:fileChanged') {
|
|
|
|
Nuxt.fileChangedHook = fn
|
|
|
|
}
|
|
|
|
},
|
2018-11-08 09:15:56 +00:00
|
|
|
options: {},
|
2018-10-25 07:43:42 +00:00
|
|
|
clearHook: jest.fn(),
|
|
|
|
close: jest.fn(),
|
2018-12-01 10:13:28 +00:00
|
|
|
ready: jest.fn(),
|
2018-10-30 20:42:53 +00:00
|
|
|
server: {
|
2018-11-08 09:15:56 +00:00
|
|
|
listeners: [],
|
|
|
|
listen: jest.fn().mockImplementationOnce(() => Promise.resolve())
|
2018-10-30 20:42:53 +00:00
|
|
|
}
|
2018-10-25 07:43:42 +00:00
|
|
|
}, implementation || {})
|
|
|
|
|
2018-10-25 15:40:55 +00:00
|
|
|
imports.core.mockImplementation(() => ({ Nuxt }))
|
|
|
|
|
2018-10-25 07:43:42 +00:00
|
|
|
return Nuxt
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mockBuilder = (implementation) => {
|
|
|
|
const Builder = function () {}
|
|
|
|
Object.assign(Builder.prototype, {
|
|
|
|
build: jest.fn().mockImplementationOnce(() => Promise.resolve()),
|
|
|
|
unwatch: jest.fn().mockImplementationOnce(() => Promise.resolve()),
|
|
|
|
watchServer: jest.fn().mockImplementationOnce(() => Promise.resolve())
|
|
|
|
}, implementation || {})
|
|
|
|
|
2018-10-25 15:40:55 +00:00
|
|
|
imports.builder.mockImplementation(() => ({ Builder }))
|
|
|
|
|
2018-10-25 07:43:42 +00:00
|
|
|
return Builder
|
|
|
|
}
|