|
1 | 1 | import test from 'ava'; |
2 | 2 | import easyImport from '../'; |
| 3 | +import path from 'path'; |
| 4 | +import postcss from 'postcss'; |
3 | 5 |
|
4 | 6 | const msg = err => 'postcss-easy-import: ' + err; |
5 | 7 |
|
| 8 | +function preprocess(input, output, opts, t) { |
| 9 | + return postcss([ easyImport(opts) ]).process(input) |
| 10 | + .then(result => { |
| 11 | + t.is(result.css, output); |
| 12 | + t.is(result.warnings().length, 0); |
| 13 | + }); |
| 14 | +} |
| 15 | + |
6 | 16 | test('should fail on incorrect \'prefix\'', t => { |
7 | 17 | t.throws(() => { |
8 | 18 | easyImport({ |
@@ -68,3 +78,30 @@ test('should not fail on correct \'extensions\'', t => { |
68 | 78 | }); |
69 | 79 | }); |
70 | 80 | }); |
| 81 | + |
| 82 | +test('should handle glob imports', t => { |
| 83 | + return preprocess( |
| 84 | + '@import "./*.css";\n', |
| 85 | + '.bar {\n color: green;\n}\n.foo {\n color: red;\n}\n', |
| 86 | + { root: path.resolve('./fixtures/integration') }, |
| 87 | + t |
| 88 | + ); |
| 89 | +}); |
| 90 | + |
| 91 | +test('should handle module imports', t => { |
| 92 | + return preprocess( |
| 93 | + '@import "./module/baz.css";\n', |
| 94 | + '.baz {\n color: blue;\n}\n', |
| 95 | + { root: path.resolve('./fixtures/integration') }, |
| 96 | + t |
| 97 | + ); |
| 98 | +}); |
| 99 | + |
| 100 | +test('should handle glob and module imports together', t => { |
| 101 | + return preprocess( |
| 102 | + '@import "./module/baz.css";\n @import "./*.css";', |
| 103 | + '.baz {\n color: blue;\n}\n .bar {\n color: green;\n}\n .foo {\n color: red;\n}', // eslint-disable-line max-len |
| 104 | + { root: path.resolve('./fixtures/integration') }, |
| 105 | + t |
| 106 | + ); |
| 107 | +}); |
0 commit comments