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