|
| 1 | +const {describe, beforeEach, afterEach} = require('mocha') |
| 2 | +const depGraph = require('../lib/dependency-graph') |
| 3 | +var rule = require('../lib/rules/unused-export') |
| 4 | +var RuleTester = require('eslint').RuleTester |
| 5 | +var ruleTester = new RuleTester() |
| 6 | + |
| 7 | +describe('dependency-graph', () => { |
| 8 | + const originalDepGraphImport = depGraph.imported |
| 9 | + beforeEach(() => { |
| 10 | + depGraph.imported = () => ({ |
| 11 | + identifiers: new Set(['a.js#*', 'b.js#foo', 'c.js#default']) |
| 12 | + }) |
| 13 | + }) |
| 14 | + |
| 15 | + afterEach(() => { |
| 16 | + depGraph.imported = originalDepGraphImport |
| 17 | + }) |
| 18 | + |
| 19 | + ruleTester.run('unused-export', rule, { |
| 20 | + valid: [ |
| 21 | + { |
| 22 | + code: 'export const foo = 1', |
| 23 | + parserOptions: {ecmaVersion: 2015, sourceType: 'module'}, |
| 24 | + filename: 'a.js' |
| 25 | + }, |
| 26 | + { |
| 27 | + code: 'export const foo = 1', |
| 28 | + parserOptions: {ecmaVersion: 2015, sourceType: 'module'}, |
| 29 | + filename: 'b.js' |
| 30 | + }, |
| 31 | + { |
| 32 | + code: 'export default 1', |
| 33 | + parserOptions: {ecmaVersion: 2015, sourceType: 'module'}, |
| 34 | + filename: 'c.js' |
| 35 | + } |
| 36 | + ], |
| 37 | + invalid: [ |
| 38 | + { |
| 39 | + code: 'export default 1', |
| 40 | + parserOptions: {ecmaVersion: 2015, sourceType: 'module'}, |
| 41 | + filename: 'b.js', |
| 42 | + errors: [ |
| 43 | + { |
| 44 | + message: 'Export was not imported by any modules.', |
| 45 | + type: 'ExportDefaultDeclaration' |
| 46 | + } |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + code: 'export const bar = 1', |
| 51 | + parserOptions: {ecmaVersion: 2015, sourceType: 'module'}, |
| 52 | + filename: 'b.js', |
| 53 | + errors: [ |
| 54 | + { |
| 55 | + message: 'Export was not imported by any modules.', |
| 56 | + type: 'ExportNamedDeclaration' |
| 57 | + } |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + code: 'export const foo = 1', |
| 62 | + parserOptions: {ecmaVersion: 2015, sourceType: 'module'}, |
| 63 | + filename: 'c.js', |
| 64 | + errors: [ |
| 65 | + { |
| 66 | + message: 'Export was not imported by any modules.', |
| 67 | + type: 'ExportNamedDeclaration' |
| 68 | + } |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + code: 'export default 1', |
| 73 | + parserOptions: {ecmaVersion: 2015, sourceType: 'module'}, |
| 74 | + filename: 'd.js', |
| 75 | + errors: [ |
| 76 | + { |
| 77 | + message: 'Export was not imported by any modules.', |
| 78 | + type: 'ExportDefaultDeclaration' |
| 79 | + } |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + code: 'export const foo = 1', |
| 84 | + parserOptions: {ecmaVersion: 2015, sourceType: 'module'}, |
| 85 | + filename: 'd.js', |
| 86 | + errors: [ |
| 87 | + { |
| 88 | + message: 'Export was not imported by any modules.', |
| 89 | + type: 'ExportNamedDeclaration' |
| 90 | + } |
| 91 | + ] |
| 92 | + } |
| 93 | + ] |
| 94 | + }) |
| 95 | +}) |
0 commit comments