|
| 1 | +var Checker = require('../../lib/checker'); |
| 2 | +var assert = require('assert'); |
| 3 | + |
| 4 | +describe('options/file-extensions', function() { |
| 5 | + var checker; |
| 6 | + |
| 7 | + beforeEach(function() { |
| 8 | + checker = new Checker(); |
| 9 | + checker.registerDefaultRules(); |
| 10 | + }); |
| 11 | + |
| 12 | + describe('default config', function() { |
| 13 | + |
| 14 | + beforeEach(function() { |
| 15 | + checker.configure({ |
| 16 | + disallowKeywords: ['with'] |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should not report any errors for non-matching extensions with default config', function() { |
| 21 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions.jsx') === null); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should report errors for matching extensions with default config', function() { |
| 25 | + // errors |
| 26 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions.js') !== null); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should report errors for matching extensions (case insensitive) with default config', function() { |
| 30 | + // errors |
| 31 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions-2.jS') !== null); |
| 32 | + }); |
| 33 | + |
| 34 | + }); |
| 35 | + |
| 36 | + describe('custom config', function() { |
| 37 | + |
| 38 | + it('should not report any errors for non-matching extensions with custom config', function() { |
| 39 | + checker.configure({ |
| 40 | + fileExtensions: ['.jsx'], |
| 41 | + disallowKeywords: ['with'] |
| 42 | + }); |
| 43 | + |
| 44 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions.js') === null); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should report errors for matching extensions with custom config', function() { |
| 48 | + checker.configure({ |
| 49 | + fileExtensions: ['.jsx'], |
| 50 | + disallowKeywords: ['with'] |
| 51 | + }); |
| 52 | + |
| 53 | + // errors |
| 54 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions.jsx') !== null); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should report errors for matching extensions (case insensitive) with custom config', function() { |
| 58 | + checker.configure({ |
| 59 | + fileExtensions: ['.JS'], |
| 60 | + disallowKeywords: ['with'] |
| 61 | + }); |
| 62 | + |
| 63 | + // errors |
| 64 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions-2.jS') !== null); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should report errors for matching extensions (case insensitive) with string value', function() { |
| 68 | + checker.configure({ |
| 69 | + fileExtensions: '.JS', |
| 70 | + disallowKeywords: ['with'] |
| 71 | + }); |
| 72 | + |
| 73 | + // errors |
| 74 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions-2.jS') !== null); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should report errors for matching extensions with custom config with multiple extensions', function() { |
| 78 | + checker.configure({ |
| 79 | + fileExtensions: ['.js', '.jsx'], |
| 80 | + disallowKeywords: ['with'] |
| 81 | + }); |
| 82 | + |
| 83 | + // errors |
| 84 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions.js') !== null); |
| 85 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions.jsx') !== null); |
| 86 | + }); |
| 87 | + |
| 88 | + it('should report errors for matching extensions with Array *', function() { |
| 89 | + checker.configure({ |
| 90 | + fileExtensions: ['*'], |
| 91 | + disallowKeywords: ['with'] |
| 92 | + }); |
| 93 | + |
| 94 | + // errors |
| 95 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions.js') !== null); |
| 96 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions.jsx') !== null); |
| 97 | + }); |
| 98 | + |
| 99 | + it('should report errors for matching extensions with string *', function() { |
| 100 | + checker.configure({ |
| 101 | + fileExtensions: '*', |
| 102 | + disallowKeywords: ['with'] |
| 103 | + }); |
| 104 | + |
| 105 | + // errors |
| 106 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions.js') !== null); |
| 107 | + assert(checker.checkFile('./test/data/configs/fileExtensions/file-extensions.jsx') !== null); |
| 108 | + }); |
| 109 | + }); |
| 110 | + |
| 111 | +}); |
0 commit comments