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-01 13:10:33 +00:00
|
|
|
import { 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
|
|
|
|
|
|
|
const distDir = fileURLToPath(new URL('../dist/templates', import.meta.url))
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
await execaCommand('pnpm build', {
|
2024-05-01 13:10:33 +00:00
|
|
|
cwd: fileURLToPath(new URL('..', import.meta.url)),
|
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
|
|
|
})
|
|
|
|
})
|