2018-09-08 20:48:46 +00:00
|
|
|
import { resolve } from 'path'
|
|
|
|
import fs from 'fs'
|
|
|
|
import { promisify } from 'util'
|
2018-10-11 21:53:02 +00:00
|
|
|
import { loadFixture, getPort, Nuxt } from '../utils'
|
2018-09-08 20:48:46 +00:00
|
|
|
|
2018-10-11 21:53:02 +00:00
|
|
|
let nuxt = null
|
2018-09-08 20:48:46 +00:00
|
|
|
const readFile = promisify(fs.readFile)
|
2018-10-11 21:53:02 +00:00
|
|
|
const isWindows = /^win/.test(process.platform)
|
2018-09-08 20:48:46 +00:00
|
|
|
|
|
|
|
describe('extract css', () => {
|
2018-10-11 21:53:02 +00:00
|
|
|
beforeAll(async () => {
|
|
|
|
const options = await loadFixture('extract-css')
|
|
|
|
nuxt = new Nuxt(options)
|
2018-10-30 20:42:53 +00:00
|
|
|
await nuxt.server.listen(await getPort(), '0.0.0.0')
|
2018-10-11 21:53:02 +00:00
|
|
|
})
|
|
|
|
|
2018-12-13 18:37:47 +00:00
|
|
|
test('Verify global.css has been extracted and minified', async () => {
|
2018-10-11 21:53:02 +00:00
|
|
|
const fileName = isWindows ? 'pages_index.css' : 'pages/index.css'
|
|
|
|
const extractedIndexCss = resolve(__dirname, '..', 'fixtures/extract-css/.nuxt/dist/client', fileName)
|
|
|
|
const content = await readFile(extractedIndexCss, 'utf-8')
|
|
|
|
|
|
|
|
const scopeCss = /^h1\[data-v-[a-zA-Z0-9]{8}\]\{color:red\}\.container\[data-v-[a-zA-Z0-9]{8}\]/
|
|
|
|
expect(content).toMatch(scopeCss)
|
|
|
|
|
|
|
|
const containerStyle = '{display:-ms-grid;display:grid;-ms-grid-columns:60px 60px 60px 60px 60px;grid-template-columns:60px 60px 60px 60px 60px;-ms-grid-rows:30px 30px;grid-template-rows:30px 30px;grid-auto-flow:row}'
|
|
|
|
expect(content).toContain(containerStyle)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/about should contain module style', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/about')
|
2018-11-24 18:49:19 +00:00
|
|
|
expect(html).toMatch(/<h1 class="test_[a-zA-Z0-9]{5}">\s*I'm BLUE\s*<\/h1>/)
|
2018-12-13 18:37:47 +00:00
|
|
|
// no duplicate inlined style
|
|
|
|
expect(html).not.toContain('{color:#00f}')
|
2018-09-08 20:48:46 +00:00
|
|
|
})
|
|
|
|
})
|