Skip to content

Commit 0c8cbaa

Browse files
committed
Add tests verifying behavior
1 parent bac776b commit 0c8cbaa

File tree

1 file changed

+186
-1
lines changed
  • packages/tailwindcss-language-server/tests/env

1 file changed

+186
-1
lines changed

packages/tailwindcss-language-server/tests/env/v4.test.js

Lines changed: 186 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'vitest'
22
import { init } from '../common'
33
import { HoverRequest } from 'vscode-languageserver'
4-
import { css, defineTest, js, json } from '../../src/testing'
4+
import { css, defineTest, html, js, json } from '../../src/testing'
55
import dedent from 'dedent'
66
import { CompletionRequest } from 'vscode-languageserver-protocol'
77

@@ -225,3 +225,188 @@ defineTest({
225225
expect(completion.items.length).toBe(12288)
226226
},
227227
})
228+
229+
defineTest({
230+
name: 'v4, using local, with explicit CSS entrypoints',
231+
fs: {
232+
'package.json': json`
233+
{
234+
"dependencies": {
235+
"tailwindcss": "4.0.1"
236+
}
237+
}
238+
`,
239+
'a/app.css': css`
240+
@import 'tailwindcss';
241+
@theme {
242+
--color-primary: #000000;
243+
}
244+
`,
245+
'b/app.css': css`
246+
@import 'tailwindcss';
247+
@theme {
248+
--color-primary: #ffffff;
249+
}
250+
`,
251+
},
252+
prepare: async ({ root }) => ({ c: await init(root) }),
253+
handle: async ({ c }) => {
254+
await c.updateSettings({
255+
tailwindCSS: {
256+
experimental: {
257+
configFile: {
258+
'a/app.css': 'c/a/**',
259+
'b/app.css': 'c/b/**',
260+
},
261+
},
262+
},
263+
})
264+
265+
let documentA = await c.openDocument({
266+
lang: 'html',
267+
text: '<div class="bg-primary">',
268+
name: 'c/a/index.html',
269+
})
270+
271+
let documentB = await c.openDocument({
272+
lang: 'html',
273+
text: '<div class="bg-primary">',
274+
name: 'c/b/index.html',
275+
})
276+
277+
let hoverA = await c.sendRequest(HoverRequest.type, {
278+
textDocument: documentA,
279+
280+
// <div class="bg-primary">
281+
// ^
282+
position: { line: 0, character: 13 },
283+
})
284+
285+
let hoverB = await c.sendRequest(HoverRequest.type, {
286+
textDocument: documentB,
287+
288+
// <div class="bg-primary">
289+
// ^
290+
position: { line: 0, character: 13 },
291+
})
292+
293+
expect(hoverA).toEqual({
294+
contents: {
295+
language: 'css',
296+
value: dedent`
297+
.bg-primary {
298+
background-color: var(--color-primary) /* #000000 */;
299+
}
300+
`,
301+
},
302+
range: {
303+
start: { line: 0, character: 12 },
304+
end: { line: 0, character: 22 },
305+
},
306+
})
307+
308+
expect(hoverB).toEqual({
309+
contents: {
310+
language: 'css',
311+
value: dedent`
312+
.bg-primary {
313+
background-color: var(--color-primary) /* #ffffff */;
314+
}
315+
`,
316+
},
317+
range: {
318+
start: { line: 0, character: 12 },
319+
end: { line: 0, character: 22 },
320+
},
321+
})
322+
},
323+
})
324+
325+
defineTest({
326+
name: 'v4, using fallback, with explicit CSS entrypoints',
327+
fs: {
328+
'a/app.css': css`
329+
@import 'tailwindcss';
330+
@theme {
331+
--color-primary: #000000;
332+
}
333+
`,
334+
'b/app.css': css`
335+
@import 'tailwindcss';
336+
@theme {
337+
--color-primary: #ffffff;
338+
}
339+
`,
340+
},
341+
prepare: async ({ root }) => ({ c: await init(root) }),
342+
handle: async ({ c }) => {
343+
await c.updateSettings({
344+
tailwindCSS: {
345+
experimental: {
346+
configFile: {
347+
'a/app.css': 'c/a/**',
348+
'b/app.css': 'c/b/**',
349+
},
350+
},
351+
},
352+
})
353+
354+
let documentA = await c.openDocument({
355+
lang: 'html',
356+
text: '<div class="bg-primary">',
357+
name: 'c/a/index.html',
358+
})
359+
360+
let documentB = await c.openDocument({
361+
lang: 'html',
362+
text: '<div class="bg-primary">',
363+
name: 'c/b/index.html',
364+
})
365+
366+
let hoverA = await c.sendRequest(HoverRequest.type, {
367+
textDocument: documentA,
368+
369+
// <div class="bg-primary">
370+
// ^
371+
position: { line: 0, character: 13 },
372+
})
373+
374+
let hoverB = await c.sendRequest(HoverRequest.type, {
375+
textDocument: documentB,
376+
377+
// <div class="bg-primary">
378+
// ^
379+
position: { line: 0, character: 13 },
380+
})
381+
382+
expect(hoverA).toEqual({
383+
contents: {
384+
language: 'css',
385+
value: dedent`
386+
.bg-primary {
387+
background-color: var(--color-primary) /* #000000 */;
388+
}
389+
`,
390+
},
391+
range: {
392+
start: { line: 0, character: 12 },
393+
end: { line: 0, character: 22 },
394+
},
395+
})
396+
397+
expect(hoverB).toEqual({
398+
contents: {
399+
language: 'css',
400+
value: dedent`
401+
.bg-primary {
402+
background-color: var(--color-primary) /* #ffffff */;
403+
}
404+
`,
405+
},
406+
range: {
407+
start: { line: 0, character: 12 },
408+
end: { line: 0, character: 22 },
409+
},
410+
})
411+
},
412+
})

0 commit comments

Comments
 (0)