UNPKG

6.39 kBMarkdownView Raw
1# PostCSS Tape [<img src="http://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][PostCSS]
2
3[![NPM Version][npm-img]][npm-url]
4[![Build Status][cli-img]][cli-url]
5[![Gitter Chat][git-img]][git-url]
6
7[PostCSS Tape] lets you quickly test [PostCSS] plugins.
8
91. Install this dependency to your project:
10 ```sh
11 npm install postcss-tape --save-dev
12 ```
13
142. Add the `postcss-tape` task to your `package.json`:
15 ```json
16 {
17 "scripts": {
18 "test": "postcss-tape"
19 }
20 }
21 ```
22
233. Add tests to your `.tape.js` file:
24 ```js
25 module.exports = {
26 'basic': {
27 message: 'supports basic usage'
28 }
29 };
30 ```
31
32That’s it! Empty tests will be auto-generated.
33
34```sh
35npm test
36```
37
38## Options
39
40Options may be passed through `package.json` using `postcssConfig`:
41
42```json
43{
44 "postcssConfig": {
45 "plugin": "path/to/plugin.js",
46 "config": "path/to/.tape.js",
47 "fixtures": "path/to/cssdir"
48 }
49}
50```
51
52Options may be passed through arguments:
53
54```sh
55postcss-tape --plugin=path/to/plugin.js --config=path/to/.tape.js
56```
57
58## Test Options
59
60### message
61
62The message provided to the console to identify the test being run.
63
64```js
65{
66 'some-test': {
67 message: 'supports some test usage'
68 }
69}
70```
71
72### options
73
74The options passed into the PostCSS plugin for the test.
75
76```js
77{
78 'some-test': {
79 options: {
80 someOption: true,
81 anotherOption: 5,
82 etc: 'etc'
83 }
84 }
85}
86```
87
88### processOptions
89
90The process options passed into PostCSS for the test. Read the
91[PostCSS documentation](http://api.postcss.org/global.html#processOptions) for
92more details.
93
94```js
95{
96 'some-test': {
97 processOptions: {
98 map: {
99 inline: true,
100 sourcesContent: true
101 }
102 }
103 }
104}
105```
106
107### warnings
108
109Either the number of warnings expected to be generated by the test, or an
110object used to match warnings given by the test.
111
112```js
113{
114 'some-test': {
115 warnings: 3
116 }
117}
118```
119
120```js
121{
122 'some-test': {
123 warnings: {
124 text: /should warn/
125 }
126 }
127}
128```
129
130### error
131
132An object used to match errors thrown by the test.
133
134```js
135{
136 'some-test': {
137 errors: {
138 message: 'You should not have done that'
139 }
140 }
141}
142```
143
144In that example, the error expects a field of `message` to be the string
145`You should not have done that`. In order that errors can be inspecific,
146regular expressions may also be used, so that something like
147`message: /^You should not have done/` would also match
148`You should not have done this`.
149
150### source
151
152The location of the source CSS file, relative to the `fixtures` directory. This
153file is passed through the PostCSS plugin.
154
155```js
156{
157 'some-test': {
158 source: 'alterate-source.css'
159 }
160}
161```
162
163In that example, a `some-test` field would automatically populate the
164`source` as `some-test.css` unless it was overridden. In order that multiple
165tests may use the same source file, a `some-test:modifier` field would still
166populate the `source` as `some-test.css`.
167
168### expect
169
170The location of the expected CSS file, relative to the `fixtures` directory.
171This file is represents the expected CSS result of `source` after being passed
172through the PostCSS plugin.
173
174```js
175{
176 'some-test': {
177 expect: 'alterate-expect.css'
178 }
179}
180```
181
182In that example, a `some-test` field would automatically populate the
183`expect` as `some-test.expect.css` unless it was overridden. In order that
184multiple tests may use the same source file, a `some-test:modifier` field would
185still populate the `source` as `some-test.css`, but alter the `expect` to be
186`some-test.modifier.expect.css`.
187
188### result
189
190The location of the resulting CSS file, relative to the `fixtures` directory.
191This file is the CSS result of `source` after being passed through the PostCSS
192plugin.
193
194```js
195{
196 'some-test': {
197 result: 'alterate-result.css'
198 }
199}
200```
201
202In that example, a `some-test` field would automatically populate the
203`result` as `some-test.result.css` unless it was overridden. In order that
204multiple tests may use the same source file, a `some-test:modifier` field would
205still populate the `source` as `some-test.css`, but alter the `result` to be
206`some-test.modifier.result.css`.
207
208### before
209
210A function to be run before the particular test. This is helpful for generating
211variables, content, or files that will be used by the plugin.
212
213```js
214{
215 'some-test': {
216 before: () => {
217 /* do something before the plugin runs */
218 }
219 }
220}
221```
222
223### after
224
225A function to be run after the particular test. This is helpful for cleaning up
226variables, content, or files that were used by the plugin.
227
228```js
229{
230 'some-test': {
231 after: () => {
232 /* do something after the plugin runs */
233 }
234 }
235}
236```
237
238### plugin
239
240A plugin or array of plugins that will specifying alternative plugin
241
242```js
243{
244 'some-test': {
245 plugin: () => require('postcss')(
246 require('some-plugin-that-runs-before'),
247 require('.'),
248 require('some-plugin-that-runs-after')
249 )
250 }
251}
252```
253
254## CLI Options
255
256Options can be passed into the `postcss-tape` function or defined in
257`package.json` using the `postcssConfig` property.
258
259### plugin
260
261The path to the plugin being tested.
262
263```bash
264postcss-tape --plugin=path/to/plugin.js
265```
266
267```json
268{
269 "postcssConfig": {
270 "plugin": "path/to/plugin.js"
271 }
272}
273```
274
275By default, `plugin` is the resolved file from the current working directory.
276
277### config
278
279The path to the configuration file used to run tests.
280
281```bash
282postcss-tape --config=path/to/config.js
283```
284
285```json
286{
287 "postcssConfig": {
288 "config": "path/to/config.js"
289 }
290}
291```
292
293By default, [PostCSS Tape] will try to use the file defined by `config`, or
294the `config` directory’s `postcss-tape.config.js` or `.tape.js` file. By
295default, `config` is the current working directory.
296
297### fixtures
298
299The path to the fixtures used by tests.
300
301```bash
302postcss-tape --fixtures=path/to/tests
303```
304
305```json
306{
307 "postcssConfig": {
308 "fixtures": "path/to/tests"
309 }
310}
311```
312
313[npm-img]: https://img.shields.io/npm/v/postcss-tape.svg
314[npm-url]: https://www.npmjs.com/package/postcss-tape
315[cli-img]: https://img.shields.io/travis/csstools/postcss-tape.svg
316[cli-url]: https://travis-ci.org/csstools/postcss-tape
317[git-img]: https://img.shields.io/badge/chat-gitter-blue.svg
318[git-url]: https://gitter.im/postcss/postcss
319
320[PostCSS]: https://github.com/postcss/postcss
321[PostCSS Tape]: https://github.com/csstools/postcss-tape