Skip to content

Commit 95271a5

Browse files
committed
Add test to ensure colors are resolved recursively
1 parent ccb7bdf commit 95271a5

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

packages/tailwindcss-language-server/tests/colors/colors.test.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { test, expect } from 'vitest'
2-
import { withFixture } from '../common'
2+
import { init, withFixture } from '../common'
3+
import { css, defineTest } from '../../src/testing'
4+
import { DocumentColorRequest } from 'vscode-languageserver'
5+
6+
const color = (red, green, blue, alpha) => ({ red, green, blue, alpha })
7+
const range = (startLine, startCol, endLine, endCol) => ({
8+
start: { line: startLine, character: startCol },
9+
end: { line: endLine, character: endCol },
10+
})
311

412
withFixture('basic', (c) => {
513
async function testColors(name, { text, expected }) {
@@ -300,3 +308,48 @@ withFixture('v4/basic', (c) => {
300308
],
301309
})
302310
})
311+
312+
defineTest({
313+
name: 'v4: colors are recursively resolved from the theme',
314+
fs: {
315+
'app.css': css`
316+
@import 'tailwindcss';
317+
@theme {
318+
--color-*: initial;
319+
--color-primary: #ff0000;
320+
--color-level-1: var(--color-primary);
321+
--color-level-2: var(--color-level-1);
322+
--color-level-3: var(--color-level-2);
323+
--color-level-4: var(--color-level-3);
324+
--color-level-5: var(--color-level-4);
325+
}
326+
`,
327+
},
328+
prepare: async ({ root }) => ({ c: await init(root) }),
329+
handle: async ({ c }) => {
330+
let textDocument = await c.openDocument({
331+
lang: 'html',
332+
text: '<div class="bg-primary bg-level-1 bg-level-2 bg-level-3 bg-level-4 bg-level-5">',
333+
})
334+
335+
expect(c.project).toMatchObject({
336+
tailwind: {
337+
version: '4.0.0',
338+
isDefaultVersion: true,
339+
},
340+
})
341+
342+
let colors = await c.sendRequest(DocumentColorRequest.type, {
343+
textDocument,
344+
})
345+
346+
expect(colors).toEqual([
347+
{ range: range(0, 12, 0, 22), color: color(1, 0, 0, 1) },
348+
{ range: range(0, 23, 0, 33), color: color(1, 0, 0, 1) },
349+
{ range: range(0, 34, 0, 44), color: color(1, 0, 0, 1) },
350+
{ range: range(0, 45, 0, 55), color: color(1, 0, 0, 1) },
351+
{ range: range(0, 56, 0, 66), color: color(1, 0, 0, 1) },
352+
{ range: range(0, 67, 0, 77), color: color(1, 0, 0, 1) },
353+
])
354+
},
355+
})

0 commit comments

Comments
 (0)