|
| 1 | +import { RuleTester } from 'eslint'; |
| 2 | +import rule from '../no-export'; |
| 3 | + |
| 4 | +const ruleTester = new RuleTester({ |
| 5 | + parserOptions: { |
| 6 | + ecmaVersion: 2015, |
| 7 | + sourceType: 'module', |
| 8 | + }, |
| 9 | +}); |
| 10 | + |
| 11 | +ruleTester.run('no-export', rule, { |
| 12 | + valid: [ |
| 13 | + 'describe("a test", () => { expect(1).toBe(1); })', |
| 14 | + 'window.location = "valid"', |
| 15 | + 'module.somethingElse = "foo";', |
| 16 | + 'export const myThing = "valid"', |
| 17 | + 'export default function () {}', |
| 18 | + 'module.exports = function(){}', |
| 19 | + 'module.exports.myThing = "valid";', |
| 20 | + ], |
| 21 | + invalid: [ |
| 22 | + { |
| 23 | + code: |
| 24 | + 'export const myThing = "invalid"; test("a test", () => { expect(1).toBe(1);});', |
| 25 | + parserOptions: { sourceType: 'module' }, |
| 26 | + errors: [{ endColumn: 34, column: 1, messageId: 'unexpectedExport' }], |
| 27 | + }, |
| 28 | + { |
| 29 | + code: |
| 30 | + 'export default function() {}; test("a test", () => { expect(1).toBe(1);});', |
| 31 | + parserOptions: { sourceType: 'module' }, |
| 32 | + errors: [{ endColumn: 29, column: 1, messageId: 'unexpectedExport' }], |
| 33 | + }, |
| 34 | + { |
| 35 | + code: |
| 36 | + 'module.exports["invalid"] = function() {}; test("a test", () => { expect(1).toBe(1);});', |
| 37 | + errors: [{ endColumn: 26, column: 1, messageId: 'unexpectedExport' }], |
| 38 | + }, |
| 39 | + { |
| 40 | + code: |
| 41 | + 'module.exports = function() {}; ; test("a test", () => { expect(1).toBe(1);});', |
| 42 | + errors: [{ endColumn: 15, column: 1, messageId: 'unexpectedExport' }], |
| 43 | + }, |
| 44 | + { |
| 45 | + code: |
| 46 | + 'module.export.invalid = function() {}; ; test("a test", () => { expect(1).toBe(1);});', |
| 47 | + errors: [{ endColumn: 22, column: 1, messageId: 'unexpectedExport' }], |
| 48 | + }, |
| 49 | + ], |
| 50 | +}); |
0 commit comments