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)
|
|
|
|
|
|
|
|
describe('extract css', () => {
|
2018-10-11 21:53:02 +00:00
|
|
|
beforeAll(async () => {
|
|
|
|
const options = await loadFixture('extract-css')
|
|
|
|
nuxt = new Nuxt(options)
|
2019-03-08 20:43:23 +00:00
|
|
|
await nuxt.ready()
|
|
|
|
|
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 () => {
|
2020-06-24 20:46:16 +00:00
|
|
|
const fileName = 'pages/index.css'
|
2018-10-11 21:53:02 +00:00
|
|
|
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)
|
|
|
|
|
2023-02-02 15:13:28 +00:00
|
|
|
const containerStyle = '{display:grid;grid-auto-flow:row;grid-template-columns:60px 60px 60px 60px 60px;grid-template-rows:30px 30px}'
|
2018-10-11 21:53:02 +00:00
|
|
|
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
|
|
|
})
|
|
|
|
})
|