Skip to content

Commit 1c73ec4

Browse files
committed
Add test to verify the design system is reloaded on css changes
This already works and is probably already tested but wanted to add a more explicit test to detect it.
1 parent 373bb9c commit 1c73ec4

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

packages/tailwindcss-language-server/src/projects.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,11 @@ export async function createProjectService(
11641164
let elapsed = process.hrtime.bigint() - start
11651165

11661166
console.log(`---- RELOADED IN ${(Number(elapsed) / 1e6).toFixed(2)}ms ----`)
1167+
1168+
let isTestMode = params.initializationOptions?.testMode ?? false
1169+
if (!isTestMode) return
1170+
1171+
connection.sendNotification('@/tailwindCSS/projectReloaded')
11671172
},
11681173

11691174
state,
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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

Comments
 (0)