mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
test: improve tests (#4237)
This commit is contained in:
parent
ec9724f712
commit
cf1aa1abc8
@ -14,6 +14,6 @@ describe('basic ssr', () => {
|
||||
test('/', async () => {
|
||||
expect(nuxt.options.head.title).toBe('Async Config!')
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<h1>I am ALIVE!</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>I am ALIVE!</h1>')
|
||||
})
|
||||
})
|
||||
|
@ -11,7 +11,7 @@ describe('basic config defaults', () => {
|
||||
test('modulesDir uses /node_modules as default if not set', () => {
|
||||
const options = getNuxtConfig({})
|
||||
const currentNodeModulesDir = resolve(__dirname, '..', '..', 'node_modules')
|
||||
expect(options.modulesDir.includes(currentNodeModulesDir)).toBe(true)
|
||||
expect(options.modulesDir).toContain(currentNodeModulesDir)
|
||||
})
|
||||
|
||||
test('vendor has been deprecated', () => {
|
||||
|
@ -85,7 +85,7 @@ describe('basic dev', () => {
|
||||
test('/stateless', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/stateless'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<h1>My component!</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>My component!</h1>')
|
||||
})
|
||||
|
||||
test('Check render:routeDone hook called', () => {
|
||||
|
@ -86,20 +86,20 @@ describe('basic generate', () => {
|
||||
test('/stateless', async () => {
|
||||
const window = await generator.nuxt.server.renderAndGetWindow(url('/stateless'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<h1>My component!</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>My component!</h1>')
|
||||
})
|
||||
|
||||
test('/store-module', async () => {
|
||||
const window = await generator.nuxt.server.renderAndGetWindow(url('/store-module'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<h1>mutated</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>mutated</h1>')
|
||||
})
|
||||
|
||||
test('/css', async () => {
|
||||
const window = await generator.nuxt.server.renderAndGetWindow(url('/css'))
|
||||
|
||||
const headHtml = window.document.head.innerHTML
|
||||
expect(headHtml.includes('.red{color:red')).toBe(true)
|
||||
expect(headHtml).toContain('.red{color:red')
|
||||
|
||||
const element = window.document.querySelector('.red')
|
||||
expect(element).not.toBe(null)
|
||||
@ -111,7 +111,7 @@ describe('basic generate', () => {
|
||||
test('/stateful', async () => {
|
||||
const window = await generator.nuxt.server.renderAndGetWindow(url('/stateful'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<div><p>The answer is 42</p></div>')).toBe(true)
|
||||
expect(html).toContain('<div><p>The answer is 42</p></div>')
|
||||
})
|
||||
|
||||
test('/head', async () => {
|
||||
@ -120,18 +120,18 @@ describe('basic generate', () => {
|
||||
const metas = window.document.getElementsByTagName('meta')
|
||||
expect(window.document.title).toBe('My title - Nuxt.js')
|
||||
expect(metas[0].getAttribute('content')).toBe('my meta')
|
||||
expect(html.includes('<div><h1>I can haz meta tags</h1></div>')).toBe(true)
|
||||
expect(html).toContain('<div><h1>I can haz meta tags</h1></div>')
|
||||
})
|
||||
|
||||
test('/async-data', async () => {
|
||||
const window = await generator.nuxt.server.renderAndGetWindow(url('/async-data'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<p>Nuxt.js</p>')).toBe(true)
|
||||
expect(html).toContain('<p>Nuxt.js</p>')
|
||||
})
|
||||
|
||||
test('/users/1/index.html', async () => {
|
||||
const html = await rp(url('/users/1/index.html'))
|
||||
expect(html.includes('<h1>User: 1</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>User: 1</h1>')
|
||||
expect(
|
||||
existsSync(resolve(distDir, 'users/1/index.html'))
|
||||
).toBe(true)
|
||||
@ -140,12 +140,12 @@ describe('basic generate', () => {
|
||||
|
||||
test('/users/2', async () => {
|
||||
const html = await rp(url('/users/2'))
|
||||
expect(html.includes('<h1>User: 2</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>User: 2</h1>')
|
||||
})
|
||||
|
||||
test('/users/3 (payload given)', async () => {
|
||||
const html = await rp(url('/users/3'))
|
||||
expect(html.includes('<h1>User: 3000</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>User: 3000</h1>')
|
||||
})
|
||||
|
||||
test('/users/4 -> Not found', async () => {
|
||||
@ -159,32 +159,32 @@ describe('basic generate', () => {
|
||||
|
||||
test('/validate should not be server-rendered', async () => {
|
||||
const html = await rp(url('/validate'))
|
||||
expect(html.includes('<div id="__nuxt"></div>')).toBe(true)
|
||||
expect(html.includes('serverRendered:!1')).toBe(true)
|
||||
expect(html).toContain('<div id="__nuxt"></div>')
|
||||
expect(html).toContain('serverRendered:!1')
|
||||
})
|
||||
|
||||
test('/validate -> should display a 404', async () => {
|
||||
const window = await generator.nuxt.server.renderAndGetWindow(url('/validate'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('This page could not be found')).toBe(true)
|
||||
expect(html).toContain('This page could not be found')
|
||||
})
|
||||
|
||||
test('/validate?valid=true', async () => {
|
||||
const window = await generator.nuxt.server.renderAndGetWindow(url('/validate?valid=true'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('I am valid</h1>')).toBe(true)
|
||||
expect(html).toContain('I am valid</h1>')
|
||||
})
|
||||
|
||||
test('/redirect should not be server-rendered', async () => {
|
||||
const html = await rp(url('/redirect'))
|
||||
expect(html.includes('<div id="__nuxt"></div>')).toBe(true)
|
||||
expect(html.includes('serverRendered:!1')).toBe(true)
|
||||
expect(html).toContain('<div id="__nuxt"></div>')
|
||||
expect(html).toContain('serverRendered:!1')
|
||||
})
|
||||
|
||||
test('/redirect -> check redirected source', async () => {
|
||||
const window = await generator.nuxt.server.renderAndGetWindow(url('/redirect'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<h1>Index page</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Index page</h1>')
|
||||
})
|
||||
|
||||
test('/users/1 not found', async () => {
|
||||
@ -204,7 +204,7 @@ describe('basic generate', () => {
|
||||
|
||||
test('/users/1.html', async () => {
|
||||
const html = await rp(url('/users/1.html'))
|
||||
expect(html.includes('<h1>User: 1</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>User: 1</h1>')
|
||||
expect(existsSync(resolve(distDir, 'users/1.html'))).toBe(true)
|
||||
expect(
|
||||
existsSync(resolve(distDir, 'users/1/index.html'))
|
||||
|
@ -92,8 +92,8 @@ describe('basic ssr csp', () => {
|
||||
})
|
||||
|
||||
expect(headers[cspHeader]).toMatch(/^script-src 'self' 'sha256-.*'/)
|
||||
expect(headers[cspHeader].includes('https://example.com')).toBe(true)
|
||||
expect(headers[cspHeader].includes('https://example.io')).toBe(true)
|
||||
expect(headers[cspHeader]).toContain('https://example.com')
|
||||
expect(headers[cspHeader]).toContain('https://example.io')
|
||||
}
|
||||
)
|
||||
|
||||
@ -115,8 +115,8 @@ describe('basic ssr csp', () => {
|
||||
|
||||
expect(headers[cspHeader]).toMatch(/default-src 'none'/)
|
||||
expect(headers[cspHeader]).toMatch(/script-src 'sha256-(.*)?' 'self'/)
|
||||
expect(headers[cspHeader].includes('https://example.com')).toBe(true)
|
||||
expect(headers[cspHeader].includes('https://example.io')).toBe(true)
|
||||
expect(headers[cspHeader]).toContain('https://example.com')
|
||||
expect(headers[cspHeader]).toContain('https://example.io')
|
||||
}
|
||||
)
|
||||
|
||||
@ -235,8 +235,8 @@ describe('basic ssr csp', () => {
|
||||
})
|
||||
|
||||
expect(headers[reportOnlyHeader]).toMatch(/^script-src 'self' 'sha256-.*'/)
|
||||
expect(headers[reportOnlyHeader].includes('https://example.com')).toBe(true)
|
||||
expect(headers[reportOnlyHeader].includes('https://example.io')).toBe(true)
|
||||
expect(headers[reportOnlyHeader]).toContain('https://example.com')
|
||||
expect(headers[reportOnlyHeader]).toContain('https://example.io')
|
||||
}
|
||||
)
|
||||
|
||||
@ -258,8 +258,8 @@ describe('basic ssr csp', () => {
|
||||
|
||||
expect(headers[reportOnlyHeader]).toMatch(/default-src 'none'/)
|
||||
expect(headers[reportOnlyHeader]).toMatch(/script-src 'sha256-(.*)?' 'self'/)
|
||||
expect(headers[reportOnlyHeader].includes('https://example.com')).toBe(true)
|
||||
expect(headers[reportOnlyHeader].includes('https://example.io')).toBe(true)
|
||||
expect(headers[reportOnlyHeader]).toContain('https://example.com')
|
||||
expect(headers[reportOnlyHeader]).toContain('https://example.io')
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -16,12 +16,12 @@ describe('basic ssr', () => {
|
||||
|
||||
test('/stateless', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/stateless')
|
||||
expect(html.includes('<h1>My component!</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>My component!</h1>')
|
||||
})
|
||||
|
||||
test('/store-module', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/store-module')
|
||||
expect(html.includes('<h1>mutated</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>mutated</h1>')
|
||||
})
|
||||
|
||||
/*
|
||||
@ -31,7 +31,7 @@ describe('basic ssr', () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/css'))
|
||||
|
||||
const headHtml = window.document.head.innerHTML
|
||||
expect(headHtml.includes('color:red')).toBe(true)
|
||||
expect(headHtml).toContain('color:red')
|
||||
|
||||
const element = window.document.querySelector('.red')
|
||||
expect(element).not.toBe(null)
|
||||
@ -44,7 +44,7 @@ describe('basic ssr', () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/css'))
|
||||
|
||||
const headHtml = window.document.head.innerHTML
|
||||
expect(headHtml.includes('background-color:#00f')).toBe(true)
|
||||
expect(headHtml).toContain('background-color:#00f')
|
||||
|
||||
// const element = window.document.querySelector('div.red')
|
||||
// t.is(window.getComputedStyle(element)['background-color'], 'blue')
|
||||
@ -52,13 +52,13 @@ describe('basic ssr', () => {
|
||||
|
||||
test('/stateful', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/stateful')
|
||||
expect(html.includes('<div><p>The answer is 42</p></div>')).toBe(true)
|
||||
expect(html).toContain('<div><p>The answer is 42</p></div>')
|
||||
})
|
||||
|
||||
test('/store', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/store')
|
||||
expect(html.includes('<h1>Vuex Nested Modules</h1>')).toBe(true)
|
||||
expect(html.includes('<p>1</p>')).toBe(true)
|
||||
expect(html).toContain('<h1>Vuex Nested Modules</h1>')
|
||||
expect(html).toContain('<p>1</p>')
|
||||
})
|
||||
|
||||
test('/head', async () => {
|
||||
@ -66,7 +66,7 @@ describe('basic ssr', () => {
|
||||
expect(window.document.title).toBe('My title - Nuxt.js')
|
||||
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<div><h1>I can haz meta tags</h1></div>')).toBe(true)
|
||||
expect(html).toContain('<div><h1>I can haz meta tags</h1></div>')
|
||||
expect(
|
||||
html.includes('<script data-n-head="true" src="/body.js" data-body="true">')
|
||||
).toBe(true)
|
||||
@ -78,64 +78,64 @@ describe('basic ssr', () => {
|
||||
|
||||
test('/async-data', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/async-data')
|
||||
expect(html.includes('<p>Nuxt.js</p>')).toBe(true)
|
||||
expect(html).toContain('<p>Nuxt.js</p>')
|
||||
})
|
||||
|
||||
test('/await-async-data', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/await-async-data')
|
||||
expect(html.includes('<p>Await Nuxt.js</p>')).toBe(true)
|
||||
expect(html).toContain('<p>Await Nuxt.js</p>')
|
||||
})
|
||||
|
||||
test('/callback-async-data', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/callback-async-data')
|
||||
expect(html.includes('<p>Callback Nuxt.js</p>')).toBe(true)
|
||||
expect(html).toContain('<p>Callback Nuxt.js</p>')
|
||||
})
|
||||
|
||||
test('/users/1', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/users/1')
|
||||
expect(html.includes('<h1>User: 1</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>User: 1</h1>')
|
||||
})
|
||||
|
||||
test('/validate should display a 404', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/validate')
|
||||
expect(html.includes('This page could not be found')).toBe(true)
|
||||
expect(html).toContain('This page could not be found')
|
||||
})
|
||||
|
||||
test('/validate-async should display a 404', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/validate-async')
|
||||
expect(html.includes('This page could not be found')).toBe(true)
|
||||
expect(html).toContain('This page could not be found')
|
||||
})
|
||||
|
||||
test('/validate?valid=true', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/validate?valid=true')
|
||||
expect(html.includes('<h1>I am valid</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>I am valid</h1>')
|
||||
})
|
||||
|
||||
test('/validate-async?valid=true', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/validate-async?valid=true')
|
||||
expect(html.includes('<h1>I am valid</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>I am valid</h1>')
|
||||
})
|
||||
|
||||
test('/validate?error=403', async () => {
|
||||
const { html, error } = await nuxt.server.renderRoute('/validate?error=403')
|
||||
expect(error).toMatchObject({ statusCode: 403, message: 'Custom Error' })
|
||||
expect(html.includes('Custom Error')).toBe(true)
|
||||
expect(html).toContain('Custom Error')
|
||||
})
|
||||
|
||||
test('/validate-async?error=503', async () => {
|
||||
const { html, error } = await nuxt.server.renderRoute('/validate-async?error=503')
|
||||
expect(error).toMatchObject({ statusCode: 503, message: 'Custom Error' })
|
||||
expect(html.includes('Custom Error')).toBe(true)
|
||||
expect(html).toContain('Custom Error')
|
||||
})
|
||||
|
||||
test('/before-enter', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/before-enter')
|
||||
expect(html.includes('<h1>Index page</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Index page</h1>')
|
||||
})
|
||||
|
||||
test('/redirect', async () => {
|
||||
const { html, redirected } = await nuxt.server.renderRoute('/redirect')
|
||||
expect(html.includes('<div id="__nuxt"></div>')).toBe(true)
|
||||
expect(html).toContain('<div id="__nuxt"></div>')
|
||||
expect(redirected.path === '/').toBe(true)
|
||||
expect(redirected.status === 302).toBe(true)
|
||||
})
|
||||
@ -144,7 +144,7 @@ describe('basic ssr', () => {
|
||||
// there are no transition properties in jsdom, ignore the error log
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/redirect'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<h1>Index page</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Index page</h1>')
|
||||
})
|
||||
|
||||
test('/redirect -> external link', async () => {
|
||||
@ -160,7 +160,7 @@ describe('basic ssr', () => {
|
||||
})
|
||||
expect(_status).toBe(302)
|
||||
expect(_headers.Location).toBe('https://nuxtjs.org')
|
||||
expect(html.includes('<div data-server-rendered="true"></div>')).toBe(true)
|
||||
expect(html).toContain('<div data-server-rendered="true"></div>')
|
||||
})
|
||||
|
||||
test('/special-state -> check window.__NUXT__.test = true', async () => {
|
||||
@ -199,8 +199,8 @@ describe('basic ssr', () => {
|
||||
|
||||
test('/error2', async () => {
|
||||
const { html, error } = await nuxt.server.renderRoute('/error2')
|
||||
expect(html.includes('Custom error')).toBe(true)
|
||||
expect(error.message.includes('Custom error')).toBe(true)
|
||||
expect(html).toContain('Custom error')
|
||||
expect(error.message).toContain('Custom error')
|
||||
expect(error.statusCode === undefined).toBe(true)
|
||||
})
|
||||
|
||||
@ -221,7 +221,7 @@ describe('basic ssr', () => {
|
||||
|
||||
test('/redirect-name', async () => {
|
||||
const { html, redirected } = await nuxt.server.renderRoute('/redirect-name')
|
||||
expect(html.includes('<div id="__nuxt"></div>')).toBe(true)
|
||||
expect(html).toContain('<div id="__nuxt"></div>')
|
||||
expect(redirected.path === '/stateless').toBe(true)
|
||||
expect(redirected.status === 302).toBe(true)
|
||||
})
|
||||
@ -236,7 +236,7 @@ describe('basic ssr', () => {
|
||||
test('/no-ssr (client-side)', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/no-ssr'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('Displayed only on client-side</h1>')).toBe(true)
|
||||
expect(html).toContain('Displayed only on client-side</h1>')
|
||||
})
|
||||
|
||||
test('ETag Header', async () => {
|
||||
@ -270,28 +270,28 @@ describe('basic ssr', () => {
|
||||
|
||||
test('/fn-midd?please=true', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/fn-midd?please=true')
|
||||
expect(html.includes('<h1>Date:')).toBe(true)
|
||||
expect(html).toContain('<h1>Date:')
|
||||
})
|
||||
|
||||
test('/router-guard', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/router-guard')
|
||||
expect(html.includes('<p>Nuxt.js</p>')).toBe(true)
|
||||
expect(html).toContain('<p>Nuxt.js</p>')
|
||||
expect(html.includes('Router Guard')).toBe(false)
|
||||
})
|
||||
|
||||
test('/jsx', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/jsx')
|
||||
expect(html.includes('<h1>JSX Page</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>JSX Page</h1>')
|
||||
})
|
||||
|
||||
test('/jsx-link', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/jsx-link')
|
||||
expect(html.includes('<h1>JSX Link Page</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>JSX Link Page</h1>')
|
||||
})
|
||||
|
||||
test('/js-link', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/js-link')
|
||||
expect(html.includes('<h1>vue file is first-class</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>vue file is first-class</h1>')
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
|
@ -15,36 +15,36 @@ describe('children', () => {
|
||||
|
||||
test('/parent', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/parent')
|
||||
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>I am the parent</h1>')
|
||||
})
|
||||
|
||||
test('/parent/child', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/parent/child')
|
||||
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
||||
expect(html.includes('<h2>I am the child</h2>')).toBe(true)
|
||||
expect(html).toContain('<h1>I am the parent</h1>')
|
||||
expect(html).toContain('<h2>I am the child</h2>')
|
||||
})
|
||||
|
||||
test('/parent should call _id.vue', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/parent')
|
||||
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
||||
expect(html.includes('<h2>Id=</h2>')).toBe(true)
|
||||
expect(html).toContain('<h1>I am the parent</h1>')
|
||||
expect(html).toContain('<h2>Id=</h2>')
|
||||
})
|
||||
|
||||
test('/parent/1', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/parent/1')
|
||||
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
||||
expect(html.includes('<h2>Id=1</h2>')).toBe(true)
|
||||
expect(html).toContain('<h1>I am the parent</h1>')
|
||||
expect(html).toContain('<h2>Id=1</h2>')
|
||||
})
|
||||
|
||||
test('/parent/validate-child should display 404', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/parent/validate-child')
|
||||
expect(html.includes('This page could not be found')).toBe(true)
|
||||
expect(html).toContain('This page could not be found')
|
||||
})
|
||||
|
||||
test('/parent/validate-child?key=12345', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/parent/validate-child?key=12345')
|
||||
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
||||
expect(html.includes('<h2>Child valid</h2>')).toBe(true)
|
||||
expect(html).toContain('<h1>I am the parent</h1>')
|
||||
expect(html).toContain('<h2>Child valid</h2>')
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
|
@ -71,7 +71,7 @@ describe('cli', () => {
|
||||
}
|
||||
|
||||
expect(error).toBe(undefined)
|
||||
expect(stdout.includes('Listening on')).toBe(true)
|
||||
expect(stdout).toContain('Listening on')
|
||||
|
||||
const html = await rp(url('/'))
|
||||
expect(html).toMatch(('<div>CLI Test</div>'))
|
||||
|
@ -12,8 +12,8 @@ describe('custom-app-template', () => {
|
||||
})
|
||||
test('/', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<p>My Template</p>')).toBe(true)
|
||||
expect(html.includes('<h1>Custom!</h1>')).toBe(true)
|
||||
expect(html).toContain('<p>My Template</p>')
|
||||
expect(html).toContain('<h1>Custom!</h1>')
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
|
@ -27,18 +27,18 @@ describe('custom-dirs', () => {
|
||||
|
||||
test('custom layouts directory', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<p>I have custom layouts directory</p>')).toBe(true)
|
||||
expect(html).toContain('<p>I have custom layouts directory</p>')
|
||||
})
|
||||
|
||||
test('custom middleware directory', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/user-agent'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<pre>Mozilla')).toBe(true)
|
||||
expect(html).toContain('<pre>Mozilla')
|
||||
})
|
||||
|
||||
test('custom pages directory', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<h1>I have custom pages directory</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>I have custom pages directory</h1>')
|
||||
})
|
||||
|
||||
test('custom static directory', async () => {
|
||||
|
@ -29,7 +29,7 @@ describe('dist options', () => {
|
||||
resolveWithFullResponse: true
|
||||
})
|
||||
const twoYears = (((60 * 60 * 24 * 365) * 2) / 1000).toString()
|
||||
expect(headers['cache-control'].includes(twoYears)).toBe(true)
|
||||
expect(headers['cache-control']).toContain(twoYears)
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
|
@ -24,7 +24,7 @@ describe('error', () => {
|
||||
|
||||
test('/404 should display an error too', async () => {
|
||||
const { error } = await nuxt.server.renderRoute('/404')
|
||||
expect(error.message.includes('This page could not be found')).toBe(true)
|
||||
expect(error.message).toContain('This page could not be found')
|
||||
})
|
||||
|
||||
test('/ with renderAndGetWindow()', async () => {
|
||||
|
@ -29,7 +29,7 @@ describe('express', () => {
|
||||
test('/stateless with express', async () => {
|
||||
const html = await rp(url('/stateless'))
|
||||
|
||||
expect(html.includes('<h1>My component!</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>My component!</h1>')
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
|
@ -12,7 +12,7 @@ describe('basic https', () => {
|
||||
|
||||
test('/', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<h1>Served over HTTPS!</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Served over HTTPS!</h1>')
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
|
@ -21,14 +21,14 @@ describe('module', () => {
|
||||
normalize('fixtures/module/.nuxt/basic.reverse.')
|
||||
)).toBe(true)
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<h1>TXUN</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>TXUN</h1>')
|
||||
})
|
||||
|
||||
test('Layout', async () => {
|
||||
expect(nuxt.options.layouts.layout.includes('layout')).toBe(true)
|
||||
expect(nuxt.options.layouts.layout).toContain('layout')
|
||||
|
||||
const { html } = await nuxt.server.renderRoute('/layout')
|
||||
expect(html.includes('<h1>Module Layouts</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Module Layouts</h1>')
|
||||
})
|
||||
|
||||
test('/404 should display the module error layout', async () => {
|
||||
|
@ -27,8 +27,8 @@ describe('nuxt', () => {
|
||||
|
||||
return new Builder(nuxt).build().catch((err) => {
|
||||
const s = String(err)
|
||||
expect(s.includes('No `pages` directory found')).toBe(true)
|
||||
expect(s.includes('Did you mean to run `nuxt` in the parent (`../`) directory?')).toBe(true)
|
||||
expect(s).toContain('No `pages` directory found')
|
||||
expect(s).toContain('Did you mean to run `nuxt` in the parent (`../`) directory?')
|
||||
})
|
||||
})
|
||||
|
||||
@ -39,7 +39,7 @@ describe('nuxt', () => {
|
||||
await nuxt.server.listen(port, 'localhost')
|
||||
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<h2 class="Landscape__Title">')).toBe(true)
|
||||
expect(html).toContain('<h2 class="Landscape__Title">')
|
||||
expect(/Landscape__Page__Explanation/.test(html)).toBe(true)
|
||||
|
||||
await nuxt.close()
|
||||
@ -53,7 +53,7 @@ describe('nuxt', () => {
|
||||
|
||||
return new Builder(nuxt).build().catch((err) => {
|
||||
const s = String(err)
|
||||
expect(s.includes('Plugin not found')).toBe(true)
|
||||
expect(s).toContain('Plugin not found')
|
||||
})
|
||||
})
|
||||
|
||||
@ -65,7 +65,7 @@ describe('nuxt', () => {
|
||||
|
||||
return new Builder(nuxt).build().catch((err) => {
|
||||
const s = String(err)
|
||||
expect(s.includes('Style Resource not found')).toBe(true)
|
||||
expect(s).toContain('Style Resource not found')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -11,7 +11,7 @@ describe.skip.win('basic sockets', () => {
|
||||
|
||||
test('/', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<h1>Served over sockets!</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Served over sockets!</h1>')
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
|
@ -16,7 +16,7 @@ describe('with-config', () => {
|
||||
|
||||
test('/', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<h1>I have custom configurations</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>I have custom configurations</h1>')
|
||||
})
|
||||
|
||||
test('/ (asset name for analyze mode)', async () => {
|
||||
@ -24,16 +24,17 @@ describe('with-config', () => {
|
||||
expect(html).toContain('<script src="/test/orion/app.js"')
|
||||
})
|
||||
|
||||
test.skip('/ (global styles inlined)', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
test('/ (global styles inlined)', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/test/'))
|
||||
const html = window.document.head.innerHTML
|
||||
expect(html).toContain('.global-css-selector')
|
||||
})
|
||||
|
||||
test.skip('/ (preload fonts)', async () => {
|
||||
test('/ (preload fonts)', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes(
|
||||
'<link rel="preload" href="/test/orion/fonts/roboto.7cf5d7c.woff2" as="font" type="font/woff2" crossorigin'
|
||||
)).toBe(true)
|
||||
expect(html).toContain(
|
||||
'<link rel="preload" href="/test/orion/fonts/7cf5d7c.woff2" as="font" type="font/woff2" crossorigin'
|
||||
)
|
||||
})
|
||||
|
||||
test('/ (styleResources styles inlined)', async () => {
|
||||
@ -43,23 +44,23 @@ describe('with-config', () => {
|
||||
|
||||
test('/ (custom app.html)', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<p>Made by Nuxt.js team</p>')).toBe(true)
|
||||
expect(html).toContain('<p>Made by Nuxt.js team</p>')
|
||||
})
|
||||
|
||||
test('/ (custom build.publicPath)', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('<script src="/test/orion/')).toBe(true)
|
||||
expect(html).toContain('<script src="/test/orion/')
|
||||
})
|
||||
|
||||
test('/ (custom postcss.config.js)', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html.includes('::-webkit-input-placeholder')).toBe(true)
|
||||
expect(html).toContain('::-webkit-input-placeholder')
|
||||
})
|
||||
|
||||
test('/test/ (custom globalName)', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/test/'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('id="custom-nuxt-id">')).toBe(true)
|
||||
expect(html).toContain('id="custom-nuxt-id">')
|
||||
expect(html.includes('id="__nuxt">')).toBe(false)
|
||||
expect(window.__NOXXT__).toBeDefined()
|
||||
expect(window.__NUXT__).toBeUndefined()
|
||||
@ -72,8 +73,8 @@ describe('with-config', () => {
|
||||
|
||||
const html = window.document.body.innerHTML
|
||||
expect(window.__NOXXT__.layout).toBe('default')
|
||||
expect(html.includes('<h1>Default layout</h1>')).toBe(true)
|
||||
expect(html.includes('<h1>I have custom configurations</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Default layout</h1>')
|
||||
expect(html).toContain('<h1>I have custom configurations</h1>')
|
||||
|
||||
expect(window.__test_plugin).toBe(true)
|
||||
})
|
||||
@ -82,57 +83,57 @@ describe('with-config', () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/test/about'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(window.__NOXXT__.layout).toBe('custom')
|
||||
expect(html.includes('<h1>Custom layout</h1>')).toBe(true)
|
||||
expect(html.includes('<h1>About page</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Custom layout</h1>')
|
||||
expect(html).toContain('<h1>About page</h1>')
|
||||
})
|
||||
|
||||
test('/test/desktop (custom layout in desktop folder)', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/test/desktop'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(window.__NOXXT__.layout).toBe('desktop/default')
|
||||
expect(html.includes('<h1>Default desktop layout</h1>')).toBe(true)
|
||||
expect(html.includes('<h1>Desktop page</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Default desktop layout</h1>')
|
||||
expect(html).toContain('<h1>Desktop page</h1>')
|
||||
})
|
||||
|
||||
test('/test/mobile (custom layout in mobile folder)', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/test/mobile'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(window.__NOXXT__.layout).toBe('mobile/default')
|
||||
expect(html.includes('<h1>Default mobile layout</h1>')).toBe(true)
|
||||
expect(html.includes('<h1>Mobile page</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Default mobile layout</h1>')
|
||||
expect(html).toContain('<h1>Mobile page</h1>')
|
||||
})
|
||||
|
||||
test('/test/env', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/test/env'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<h1>Custom env layout</h1>')).toBe(true)
|
||||
expect(html.includes('"bool": true')).toBe(true)
|
||||
expect(html.includes('"num": 23')).toBe(true)
|
||||
expect(html.includes('"string": "Nuxt.js"')).toBe(true)
|
||||
expect(html.includes('"bool": false')).toBe(true)
|
||||
expect(html.includes('"string": "ok"')).toBe(true)
|
||||
expect(html.includes('"num2": 8.23')).toBe(true)
|
||||
expect(html.includes('"obj": {')).toBe(true)
|
||||
expect(html).toContain('<h1>Custom env layout</h1>')
|
||||
expect(html).toContain('"bool": true')
|
||||
expect(html).toContain('"num": 23')
|
||||
expect(html).toContain('"string": "Nuxt.js"')
|
||||
expect(html).toContain('"bool": false')
|
||||
expect(html).toContain('"string": "ok"')
|
||||
expect(html).toContain('"num2": 8.23')
|
||||
expect(html).toContain('"obj": {')
|
||||
expect(html).toContain('"NUXT_ENV_FOO": "manniL"')
|
||||
})
|
||||
|
||||
test('/test/error', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/test/error'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('Error page')).toBe(true)
|
||||
expect(html).toContain('Error page')
|
||||
})
|
||||
|
||||
test('/test/user-agent', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/test/user-agent'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<pre>Mozilla')).toBe(true)
|
||||
expect(html).toContain('<pre>Mozilla')
|
||||
})
|
||||
|
||||
test('/test/about-bis (added with extendRoutes)', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/test/about-bis'))
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<h1>Custom layout</h1>')).toBe(true)
|
||||
expect(html.includes('<h1>About page</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Custom layout</h1>')
|
||||
expect(html).toContain('<h1>About page</h1>')
|
||||
})
|
||||
|
||||
test('/test/not-existed should return 404', async () => {
|
||||
@ -143,11 +144,11 @@ describe('with-config', () => {
|
||||
test('/test/redirect/about-bis (redirect with extendRoutes)', async () => {
|
||||
const window = await nuxt.server.renderAndGetWindow(url('/test/redirect/about-bis'))
|
||||
const windowHref = window.location.href
|
||||
expect(windowHref.includes('/test/about-bis')).toBe(true)
|
||||
expect(windowHref).toContain('/test/about-bis')
|
||||
|
||||
const html = window.document.body.innerHTML
|
||||
expect(html.includes('<h1>Custom layout</h1>')).toBe(true)
|
||||
expect(html.includes('<h1>About page</h1>')).toBe(true)
|
||||
expect(html).toContain('<h1>Custom layout</h1>')
|
||||
expect(html).toContain('<h1>About page</h1>')
|
||||
})
|
||||
|
||||
test('Check /test/test.txt with custom serve-static options', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user