-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy pathsink.test.ts
43 lines (35 loc) · 1.47 KB
/
sink.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { existsSync, readFileSync } from 'node:fs'
import { exec } from 'node:child_process'
import { describe, test, expect, beforeAll } from 'vitest'
import { ofetch } from 'ofetch'
import { r } from './utils'
const fixturePath = r('', 'nuxt.com')
describe.skipIf(!existsSync(fixturePath))('nuxt.com', async () => {
// await setupNuxtTailwind({}, {}, {}, fixturePath)
// was going to use test-utils but gave up trying to set it up properly
beforeAll(() => {
const generateCommand = exec(`cd ${fixturePath} && pnpm generate`)
while (true) {
if (
existsSync(`${fixturePath}.output/public/index.html`)
&& readFileSync(`${fixturePath}.output/public/index.html`, 'utf-8').includes('<style>/*! tailwindcss')
) {
setTimeout(() => generateCommand.kill(), 5000)
break
}
}
})
test('check homepage css', async () => {
const getStyles = (html: string) => {
const searchText = '<style>/*! tailwindcss'
const _styles = html.slice(html.indexOf(searchText) + '<style>'.length)
return _styles.slice(0, _styles.indexOf('</style>'))
}
const builtHtml = readFileSync(`${fixturePath}.output/public/index.html`, 'utf-8')
const builtStyles = getStyles(builtHtml)
const expectedHtml: string = await ofetch('https://nuxt.com/')
const expectedStyles = getStyles(expectedHtml)
expect(builtStyles.length).toBeGreaterThanOrEqual(expectedStyles.length)
expect(builtStyles).toBe(expectedStyles)
})
})