/
no-export.test.ts
86 lines (81 loc) · 2.59 KB
/
no-export.test.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { TSESLint } from '@typescript-eslint/experimental-utils';
import dedent from 'dedent';
import resolveFrom from 'resolve-from';
import rule from '../no-export';
const ruleTester = new TSESLint.RuleTester({
parser: resolveFrom(require.resolve('eslint'), 'espree'),
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: dedent`
export const myThing = 'invalid';
test.each()('my code', () => {
expect(1).toBe(1);
});
`,
parserOptions: { sourceType: 'module' },
errors: [{ endColumn: 34, column: 1, messageId: 'unexpectedExport' }],
},
{
code: dedent`
export const myThing = 'invalid';
test.each\`\`('my code', () => {
expect(1).toBe(1);
});
`,
parserOptions: { sourceType: 'module' },
errors: [{ endColumn: 34, column: 1, messageId: 'unexpectedExport' }],
},
{
code: dedent`
export const myThing = 'invalid';
test.only.each\`\`('my code', () => {
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' }],
},
],
});