|
| 1 | +const Vinyl = require('vinyl') |
| 2 | +const configFn = require('./postcss.config.js') |
| 3 | + |
| 4 | +describe('PostCSS config', () => { |
| 5 | + let env |
| 6 | + |
| 7 | + function getPluginNames ({ plugins }) { |
| 8 | + return plugins.map(({ postcssPlugin }) => postcssPlugin) |
| 9 | + } |
| 10 | + |
| 11 | + beforeAll(() => { |
| 12 | + env = 'production' |
| 13 | + }) |
| 14 | + |
| 15 | + describe('Default', () => { |
| 16 | + it.each( |
| 17 | + [ |
| 18 | + { path: 'example.css' }, |
| 19 | + { path: 'example.scss' } |
| 20 | + ] |
| 21 | + )('Adds plugins for $path', ({ path }) => { |
| 22 | + const input = new Vinyl({ path }) |
| 23 | + |
| 24 | + // Confirm plugins for both file object and path |
| 25 | + for (const file of [input, input.path]) { |
| 26 | + const config = configFn({ env, file }) |
| 27 | + |
| 28 | + expect(getPluginNames(config)) |
| 29 | + .toEqual(['autoprefixer']) |
| 30 | + } |
| 31 | + }) |
| 32 | + }) |
| 33 | + |
| 34 | + describe('Default + IE8', () => { |
| 35 | + it.each( |
| 36 | + [ |
| 37 | + { path: 'example-ie8.css' }, |
| 38 | + { path: 'example-ie8.scss' } |
| 39 | + ] |
| 40 | + )('Adds plugins for $path', ({ path }) => { |
| 41 | + const input = new Vinyl({ path }) |
| 42 | + |
| 43 | + // Confirm plugins for both file object and path |
| 44 | + for (const file of [input, input.path]) { |
| 45 | + const config = configFn({ env, file }) |
| 46 | + |
| 47 | + expect(getPluginNames(config)) |
| 48 | + .toEqual([ |
| 49 | + 'autoprefixer', |
| 50 | + 'oldie' |
| 51 | + ]) |
| 52 | + } |
| 53 | + }) |
| 54 | + }) |
| 55 | + |
| 56 | + describe('Default + Minification', () => { |
| 57 | + it.each( |
| 58 | + [ |
| 59 | + { path: 'example.min.css' }, |
| 60 | + { path: 'example.min.scss' } |
| 61 | + ] |
| 62 | + )('Adds plugins for $path', ({ path }) => { |
| 63 | + const input = new Vinyl({ path }) |
| 64 | + |
| 65 | + // Confirm plugins for both file object and path |
| 66 | + for (const file of [input, input.path]) { |
| 67 | + const config = configFn({ env, file }) |
| 68 | + |
| 69 | + expect(getPluginNames(config)) |
| 70 | + .toEqual([ |
| 71 | + 'autoprefixer', |
| 72 | + 'cssnano' |
| 73 | + ]) |
| 74 | + } |
| 75 | + }) |
| 76 | + }) |
| 77 | + |
| 78 | + describe('Default + Minification + IE8', () => { |
| 79 | + it.each( |
| 80 | + [ |
| 81 | + { path: 'example-ie8.min.css' }, |
| 82 | + { path: 'example-ie8.min.scss' } |
| 83 | + ] |
| 84 | + )('Adds plugins for $path', ({ path }) => { |
| 85 | + const input = new Vinyl({ path }) |
| 86 | + |
| 87 | + // Confirm plugins for both file object and path |
| 88 | + for (const file of [input, input.path]) { |
| 89 | + const config = configFn({ env, file }) |
| 90 | + |
| 91 | + expect(getPluginNames(config)) |
| 92 | + .toEqual([ |
| 93 | + 'autoprefixer', |
| 94 | + 'cssnano', |
| 95 | + 'oldie' |
| 96 | + ]) |
| 97 | + } |
| 98 | + }) |
| 99 | + }) |
| 100 | + |
| 101 | + describe('Review app only', () => { |
| 102 | + it.each( |
| 103 | + [ |
| 104 | + { path: 'app/assets/scss/app.scss' }, |
| 105 | + { path: 'app/assets/scss/app-legacy.scss' } |
| 106 | + ] |
| 107 | + )('Adds plugins for $path', ({ path }) => { |
| 108 | + const input = new Vinyl({ path }) |
| 109 | + |
| 110 | + // Confirm plugins for both file object and path |
| 111 | + for (const file of [input, input.path]) { |
| 112 | + const config = configFn({ env, file }) |
| 113 | + |
| 114 | + expect(getPluginNames(config)) |
| 115 | + .toEqual([ |
| 116 | + 'autoprefixer', |
| 117 | + 'postcss-pseudo-classes' |
| 118 | + ]) |
| 119 | + } |
| 120 | + }) |
| 121 | + }) |
| 122 | + |
| 123 | + describe('Review app only + IE8', () => { |
| 124 | + it.each( |
| 125 | + [ |
| 126 | + { path: 'app/assets/scss/app-ie8.scss' }, |
| 127 | + { path: 'app/assets/scss/app-legacy-ie8.scss' } |
| 128 | + ] |
| 129 | + )('Adds plugins for $path', ({ path }) => { |
| 130 | + const input = new Vinyl({ path }) |
| 131 | + |
| 132 | + // Confirm plugins for both file object and path |
| 133 | + for (const file of [input, input.path]) { |
| 134 | + const config = configFn({ env, file }) |
| 135 | + |
| 136 | + expect(getPluginNames(config)) |
| 137 | + .toEqual([ |
| 138 | + 'autoprefixer', |
| 139 | + 'postcss-pseudo-classes', |
| 140 | + 'oldie' |
| 141 | + ]) |
| 142 | + } |
| 143 | + }) |
| 144 | + }) |
| 145 | +}) |
0 commit comments