add tests for font preload

This commit is contained in:
Pooya Parsa 2017-08-30 18:48:37 +04:30
parent 5eeca5a41b
commit 5c2f4715e6
4 changed files with 26 additions and 5 deletions

View File

@ -1,3 +1,15 @@
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(../assets/roboto.woff2) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
body {
font-family: 'Roboto';
}
.global-css-selector {
color: red;
}

Binary file not shown.

View File

@ -27,7 +27,7 @@ module.exports = {
string: 'Nuxt.js'
},
build: {
extractCSS: true,
// extractCSS: true,
publicPath: '/orion/',
analyze: {
analyzerMode: 'disabled',
@ -46,6 +46,11 @@ module.exports = {
http2: {
push: true
},
bundleRenderer: {
shouldPreload: (file, type) => {
return ['script', 'style', 'font'].includes(type)
}
},
static: {
maxAge: '1y'
}

View File

@ -26,9 +26,13 @@ test('/', async t => {
})
test('/ (global styles inlined)', async t => {
// const { html } = await nuxt.renderRoute('/')
// t.true(html.includes('.global-css-selector'))
t.pass()
const { html } = await nuxt.renderRoute('/')
t.true(html.includes('.global-css-selector'))
})
test('/ (preload fonts)', async t => {
const { html } = await nuxt.renderRoute('/')
t.true(html.includes('<link rel="preload" href="/test/orion/fonts/roboto.7cf5d7c.woff2" as="font" type="font/woff2" crossorigin'))
})
test('/ (custom app.html)', async t => {
@ -87,7 +91,7 @@ test('/test/about-bis (added with extendRoutes)', async t => {
test('Check stats.json generated by build.analyze', t => {
const stats = require(resolve(__dirname, 'fixtures/with-config/.nuxt/dist/stats.json'))
t.is(stats.assets.length, 28)
t.is(stats.assets.length, 27)
})
test('Check /test/test.txt with custom serve-static options', async t => {