|
| 1 | +const stylelint = require('stylelint') |
| 2 | +const path = require('path') |
| 3 | + |
| 4 | +const processor = path.join(__dirname, '../src/index.js') |
| 5 | +const rules = { |
| 6 | + 'block-no-empty': true, |
| 7 | + indentation: 2, |
| 8 | + 'rule-empty-line-before': [ |
| 9 | + 'always-multi-line', |
| 10 | + { |
| 11 | + except: ['first-nested'], |
| 12 | + ignore: ['after-comment'] |
| 13 | + } |
| 14 | + ], |
| 15 | + 'selector-type-no-unknown': true |
| 16 | +} |
| 17 | + |
| 18 | +describe('options', () => { |
| 19 | + let fixture |
| 20 | + let data |
| 21 | + |
| 22 | + // NOTE beforeEach() runs _after_ the beforeAll() hooks of the describe() blocks, so `fixture` |
| 23 | + // will have the right path |
| 24 | + beforeEach(done => { |
| 25 | + stylelint |
| 26 | + .lint({ |
| 27 | + files: [fixture], |
| 28 | + syntax: 'scss', |
| 29 | + config: { |
| 30 | + // Set moduleName option to "emotion" |
| 31 | + processors: [[processor, { moduleName: 'emotion' }]], |
| 32 | + rules |
| 33 | + } |
| 34 | + }) |
| 35 | + .then(result => { |
| 36 | + data = result |
| 37 | + done() |
| 38 | + }) |
| 39 | + .catch(err => { |
| 40 | + console.log(err) |
| 41 | + data = err |
| 42 | + done() |
| 43 | + }) |
| 44 | + }) |
| 45 | + |
| 46 | + describe('moduleName', () => { |
| 47 | + beforeAll(() => { |
| 48 | + fixture = path.join(__dirname, './fixtures/options/module-name.js') |
| 49 | + }) |
| 50 | + |
| 51 | + it('should have one result', () => { |
| 52 | + expect(data.results.length).toEqual(1) |
| 53 | + }) |
| 54 | + |
| 55 | + it('should use the right file', () => { |
| 56 | + expect(data.results[0].source).toEqual(fixture) |
| 57 | + }) |
| 58 | + |
| 59 | + it('should have errored', () => { |
| 60 | + expect(data.results[0].errored).toEqual(true) |
| 61 | + }) |
| 62 | + |
| 63 | + it('should have one warning (i.e. wrong lines of code)', () => { |
| 64 | + expect(data.results[0].warnings.length).toEqual(1) |
| 65 | + }) |
| 66 | + |
| 67 | + it('should have a block-no-empty as the first warning', () => { |
| 68 | + expect(data.results[0].warnings[0].rule).toEqual('block-no-empty') |
| 69 | + }) |
| 70 | + }) |
| 71 | + |
| 72 | + describe('relative moduleName', () => { |
| 73 | + beforeAll(() => { |
| 74 | + fixture = path.join(__dirname, './fixtures/options/relative-module-name.js') |
| 75 | + }) |
| 76 | + |
| 77 | + it('should have one result', () => { |
| 78 | + expect(data.results.length).toEqual(1) |
| 79 | + }) |
| 80 | + |
| 81 | + it('should use the right file', () => { |
| 82 | + expect(data.results[0].source).toEqual(fixture) |
| 83 | + }) |
| 84 | + |
| 85 | + it('should have errored', () => { |
| 86 | + expect(data.results[0].errored).toEqual(true) |
| 87 | + }) |
| 88 | + |
| 89 | + it('should have one warning (i.e. wrong lines of code)', () => { |
| 90 | + expect(data.results[0].warnings.length).toEqual(1) |
| 91 | + }) |
| 92 | + |
| 93 | + it('should have a block-no-empty as the first warning', () => { |
| 94 | + expect(data.results[0].warnings[0].rule).toEqual('block-no-empty') |
| 95 | + }) |
| 96 | + }) |
| 97 | + |
| 98 | + describe('invalid moduleName', () => { |
| 99 | + beforeAll(() => { |
| 100 | + fixture = path.join(__dirname, './fixtures/options/invalid-module-name.js') |
| 101 | + }) |
| 102 | + |
| 103 | + it('should have one result', () => { |
| 104 | + expect(data.results.length).toEqual(1) |
| 105 | + }) |
| 106 | + |
| 107 | + it('should use the right file', () => { |
| 108 | + expect(data.results[0].source).toEqual(fixture) |
| 109 | + }) |
| 110 | + |
| 111 | + it('should not have errored', () => { |
| 112 | + expect(data.results[0].errored).toEqual(undefined) |
| 113 | + }) |
| 114 | + }) |
| 115 | +}) |
0 commit comments