2022-10-12 12:43:59 +00:00
|
|
|
import { fileURLToPath } from 'node:url'
|
2024-05-02 08:51:39 +00:00
|
|
|
import { readFileSync } from 'node:fs'
|
2024-05-07 21:45:03 +00:00
|
|
|
import { rm } from 'node:fs/promises'
|
|
|
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
2022-10-12 12:43:59 +00:00
|
|
|
import { execaCommand } from 'execa'
|
2024-03-29 14:34:38 +00:00
|
|
|
import { format } from 'prettier'
|
2022-10-12 12:43:59 +00:00
|
|
|
|
2024-05-07 21:45:03 +00:00
|
|
|
const distDir = fileURLToPath(new URL('../node_modules/.temp/dist/templates', import.meta.url))
|
2022-10-12 12:43:59 +00:00
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
await execaCommand('pnpm build', {
|
2024-05-01 13:10:33 +00:00
|
|
|
cwd: fileURLToPath(new URL('..', import.meta.url)),
|
2024-05-07 21:45:03 +00:00
|
|
|
env: {
|
|
|
|
OUTPUT_DIR: './node_modules/.temp/dist',
|
|
|
|
},
|
2022-10-12 12:43:59 +00:00
|
|
|
})
|
|
|
|
})
|
2024-05-07 21:45:03 +00:00
|
|
|
afterAll(() => rm(distDir, { force: true, recursive: true }))
|
2022-10-12 12:43:59 +00:00
|
|
|
|
2024-03-29 14:34:38 +00:00
|
|
|
function formatCss (css: string) {
|
|
|
|
return format(css, {
|
2024-05-01 13:10:33 +00:00
|
|
|
parser: 'css',
|
2024-03-29 14:34:38 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-12 12:43:59 +00:00
|
|
|
it.each(['error-404.vue', 'error-500.vue', 'error-dev.vue', 'loading.vue', 'welcome.vue'])('correctly outputs style blocks for %s', async (file) => {
|
2024-05-02 08:51:39 +00:00
|
|
|
const contents = readFileSync(`${distDir}/${file}`, 'utf-8')
|
2022-10-12 12:43:59 +00:00
|
|
|
|
|
|
|
const scopedStyle = contents.match(/<style scoped>([\s\S]*)<\/style>/)
|
|
|
|
const globalStyle = contents.match(/style: \[[\s\S]*children: `([\s\S]*)`/)
|
|
|
|
|
2024-03-29 14:34:38 +00:00
|
|
|
expect(await formatCss(scopedStyle?.[1] || '')).toMatchSnapshot()
|
|
|
|
expect(await formatCss(globalStyle?.[1] || '')).toMatchSnapshot()
|
2022-10-12 12:43:59 +00:00
|
|
|
})
|
|
|
|
})
|