Skip to content

Commit 197e1c7

Browse files
committed
Add tests
1 parent 684830e commit 197e1c7

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { expect } from 'vitest'
2+
import { css, defineTest } from '../../src/testing'
3+
import { createClient } from '../utils/client'
4+
import dedent from 'dedent'
5+
6+
let ignored = css`
7+
@import 'tailwindcss';
8+
@theme {
9+
--color-primary: #c0ffee;
10+
}
11+
`
12+
13+
let found = css`
14+
@import 'tailwindcss';
15+
@theme {
16+
--color-primary: rebeccapurple;
17+
}
18+
`
19+
20+
defineTest({
21+
name: 'various build folders and caches are ignored by default',
22+
fs: {
23+
// All of these should be ignored
24+
'aaa/.git/app.css': ignored,
25+
'aaa/.hg/app.css': ignored,
26+
'aaa/.svn/app.css': ignored,
27+
'aaa/node_modules/app.css': ignored,
28+
'aaa/.yarn/app.css': ignored,
29+
'aaa/.venv/app.css': ignored,
30+
'aaa/venv/app.css': ignored,
31+
'aaa/.next/app.css': ignored,
32+
'aaa/.parcel-cache/app.css': ignored,
33+
'aaa/.svelte-kit/app.css': ignored,
34+
'aaa/.turbo/app.css': ignored,
35+
'aaa/__pycache__/app.css': ignored,
36+
37+
// But this one should not be
38+
'zzz/app.css': found,
39+
},
40+
41+
prepare: async ({ root }) => ({ client: await createClient({ root }) }),
42+
handle: async ({ client }) => {
43+
let doc = await client.open({
44+
lang: 'html',
45+
text: '<div class="bg-primary">',
46+
})
47+
48+
// <div class="bg-primary">
49+
// ^
50+
let hover = await doc.hover({ line: 0, character: 13 })
51+
expect(hover).toEqual({
52+
contents: {
53+
language: 'css',
54+
value: dedent`
55+
.bg-primary {
56+
background-color: var(--color-primary) /* rebeccapurple = #663399 */;
57+
}
58+
`,
59+
},
60+
range: {
61+
start: { line: 0, character: 12 },
62+
end: { line: 0, character: 22 },
63+
},
64+
})
65+
},
66+
})
67+
68+
defineTest({
69+
name: 'ignores can be overridden',
70+
fs: {
71+
'aaa/.git/app.css': found,
72+
},
73+
74+
prepare: async ({ root }) => ({
75+
client: await createClient({
76+
root,
77+
settings: {
78+
tailwindCSS: {
79+
files: {
80+
exclude: [],
81+
},
82+
},
83+
},
84+
}),
85+
}),
86+
handle: async ({ client }) => {
87+
let doc = await client.open({
88+
lang: 'html',
89+
text: '<div class="bg-primary">',
90+
})
91+
92+
// <div class="bg-primary">
93+
// ^
94+
let hover = await doc.hover({ line: 0, character: 13 })
95+
expect(hover).toEqual({
96+
contents: {
97+
language: 'css',
98+
value: dedent`
99+
.bg-primary {
100+
background-color: var(--color-primary) /* rebeccapurple = #663399 */;
101+
}
102+
`,
103+
},
104+
range: {
105+
start: { line: 0, character: 12 },
106+
end: { line: 0, character: 22 },
107+
},
108+
})
109+
},
110+
})

0 commit comments

Comments
 (0)