|
1 | 1 | const postcss = require('postcss');
|
| 2 | +const fs = require('fs'); |
2 | 3 | const plugin = require('./');
|
3 |
| - |
4 |
| -const css = ` |
5 |
| -/* |
6 |
| -@define Link |
7 |
| -
|
8 |
| -@boolean |
9 |
| -
|
10 |
| -@description |
11 |
| -Pink anchors |
12 |
| -are super hip |
13 |
| -*/ |
14 |
| -a { color: blue; } |
15 |
| -/* #define Empty comment block #boolean*/ |
16 |
| -/* @define Empty comment block @boolean*/ |
17 |
| -`; |
18 |
| - |
| 4 | +const css = fs.readFileSync('index.test.css', 'utf-8'); |
19 | 5 | const opts = {
|
20 | 6 | prefix: '#'
|
21 | 7 | };
|
22 | 8 |
|
23 | 9 | it('should not modify any output CSS', () => {
|
24 |
| - return postcss([ plugin ]).process(css) |
| 10 | + return postcss([plugin]).process(css) |
25 | 11 | .then(result => {
|
26 | 12 | expect(result.css).toEqual(css);
|
27 | 13 | });
|
28 | 14 | });
|
29 | 15 |
|
30 |
| -it('should return array of objects for each annotated comment block', () => { |
31 |
| - return postcss([ plugin ]).process(css) |
| 16 | +it('should only push comments that have annotations', () => { |
| 17 | + return postcss([plugin]).process(css) |
32 | 18 | .then(result => {
|
33 |
| - expect(result.commentAnnotations).toHaveLength(2); |
| 19 | + expect(result.commentAnnotations).toHaveLength(1); |
34 | 20 | });
|
35 | 21 | });
|
36 | 22 |
|
37 |
| -it('should create annotation property for default prefixed keys', () => { |
38 |
| - return postcss([ plugin ]).process(css) |
| 23 | +it('should create property for default prefixed keys', () => { |
| 24 | + return postcss([plugin]).process(css) |
39 | 25 | .then(result => {
|
40 |
| - expect(result.commentAnnotations[0]).toHaveProperty('define'); |
| 26 | + expect(result.commentAnnotations[0]).toHaveProperty('foo'); |
41 | 27 | });
|
42 | 28 | });
|
43 | 29 |
|
44 |
| -it('should use option prefix to create annotation property', () => { |
| 30 | +it('should use option prefix to create properties', () => { |
45 | 31 | return postcss([plugin(opts)]).process(css)
|
46 | 32 | .then(result => {
|
47 |
| - expect(result.commentAnnotations[0]).toHaveProperty('define'); |
| 33 | + expect(result.commentAnnotations[0]).toHaveProperty('foo'); |
48 | 34 | });
|
49 | 35 | });
|
50 | 36 |
|
51 | 37 | it('should create a value for single line annotations', () => {
|
52 | 38 | return postcss([plugin]).process(css)
|
53 | 39 | .then(result => {
|
54 |
| - expect(result.commentAnnotations[0]) |
55 |
| - .toHaveProperty('define', 'Link'); |
| 40 | + expect(result.commentAnnotations[0]).toHaveProperty('foo', 'Bar'); |
56 | 41 | });
|
57 | 42 | });
|
58 | 43 |
|
59 | 44 | it('should create a value for multi line annotations', () => {
|
60 | 45 | return postcss([plugin]).process(css)
|
61 | 46 | .then(result => {
|
62 | 47 | expect(result.commentAnnotations[0])
|
63 |
| - .toHaveProperty('description', 'Pink anchors\nare super hip'); |
| 48 | + .toHaveProperty('qux', 'Foo bar\nbaz qux'); |
64 | 49 | });
|
65 | 50 | });
|
66 | 51 |
|
67 | 52 | it('should take key without value as boolean', () => {
|
68 | 53 | return postcss([plugin]).process(css)
|
69 | 54 | .then(result => {
|
70 |
| - expect(result.commentAnnotations[0]) |
71 |
| - .toHaveProperty('boolean', true); |
| 55 | + expect(result.commentAnnotations[0]).toHaveProperty('baz', true); |
72 | 56 | });
|
73 | 57 | });
|
0 commit comments