|
| 1 | +var postcss = require('postcss') |
| 2 | +var reducePostcss = require('..') |
| 3 | +var reduce = require('reduce-css') |
| 4 | +var test = require('tape') |
| 5 | +var compare = require('compare-directory') |
| 6 | +var del = require('del') |
| 7 | +var path = require('path') |
| 8 | + |
| 9 | +var fixtures = path.resolve.bind(path, __dirname, 'fixtures') |
| 10 | +var DEST = fixtures('build') |
| 11 | + |
| 12 | +test('processorFilter, Function', function(t) { |
| 13 | + t.task(clean) |
| 14 | + t.task(function () { |
| 15 | + return bundle( |
| 16 | + t, |
| 17 | + { |
| 18 | + basedir: fixtures('src'), |
| 19 | + factor: 'common.css', |
| 20 | + }, |
| 21 | + DEST, |
| 22 | + null, |
| 23 | + { |
| 24 | + maxSize: 0, |
| 25 | + assetOutFolder: fixtures('build', 'images'), |
| 26 | + } |
| 27 | + ) |
| 28 | + }) |
| 29 | + t.task(function () { |
| 30 | + compare(t, ['**/*.css', '**/*.png'], DEST, fixtures('expected', 'single-bundle')) |
| 31 | + }) |
| 32 | + |
| 33 | + function bundle(t, ropts, dest, outOpts, urlOpts) { |
| 34 | + return reduce |
| 35 | + .on('error', console.log.bind(console)) |
| 36 | + .on('instance', function (b) { |
| 37 | + b.plugin(reducePostcss, { |
| 38 | + processorFilter: function (pipeline) { |
| 39 | + pipeline.push(postcss.plugin('A', function () { |
| 40 | + return function () { |
| 41 | + t.ok(true) |
| 42 | + } |
| 43 | + })) |
| 44 | + }, |
| 45 | + }) |
| 46 | + }) |
| 47 | + .src('*.css', ropts) |
| 48 | + .pipe(reduce.dest(dest, outOpts, urlOpts)) |
| 49 | + } |
| 50 | + |
| 51 | +}) |
| 52 | + |
| 53 | +test('processorFilter, Array', function(t) { |
| 54 | + t.task(clean) |
| 55 | + t.task(function () { |
| 56 | + return bundle( |
| 57 | + t, |
| 58 | + { |
| 59 | + basedir: fixtures('src'), |
| 60 | + factor: 'common.css', |
| 61 | + }, |
| 62 | + DEST, |
| 63 | + null, |
| 64 | + { |
| 65 | + maxSize: 0, |
| 66 | + assetOutFolder: fixtures('build', 'images'), |
| 67 | + } |
| 68 | + ) |
| 69 | + }) |
| 70 | + t.task(function () { |
| 71 | + compare(t, ['**/*.css', '**/*.png'], DEST, fixtures('expected', 'single-bundle')) |
| 72 | + }) |
| 73 | + |
| 74 | + function bundle(t, ropts, dest, outOpts, urlOpts) { |
| 75 | + return reduce |
| 76 | + .on('error', console.log.bind(console)) |
| 77 | + .on('instance', function (b) { |
| 78 | + b.plugin(reducePostcss, { |
| 79 | + processorFilter: [postcss.plugin('A', function () { |
| 80 | + return function () { |
| 81 | + t.ok(true) |
| 82 | + } |
| 83 | + })], |
| 84 | + }) |
| 85 | + }) |
| 86 | + .src('*.css', ropts) |
| 87 | + .pipe(reduce.dest(dest, outOpts, urlOpts)) |
| 88 | + } |
| 89 | + |
| 90 | +}) |
| 91 | + |
| 92 | +function clean() { |
| 93 | + return del(DEST) |
| 94 | +} |
| 95 | + |
0 commit comments