|
1 | 1 | const rewire = require('rewire') |
2 | | -const cssStandardsRewired = rewire('..') |
3 | | -const cssStandards = require('..') |
| 2 | +const cssStandardsRewired = rewire('../lib') |
| 3 | +const cssStandards = require('../lib') |
4 | 4 | const test = require('ava') |
5 | 5 |
|
6 | | -test('basic', (t) => { |
7 | | - cssStandardsRewired.__set__('postcssImport', (opts) => { |
8 | | - t.truthy(opts.root === 'test') |
9 | | - t.truthy(opts.path[0] === 'test/test1') |
10 | | - t.truthy(opts.path[1] === 'test/test2') |
11 | | - t.truthy(opts.path[2] === 'test') // webpack.resourcePath |
12 | | - }) |
| 6 | +test('passes parser opt correctly', (t) => { |
| 7 | + const out = cssStandards({ parser: 'test' }) |
| 8 | + const out2 = cssStandards({ parser: false }) |
| 9 | + t.is(out.parser, 'test') |
| 10 | + t.is(out2.parser, undefined) |
| 11 | +}) |
13 | 12 |
|
14 | | - cssStandardsRewired.__set__('cssnext', (opts) => { |
15 | | - t.truthy(opts.features === 'test') |
16 | | - t.truthy(opts.browsers === 'test') |
17 | | - t.truthy(opts.warnForDuplicates === 'test') |
| 13 | +test('passes import opts correctly', (t) => { |
| 14 | + const undo = cssStandardsRewired.__set__('postcssImport', (opts) => { |
| 15 | + t.is(opts.root, 'test') |
| 16 | + t.is(opts.path[0], 'test') |
18 | 17 | }) |
| 18 | + cssStandardsRewired({ root: 'test', path: 'test' }) |
| 19 | + undo() |
| 20 | +}) |
19 | 21 |
|
20 | | - cssStandardsRewired.__set__('rucksack', (opts) => { |
21 | | - t.truthy(opts === 'test') |
| 22 | +test('passes cssnext opts correctly', (t) => { |
| 23 | + const undo = cssStandardsRewired.__set__('cssnext', (opts) => { |
| 24 | + t.is(opts.browsers, 'test') |
| 25 | + t.is(opts.features, 'test') |
| 26 | + t.is(opts.warnForDuplicates, 'test') |
22 | 27 | }) |
23 | | - |
24 | | - const out1 = cssStandardsRewired({ |
25 | | - parser: false, |
26 | | - webpack: { |
27 | | - resourcePath: 'test', |
28 | | - options: { context: 'test' } |
29 | | - }, |
30 | | - path: ['test/test1', 'test/test2'], |
31 | | - features: 'test', |
| 28 | + cssStandardsRewired({ |
32 | 29 | browsers: 'test', |
33 | | - warnForDuplicates: 'test', |
34 | | - rucksack: 'test' |
| 30 | + features: 'test', |
| 31 | + warnForDuplicates: 'test' |
| 32 | + }) |
| 33 | + undo() |
| 34 | +}) |
| 35 | + |
| 36 | +test('passes rucksack opts correctly', (t) => { |
| 37 | + const undo = cssStandardsRewired.__set__('rucksack', (opts) => { |
| 38 | + t.is(opts, 'test') |
35 | 39 | }) |
| 40 | + cssStandardsRewired({ rucksack: 'test' }) |
| 41 | + undo() |
| 42 | +}) |
36 | 43 |
|
37 | | - t.truthy(out1.plugins.length === 3) |
38 | | - t.falsy(out1.parser) |
| 44 | +test('default plugins working', (t) => { |
| 45 | + const out = cssStandards() |
| 46 | + t.is(out.plugins.length, 3) |
| 47 | +}) |
39 | 48 |
|
40 | | - const out2 = cssStandards({ minify: true }) |
| 49 | +test('minify option working', (t) => { |
| 50 | + const out = cssStandards({ minify: true }) |
| 51 | + t.is(out.plugins.length, 4) |
| 52 | + t.is(out.plugins[out.plugins.length - 1].postcssPlugin, 'cssnano') |
| 53 | +}) |
| 54 | + |
| 55 | +test('appendPlugins option', (t) => { |
| 56 | + const out = cssStandards({ appendPlugins: ['test'] }) |
| 57 | + const out2 = cssStandards({ appendPlugins: 'test' }) |
| 58 | + t.truthy(out.plugins[out.plugins.length - 1] === 'test') |
| 59 | + t.truthy(out2.plugins[out.plugins.length - 1] === 'test') |
| 60 | +}) |
41 | 61 |
|
42 | | - t.truthy(out2.parser) |
43 | | - t.truthy(out2.plugins.length === 4) |
| 62 | +test('prependPlugins option', (t) => { |
| 63 | + const out = cssStandards({ prependPlugins: ['test'] }) |
| 64 | + const out2 = cssStandards({ prependPlugins: 'test' }) |
| 65 | + t.truthy(out.plugins[0] === 'test') |
| 66 | + t.truthy(out2.plugins[0] === 'test') |
44 | 67 | }) |
0 commit comments