-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.test.js
115 lines (97 loc) · 2.93 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import fs from 'fs'
import path from 'path'
import postcss from 'postcss'
import prettier from 'prettier'
import tailwind from './index'
it('should generate CSS using values from your config file', () => {
let input = readFile('./test-fixtures/colors/index.css')
let config = file('./test-fixtures/colors/tailwind.config.js')
return run(input, config).then((result) => {
expect(format(result.css)).toEqual(
format(css`
.text-primary {
color: #0088cc;
}
`),
)
})
})
describe('plugins', () => {
it('should generate CSS using built-in plugins', () => {
let input = readFile('./test-fixtures/basic/index.css')
let config = file('./test-fixtures/basic/tailwind.config.js')
return run(input, config).then((result) => {
expect(format(result.css)).toEqual(
format(css`
.built-in-utility {
color: red;
}
`),
)
})
})
it('should generate CSS using static plugins defined in your CSS', () => {
let input = readFile('./test-fixtures/css-plugin/index.css')
let config = file('./test-fixtures/css-plugin/tailwind.config.js')
return run(input, config).then((result) => {
expect(format(result.css)).toEqual(
format(css`
.css-utility {
color: blue;
}
`),
)
})
})
it('should generate CSS using external plugins defined in your tailwind.config.js file', () => {
let input = readFile('./test-fixtures/external-plugin/index.css')
let config = file('./test-fixtures/external-plugin/tailwind.config.js')
return run(input, config).then((result) => {
expect(format(result.css)).toEqual(
format(css`
.plugin-utility {
color: green;
}
`),
)
})
})
it('should generate CSS using built-in, CSS and external plugins', () => {
let input = readFile('./test-fixtures/combined-plugins/index.css')
let config = file('./test-fixtures/combined-plugins/tailwind.config.js')
return run(input, config).then((result) => {
expect(format(result.css)).toEqual(
format(css`
.built-in-utility {
color: red;
}
.plugin-utility {
color: green;
}
.css-utility {
color: blue;
}
`),
)
})
})
})
// ---
// Ignore below, just some helper functions
let css = String.raw
function file(filePath) {
return path.resolve(__dirname, filePath)
}
function readFile(filePath) {
return fs.readFileSync(file(filePath), 'utf8')
}
function run(input, config, plugin = tailwind) {
let { currentTestName } = expect.getState()
return postcss(plugin(config)).process(input, {
from: `${path.resolve(__filename)}?test=${currentTestName}`,
})
}
// Just for a bit nicer diffs in the tests, nothing related to Tailwind itself.
function format(styles) {
return prettier.format(styles, { parser: 'css' })
}