mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
fix(test): remove local paths
This commit is contained in:
parent
bd1ae0b9df
commit
d02eb2f958
@ -4,8 +4,8 @@ exports[`config: options should return default nuxt config 1`] = `
|
||||
Object {
|
||||
"ErrorPage": null,
|
||||
"__normalized__": true,
|
||||
"_nuxtConfigFile": "/mnt/c/Users/CDu/projects/github/nuxt.js/nuxt.config.js",
|
||||
"appTemplatePath": "/mnt/c/Users/CDu/projects/github/nuxt.js/.nuxt/views/app.template.html",
|
||||
"_nuxtConfigFile": "/var/nuxt/test/nuxt.config.js",
|
||||
"appTemplatePath": "/var/nuxt/test/.nuxt/views/app.template.html",
|
||||
"build": Object {
|
||||
"_publicPath": "/_nuxt/",
|
||||
"analyze": false,
|
||||
@ -134,7 +134,7 @@ Object {
|
||||
"useForkTsChecker": false,
|
||||
"watch": Array [],
|
||||
},
|
||||
"buildDir": "/mnt/c/Users/CDu/projects/github/nuxt.js/.nuxt",
|
||||
"buildDir": "/var/nuxt/test/.nuxt",
|
||||
"cli": Object {
|
||||
"badgeMessages": Array [],
|
||||
},
|
||||
@ -158,7 +158,7 @@ Object {
|
||||
],
|
||||
"generate": Object {
|
||||
"concurrency": 500,
|
||||
"dir": "/mnt/c/Users/CDu/projects/github/nuxt.js/dist",
|
||||
"dir": "/var/nuxt/test/dist",
|
||||
"fallback": "200.html",
|
||||
"interval": 0,
|
||||
"routes": Array [],
|
||||
@ -240,19 +240,6 @@ Object {
|
||||
},
|
||||
},
|
||||
"modules": Array [],
|
||||
"modulesDir": Array [
|
||||
"/mnt/c/Users/CDu/projects/github/nuxt.js/packages/config/test/node_modules",
|
||||
"/mnt/c/Users/CDu/projects/github/nuxt.js/packages/config/node_modules",
|
||||
"/mnt/c/Users/CDu/projects/github/nuxt.js/packages/node_modules",
|
||||
"/mnt/c/Users/CDu/projects/github/nuxt.js/node_modules",
|
||||
"/mnt/c/Users/CDu/projects/github/node_modules",
|
||||
"/mnt/c/Users/CDu/projects/node_modules",
|
||||
"/mnt/c/Users/CDu/node_modules",
|
||||
"/mnt/c/Users/node_modules",
|
||||
"/mnt/c/node_modules",
|
||||
"/mnt/node_modules",
|
||||
"/node_modules",
|
||||
],
|
||||
"plugins": Array [],
|
||||
"render": Object {
|
||||
"bundleRenderer": Object {
|
||||
@ -292,7 +279,7 @@ Object {
|
||||
"prefix": true,
|
||||
},
|
||||
},
|
||||
"rootDir": "/mnt/c/Users/CDu/projects/github/nuxt.js",
|
||||
"rootDir": "/var/nuxt/test",
|
||||
"router": Object {
|
||||
"base": "/",
|
||||
"extendRoutes": null,
|
||||
@ -316,7 +303,7 @@ Object {
|
||||
"socket": undefined,
|
||||
},
|
||||
"serverMiddleware": Array [],
|
||||
"srcDir": "/mnt/c/Users/CDu/projects/github/nuxt.js",
|
||||
"srcDir": "/var/nuxt/test",
|
||||
"styleExtensions": Array [
|
||||
"css",
|
||||
"pcss",
|
||||
@ -343,7 +330,7 @@ Object {
|
||||
},
|
||||
},
|
||||
"watch": Array [
|
||||
"/mnt/c/Users/CDu/projects/github/nuxt.js/nuxt.config.js",
|
||||
"/var/nuxt/test/nuxt.config.js",
|
||||
],
|
||||
"watchers": Object {
|
||||
"chokidar": Object {
|
||||
|
@ -1,5 +1,17 @@
|
||||
import { getDefaultNuxtConfig } from '../../src/config'
|
||||
|
||||
jest.mock('std-env', () => ({
|
||||
browser: false,
|
||||
test: 'test',
|
||||
dev: false,
|
||||
production: true,
|
||||
debug: false,
|
||||
ci: true,
|
||||
windows: false,
|
||||
darwin: false,
|
||||
linux: true
|
||||
}))
|
||||
|
||||
describe('config', () => {
|
||||
test('should return default nuxt configurations', () => {
|
||||
expect(getDefaultNuxtConfig()).toMatchSnapshot()
|
||||
|
@ -1,23 +1,41 @@
|
||||
import path from 'path'
|
||||
import consola from 'consola'
|
||||
import { getNuxtConfig } from '../src/options'
|
||||
import * as options from '../src/options'
|
||||
|
||||
jest.mock('std-env', () => ({
|
||||
browser: false,
|
||||
test: 'test',
|
||||
dev: false,
|
||||
production: true,
|
||||
debug: false,
|
||||
ci: true,
|
||||
windows: false,
|
||||
darwin: false,
|
||||
linux: true
|
||||
}))
|
||||
|
||||
describe('config: options', () => {
|
||||
test('should return default nuxt config', () => {
|
||||
expect(getNuxtConfig({})).toMatchSnapshot()
|
||||
jest.spyOn(process, 'cwd').mockReturnValue('/var/nuxt/test')
|
||||
|
||||
const config = options.getNuxtConfig({})
|
||||
delete config.modulesDir
|
||||
expect(config).toMatchSnapshot()
|
||||
|
||||
process.cwd.mockRestore()
|
||||
})
|
||||
|
||||
test('should prevent duplicate calls with same options', () => {
|
||||
const options = {}
|
||||
const firstConfig = getNuxtConfig(options)
|
||||
const secondConfig = getNuxtConfig(firstConfig)
|
||||
const firstConfig = options.getNuxtConfig(options)
|
||||
const secondConfig = options.getNuxtConfig(firstConfig)
|
||||
|
||||
expect(firstConfig).toBe(secondConfig)
|
||||
expect(firstConfig.__normalized__).toBe(true)
|
||||
})
|
||||
|
||||
test('should return default loading when loading is true', () => {
|
||||
const { loading } = getNuxtConfig({ loading: true })
|
||||
const { loading } = options.getNuxtConfig({ loading: true })
|
||||
expect(loading).toEqual({
|
||||
color: 'black',
|
||||
failedColor: 'red',
|
||||
@ -31,7 +49,7 @@ describe('config: options', () => {
|
||||
})
|
||||
|
||||
test('should transform transition/layoutTransition to name', () => {
|
||||
const { transition, layoutTransition } = getNuxtConfig({
|
||||
const { transition, layoutTransition } = options.getNuxtConfig({
|
||||
transition: 'test-tran',
|
||||
layoutTransition: 'test-layout-tran'
|
||||
})
|
||||
@ -40,22 +58,22 @@ describe('config: options', () => {
|
||||
})
|
||||
|
||||
test('should transform extensions to array', () => {
|
||||
const { extensions } = getNuxtConfig({ extensions: 'ext' })
|
||||
const { extensions } = options.getNuxtConfig({ extensions: 'ext' })
|
||||
expect(extensions).toEqual(['js', 'mjs', 'ts', 'ext'])
|
||||
})
|
||||
|
||||
test('should support custom global name', () => {
|
||||
const { globalName } = getNuxtConfig({ globalName: 'globalNuxt' })
|
||||
const { globalName } = options.getNuxtConfig({ globalName: 'globalNuxt' })
|
||||
expect(globalName).toEqual('globalnuxt')
|
||||
})
|
||||
|
||||
test('should detect store dir', () => {
|
||||
const { store } = getNuxtConfig({ rootDir: path.resolve(__dirname, 'fixtures') })
|
||||
const { store } = options.getNuxtConfig({ rootDir: path.resolve(__dirname, 'fixtures') })
|
||||
expect(store).toEqual(true)
|
||||
})
|
||||
|
||||
test('should enable csp', () => {
|
||||
const { render: { csp } } = getNuxtConfig({ render: { csp: { allowedSources: true, test: true } } })
|
||||
const { render: { csp } } = options.getNuxtConfig({ render: { csp: { allowedSources: true, test: true } } })
|
||||
expect(csp).toEqual({
|
||||
hashAlgorithm: 'sha256',
|
||||
allowedSources: true,
|
||||
@ -66,39 +84,39 @@ describe('config: options', () => {
|
||||
})
|
||||
|
||||
test('should check unknown mode', () => {
|
||||
const { build, render } = getNuxtConfig({ mode: 'test' })
|
||||
const { build, render } = options.getNuxtConfig({ mode: 'test' })
|
||||
expect(consola.warn).toHaveBeenCalledWith('Unknown mode: test. Falling back to universal')
|
||||
expect(build.ssr).toEqual(true)
|
||||
expect(render.ssr).toEqual(true)
|
||||
})
|
||||
|
||||
test('should return 404.html as default generate.fallback', () => {
|
||||
const { generate: { fallback } } = getNuxtConfig({ generate: { fallback: true } })
|
||||
const { generate: { fallback } } = options.getNuxtConfig({ generate: { fallback: true } })
|
||||
expect(fallback).toEqual('404.html')
|
||||
})
|
||||
|
||||
describe('config: router dir', () => {
|
||||
test('should transform middleware to array', () => {
|
||||
const { router: { middleware } } = getNuxtConfig({ router: { middleware: 'midd' } })
|
||||
const { router: { middleware } } = options.getNuxtConfig({ router: { middleware: 'midd' } })
|
||||
expect(middleware).toEqual(['midd'])
|
||||
})
|
||||
|
||||
test('should set _routerBaseSpecified when base is specified', () => {
|
||||
const { _routerBaseSpecified } = getNuxtConfig({ router: { base: '/test' } })
|
||||
const { _routerBaseSpecified } = options.getNuxtConfig({ router: { base: '/test' } })
|
||||
expect(_routerBaseSpecified).toEqual(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('config: options dir', () => {
|
||||
test('should support custom root dir', () => {
|
||||
const { rootDir } = getNuxtConfig({
|
||||
const { rootDir } = options.getNuxtConfig({
|
||||
rootDir: 'root'
|
||||
})
|
||||
expect(rootDir).toEqual(path.resolve('root'))
|
||||
})
|
||||
|
||||
test('should support custom src dir', () => {
|
||||
const { srcDir } = getNuxtConfig({
|
||||
const { srcDir } = options.getNuxtConfig({
|
||||
rootDir: 'root',
|
||||
srcDir: 'src'
|
||||
})
|
||||
@ -106,7 +124,7 @@ describe('config: options', () => {
|
||||
})
|
||||
|
||||
test('should support custom generate dir', () => {
|
||||
const { generate: { dir } } = getNuxtConfig({
|
||||
const { generate: { dir } } = options.getNuxtConfig({
|
||||
rootDir: 'root',
|
||||
generate: { dir: 'generate' }
|
||||
})
|
||||
@ -116,41 +134,41 @@ describe('config: options', () => {
|
||||
|
||||
describe('config: options template', () => {
|
||||
test('should use default appTemplatePath', () => {
|
||||
const { appTemplatePath } = getNuxtConfig({})
|
||||
const { appTemplatePath } = options.getNuxtConfig({})
|
||||
expect(appTemplatePath).toEqual(path.resolve('.nuxt', 'views', 'app.template.html'))
|
||||
})
|
||||
|
||||
test('should use custom appTemplatePath', () => {
|
||||
const { appTemplatePath } = getNuxtConfig({ appTemplatePath: 'templates' })
|
||||
const { appTemplatePath } = options.getNuxtConfig({ appTemplatePath: 'templates' })
|
||||
expect(appTemplatePath).toEqual(path.resolve('templates'))
|
||||
})
|
||||
|
||||
test('should use custom app.html', () => {
|
||||
const { appTemplatePath } = getNuxtConfig({ rootDir: path.resolve(__dirname, 'fixtures') })
|
||||
const { appTemplatePath } = options.getNuxtConfig({ rootDir: path.resolve(__dirname, 'fixtures') })
|
||||
expect(appTemplatePath).toEqual(path.resolve(__dirname, 'fixtures', 'app.html'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('config: options publicPath', () => {
|
||||
test('should fallback to default when publicPath is falsy', () => {
|
||||
const { build: { publicPath } } = getNuxtConfig({ build: { publicPath: false } })
|
||||
const { build: { publicPath } } = options.getNuxtConfig({ build: { publicPath: false } })
|
||||
expect(publicPath).toEqual('/_nuxt/')
|
||||
})
|
||||
|
||||
test('should append slash in publicPath', () => {
|
||||
const { build: { publicPath } } = getNuxtConfig({ build: { publicPath: '/nuxt_public' } })
|
||||
const { build: { publicPath } } = options.getNuxtConfig({ build: { publicPath: '/nuxt_public' } })
|
||||
expect(publicPath).toEqual('/nuxt_public/')
|
||||
})
|
||||
|
||||
test('should ignore url publicPath in dev', () => {
|
||||
const { build: { publicPath } } = getNuxtConfig({ dev: true, build: { publicPath: 'http://nuxt_public' } })
|
||||
const { build: { publicPath } } = options.getNuxtConfig({ dev: true, build: { publicPath: 'http://nuxt_public' } })
|
||||
expect(publicPath).toEqual('/_nuxt/')
|
||||
})
|
||||
})
|
||||
|
||||
describe('config: options babel', () => {
|
||||
test('should replace and deprecate @nuxtjs/babel-preset-app', () => {
|
||||
const { build: { babel } } = getNuxtConfig({
|
||||
const { build: { babel } } = options.getNuxtConfig({
|
||||
build: { babel: { presets: ['@nuxtjs/babel-preset-app'] } }
|
||||
})
|
||||
expect(consola.warn).toHaveBeenCalledWith('@nuxtjs/babel-preset-app has been deprecated, please use @nuxt/babel-preset-app.')
|
||||
@ -162,7 +180,7 @@ describe('config: options', () => {
|
||||
})
|
||||
|
||||
test('should support options in babel presets', () => {
|
||||
const { build: { babel } } = getNuxtConfig({
|
||||
const { build: { babel } } = options.getNuxtConfig({
|
||||
build: { babel: { presets: [['@nuxt/babel-preset-app', { test: true }]] } }
|
||||
})
|
||||
expect(babel).toEqual({
|
||||
@ -175,17 +193,17 @@ describe('config: options', () => {
|
||||
|
||||
describe('config: options deprecated', () => {
|
||||
test('should deprecate render.gzip', () => {
|
||||
getNuxtConfig({ render: { gzip: true } })
|
||||
options.getNuxtConfig({ render: { gzip: true } })
|
||||
expect(consola.warn).toHaveBeenCalledWith('render.gzip is deprecated and will be removed in a future version! Please switch to render.compressor')
|
||||
})
|
||||
|
||||
test('should deprecate build.vendor', () => {
|
||||
getNuxtConfig({ build: { vendor: ['lodash'] } })
|
||||
options.getNuxtConfig({ build: { vendor: ['lodash'] } })
|
||||
expect(consola.warn).toHaveBeenCalledWith('vendor has been deprecated due to webpack4 optimization')
|
||||
})
|
||||
|
||||
test('should deprecate build.extractCSS.allChunks', () => {
|
||||
getNuxtConfig({ build: { extractCSS: { allChunks: true } } })
|
||||
options.getNuxtConfig({ build: { extractCSS: { allChunks: true } } })
|
||||
expect(consola.warn).toHaveBeenCalledWith('build.extractCSS.allChunks has no effect from v2.0.0. Please use build.optimization.splitChunks settings instead.')
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user