-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathcreate-testing-library-rule.test.ts
146 lines (138 loc) · 3.49 KB
/
create-testing-library-rule.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { createRuleTester } from './lib/test-utils';
import rule, { RULE_NAME } from './fake-rule';
const ruleTester = createRuleTester();
ruleTester.run(RULE_NAME, rule, {
valid: [
{
code: `
// case: nothing related to Testing Library at all
import { shallow } from 'enzyme';
const wrapper = shallow(<MyComponent />);
`,
},
{
code: `
// case: render imported from other than custom module
import { render } from '@somewhere/else'
const utils = render();
`,
settings: {
'testing-library/module': 'test-utils',
},
},
{
code: `
// case: prevent import which should trigger an error since it's imported
// from other than custom module
import { foo } from 'report-me'
`,
settings: {
'testing-library/module': 'test-utils',
},
},
{
code: `
// case: import module forced to be reported but not matching file name
import { foo } from 'report-me'
`,
settings: {
'testing-library/file-name': 'testing-library\\.js',
},
},
],
invalid: [
{
code: `
// case: import module forced to be reported
import { foo } from 'report-me'
`,
errors: [{ line: 3, column: 7, messageId: 'fakeError' }],
},
{
filename: 'MyComponent.spec.js',
code: `
// case: import module forced to be reported but from .spec.js named file
import { foo } from 'report-me'
`,
errors: [{ line: 3, column: 7, messageId: 'fakeError' }],
},
{
filename: 'MyComponent.testing-library.js',
code: `
// case: import module forced to be reported with custom file name
import { foo } from 'report-me'
`,
settings: {
'testing-library/file-name': 'testing-library\\.js',
},
errors: [{ line: 3, column: 7, messageId: 'fakeError' }],
},
{
code: `
// case: render imported from any module by default (aggressive reporting)
import { render } from '@somewhere/else'
import { somethingElse } from 'another-module'
const utils = render();
`,
errors: [
{
line: 6,
column: 21,
messageId: 'fakeError',
},
],
},
{
code: `
// case: render imported from Testing Library module
import { render } from '@testing-library/react'
import { somethingElse } from 'another-module'
const utils = render();
`,
errors: [
{
line: 6,
column: 21,
messageId: 'fakeError',
},
],
},
{
code: `
// case: render imported from config custom module
import { render } from 'test-utils'
import { somethingElse } from 'another-module'
const utils = render();
`,
settings: {
'testing-library/module': 'test-utils',
},
errors: [
{
line: 6,
column: 21,
messageId: 'fakeError',
},
],
},
{
code: `
// case: render imported from Testing Library module if
// custom module setup
import { render } from '@testing-library/react'
import { somethingElse } from 'another-module'
const utils = render();
`,
settings: {
'testing-library/module': 'test-utils',
},
errors: [
{
line: 7,
column: 21,
messageId: 'fakeError',
},
],
},
],
});