|
| 1 | +import { expect } from 'vitest' |
| 2 | +import * as fs from 'node:fs/promises' |
| 3 | +import * as path from 'node:path' |
| 4 | +import { css, defineTest } from '../../src/testing' |
| 5 | +import dedent from 'dedent' |
| 6 | +import { createClient } from '../utils/client' |
| 7 | + |
| 8 | +defineTest({ |
| 9 | + name: 'The design system is reloaded when the CSS changes ($watcher)', |
| 10 | + fs: { |
| 11 | + 'app.css': css` |
| 12 | + @import 'tailwindcss'; |
| 13 | +
|
| 14 | + @theme { |
| 15 | + --color-primary: #c0ffee; |
| 16 | + } |
| 17 | + `, |
| 18 | + }, |
| 19 | + prepare: async ({ root }) => ({ |
| 20 | + client: await createClient({ |
| 21 | + root, |
| 22 | + capabilities(caps) { |
| 23 | + caps.workspace!.didChangeWatchedFiles!.dynamicRegistration = false |
| 24 | + }, |
| 25 | + }), |
| 26 | + }), |
| 27 | + handle: async ({ root, client }) => { |
| 28 | + let doc = await client.open({ |
| 29 | + lang: 'html', |
| 30 | + text: '<div class="text-primary">', |
| 31 | + }) |
| 32 | + |
| 33 | + // <div class="text-primary"> |
| 34 | + // ^ |
| 35 | + let hover = await doc.hover({ line: 0, character: 13 }) |
| 36 | + |
| 37 | + expect(hover).toEqual({ |
| 38 | + contents: { |
| 39 | + language: 'css', |
| 40 | + value: dedent` |
| 41 | + .text-primary { |
| 42 | + color: var(--color-primary) /* #c0ffee */; |
| 43 | + } |
| 44 | + `, |
| 45 | + }, |
| 46 | + range: { |
| 47 | + start: { line: 0, character: 12 }, |
| 48 | + end: { line: 0, character: 24 }, |
| 49 | + }, |
| 50 | + }) |
| 51 | + |
| 52 | + let didReload = new Promise((resolve) => { |
| 53 | + client.conn.onNotification('@/tailwindCSS/projectReloaded', resolve) |
| 54 | + }) |
| 55 | + |
| 56 | + // Update the CSS |
| 57 | + await fs.writeFile( |
| 58 | + path.resolve(root, 'app.css'), |
| 59 | + css` |
| 60 | + @import 'tailwindcss'; |
| 61 | +
|
| 62 | + @theme { |
| 63 | + --color-primary: #bada55; |
| 64 | + } |
| 65 | + `, |
| 66 | + ) |
| 67 | + |
| 68 | + await didReload |
| 69 | + |
| 70 | + // <div class="text-primary"> |
| 71 | + // ^ |
| 72 | + let hover2 = await doc.hover({ line: 0, character: 13 }) |
| 73 | + |
| 74 | + expect(hover2).toEqual({ |
| 75 | + contents: { |
| 76 | + language: 'css', |
| 77 | + value: dedent` |
| 78 | + .text-primary { |
| 79 | + color: var(--color-primary) /* #bada55 */; |
| 80 | + } |
| 81 | + `, |
| 82 | + }, |
| 83 | + range: { |
| 84 | + start: { line: 0, character: 12 }, |
| 85 | + end: { line: 0, character: 24 }, |
| 86 | + }, |
| 87 | + }) |
| 88 | + }, |
| 89 | +}) |
0 commit comments