|
1 | 1 | import postcss from 'postcss';
|
2 | 2 | import test from 'ava';
|
3 |
| -import plugin from '../src/'; |
| 3 | +import plugin from '../src'; |
4 | 4 |
|
5 | 5 | const processing = (input, opts) => {
|
6 |
| - return postcss([plugin(opts)]).process(input).css; |
| 6 | + return postcss([plugin(opts)]).process(input).css; |
7 | 7 | };
|
8 | 8 |
|
| 9 | +test('it change circular reference', t => { |
| 10 | + const expected = ':root{ --from: 1; --to: 1}'; |
| 11 | + const value = ':root{ --from: 1; --to: var(--from)}'; |
| 12 | + t.is(processing(value), expected); |
| 13 | +}); |
| 14 | + |
9 | 15 | test('it change first properties for @for', t => {
|
10 |
| - const expected = ':root{ --from: 1; } @for $i from 1 to 2'; |
11 |
| - const value = ':root{ --from: 1; } @for $i from var(--from) to 2'; |
12 |
| - t.is(processing(value), expected); |
| 16 | + const expected = ':root{ --from: 1; } @for $i from 1 to 2'; |
| 17 | + const value = ':root{ --from: 1; } @for $i from var(--from) to 2'; |
| 18 | + t.is(processing(value), expected); |
13 | 19 | });
|
14 | 20 |
|
15 | 21 | test('it change second properties for @for', t => {
|
16 |
| - const expected = ':root{ --to: 2; } @for $i from 1 to 2'; |
17 |
| - const value = ':root{ --to: 2; } @for $i from 1 to var(--to)'; |
18 |
| - t.is(processing(value), expected); |
| 22 | + const expected = ':root{ --to: 2; } @for $i from 1 to 2'; |
| 23 | + const value = ':root{ --to: 2; } @for $i from 1 to var(--to)'; |
| 24 | + t.is(processing(value), expected); |
19 | 25 | });
|
20 | 26 |
|
21 | 27 | test('it change two properties for @for', t => {
|
22 |
| - const expected = ':root{ --from: 1; --to: 2; } @for $i from 1 to 2'; |
23 |
| - const value = ':root{ --from: 1; --to: 2; } @for $i from var(--from) to var(--to)'; |
24 |
| - t.is(processing(value), expected); |
| 28 | + const expected = ':root{ --from: 1; --to: 2; } @for $i from 1 to 2'; |
| 29 | + const value = ':root{ --from: 1; --to: 2; } @for $i from var(--from) to var(--to)'; |
| 30 | + t.is(processing(value), expected); |
25 | 31 | });
|
26 | 32 |
|
27 | 33 | test('it change three properties for @for', t => {
|
28 |
| - const expected = ':root{ --from: 1; --to: 2; --step: 5 } @for $i from 1 to 2 by 5'; |
29 |
| - const value = ':root{ --from: 1; --to: 2; --step: 5 } @for $i from var(--from) to var(--to) by var(--step)'; |
30 |
| - t.is(processing(value), expected); |
| 34 | + const expected = ':root{ --from: 1; --to: 2; --step: 5 } @for $i from 1 to 2 by 5'; |
| 35 | + const value = ':root{ --from: 1; --to: 2; --step: 5 } @for $i from var(--from) to var(--to) by var(--step)'; |
| 36 | + t.is(processing(value), expected); |
31 | 37 | });
|
32 | 38 |
|
33 | 39 | test('it change two properties for @if', t => {
|
34 |
| - const expected = ':root{ --first: 1; --second: 2; } @if 1 < 2'; |
35 |
| - const value = ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second)'; |
36 |
| - t.is(processing(value, {atRules: ['if']}), expected); |
| 40 | + const expected = ':root{ --first: 1; --second: 2; } @if 1 < 2'; |
| 41 | + const value = ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second)'; |
| 42 | + t.is(processing(value, {atRules: ['if']}), expected); |
37 | 43 | });
|
38 | 44 |
|
39 | 45 | test('it change two properties for @if, @else if', t => {
|
40 |
| - const expected = ':root{ --first: 1; --second: 2; } @if 1 < 2 { color: olive; } @else if 1 > 2 { color: red; }'; |
41 |
| - const value = ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second) { color: olive; } @else if var(--first) > var(--second) { color: red; }'; |
42 |
| - t.is(processing(value, {atRules: ['if', 'else']}), expected); |
| 46 | + const expected = ':root{ --first: 1; --second: 2; } @if 1 < 2 { color: olive; } @else if 1 > 2 { color: red; }'; |
| 47 | + const value = ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second) { color: olive; } @else if var(--first) > var(--second) { color: red; }'; |
| 48 | + t.is(processing(value, {atRules: ['if', 'else']}), expected); |
43 | 49 | });
|
44 | 50 |
|
45 | 51 | test('it change multi properties for @each', t => {
|
46 |
| - const expected = ':root{ --array: foo, bar, baz; } @each $val in foo, bar, baz {} @for foo, bar, baz {}'; |
47 |
| - const value = ':root{ --array: foo, bar, baz; } @each $val in var(--array) {} @for var(--array) {}'; |
48 |
| - t.is(processing(value, {atRules: ['each']}), expected); |
| 52 | + const expected = ':root{ --array: foo, bar, baz; } @each $val in foo, bar, baz {} @for foo, bar, baz {}'; |
| 53 | + const value = ':root{ --array: foo, bar, baz; } @each $val in var(--array) {} @for var(--array) {}'; |
| 54 | + t.is(processing(value, {atRules: ['each']}), expected); |
49 | 55 | });
|
50 | 56 |
|
51 | 57 | test('it without variables', t => {
|
52 |
| - const expected = ':root{ --red: red; } @if var(--green) { color: var(--green) }'; |
53 |
| - const value = ':root{ --red: red; } @if var(--green) { color: var(--green) }'; |
54 |
| - t.is(processing(value), expected); |
| 58 | + const expected = ':root{ --red: red; } @if var(--green) { color: var(--green) }'; |
| 59 | + const value = ':root{ --red: red; } @if var(--green) { color: var(--green) }'; |
| 60 | + t.is(processing(value), expected); |
55 | 61 | });
|
56 | 62 |
|
57 | 63 | test('chould change from options variables', t => {
|
58 |
| - const expected = '@if green { .text-green { color: var(--green) }}'; |
59 |
| - const value = '@if var(--green) { .text-green { color: var(--green) }}'; |
60 |
| - const variables = { |
61 |
| - '--green': 'green' |
62 |
| - }; |
63 |
| - t.is(processing(value, {variables: variables}), expected); |
| 64 | + const expected = '@if green { .text-green { color: var(--green) }}'; |
| 65 | + const value = '@if var(--green) { .text-green { color: var(--green) }}'; |
| 66 | + const variables = { |
| 67 | + '--green': 'green' |
| 68 | + }; |
| 69 | + t.is(processing(value, {variables: variables}), expected); |
64 | 70 | });
|
65 | 71 |
|
66 | 72 | test('should change for @custom-media', t => {
|
67 |
| - const expected = ':root{ --breakpoint-xs: 29.25em } @custom-media --viewport-xs (width > 29.25em)'; |
68 |
| - const value = ':root{ --breakpoint-xs: 29.25em } @custom-media --viewport-xs (width > var(--breakpoint-xs))'; |
69 |
| - t.is(processing(value, {atRules: ['custom-media']}), expected); |
| 73 | + const expected = ':root{ --breakpoint-xs: 29.25em } @custom-media --viewport-xs (width > 29.25em)'; |
| 74 | + const value = ':root{ --breakpoint-xs: 29.25em } @custom-media --viewport-xs (width > var(--breakpoint-xs))'; |
| 75 | + t.is(processing(value, {atRules: ['custom-media']}), expected); |
70 | 76 | });
|
0 commit comments