(page: Page, content: string, extraCss: string = '')
| 2183 | const defaultTheme = fs.readFileSync(path.resolve(__dirname, '..', 'theme.css'), 'utf-8') |
| 2184 | |
| 2185 | async function render(page: Page, content: string, extraCss: string = '') { |
| 2186 | let { build } = await compile(css` |
| 2187 | @layer theme, base, components, utilities; |
| 2188 | @layer theme { |
| 2189 | ${defaultTheme} |
| 2190 | |
| 2191 | @theme { |
| 2192 | --color-red: rgb(255, 0, 0); |
| 2193 | --color-green: rgb(0, 255, 0); |
| 2194 | --color-blue: rgb(0, 0, 255); |
| 2195 | --color-black: black; |
| 2196 | --color-transparent: transparent; |
| 2197 | } |
| 2198 | } |
| 2199 | @layer base { |
| 2200 | ${preflight} |
| 2201 | } |
| 2202 | @layer utilities { |
| 2203 | @tailwind utilities; |
| 2204 | } |
| 2205 | ${extraCss} |
| 2206 | `) |
| 2207 | |
| 2208 | // We noticed that some of the tests depending on the `hover:` variant were |
| 2209 | // flaky. After some investigation, we found that injected elements had the |
| 2210 | // `:hover` state without us explicitly hovering over the element. |
| 2211 | // |
| 2212 | // To avoid this, we now set up an explicit placeholder element to move the |
| 2213 | // mouse to before running the tests. |
| 2214 | content = `<div id="mouse-park" class="size-12"></div>${content}` |
| 2215 | |
| 2216 | let scanner = new Scanner({}) |
| 2217 | let candidates = scanner.scanFiles([{ content, extension: 'html' }]) |
| 2218 | |
| 2219 | let { code: styles } = optimize(build(candidates)) |
| 2220 | |
| 2221 | content = `<style type="text/css">${styles}</style>${content}` |
| 2222 | await page.setContent(content) |
| 2223 | |
| 2224 | await page.locator('#mouse-park').hover() |
| 2225 | |
| 2226 | return { |
| 2227 | getPropertyValue(selector: string | [string, string], property: string) { |
| 2228 | return getPropertyValue( |
| 2229 | page, |
| 2230 | Array.isArray(selector) ? selector : [selector, undefined], |
| 2231 | property, |
| 2232 | ) |
| 2233 | }, |
| 2234 | |
| 2235 | async getPropertyList(selector: string | [string, string], property: string) { |
| 2236 | let value = await getPropertyValue( |
| 2237 | page, |
| 2238 | Array.isArray(selector) ? selector : [selector, undefined], |
| 2239 | property, |
| 2240 | ) |
| 2241 | |
| 2242 | return segment(value, ',').map((item) => item.trim()) |
no test coverage detected