@@ -15,8 +15,18 @@ ruleTester.run('prefer-importing-jest-globals', rule, {
15
15
valid : [
16
16
{
17
17
code : dedent `
18
+ // with import
18
19
import { test, expect } from '@jest/globals';
19
-
20
+ test('should pass', () => {
21
+ expect(true).toBeDefined();
22
+ });
23
+ ` ,
24
+ parserOptions : { sourceType : 'module' } ,
25
+ } ,
26
+ {
27
+ code : dedent `
28
+ // with require
29
+ const { test, expect } = require('@jest/globals');
20
30
test('should pass', () => {
21
31
expect(true).toBeDefined();
22
32
});
@@ -26,15 +36,13 @@ ruleTester.run('prefer-importing-jest-globals', rule, {
26
36
{
27
37
code : dedent `
28
38
import { it as itChecks } from '@jest/globals';
29
-
30
39
itChecks("foo");
31
40
` ,
32
41
parserOptions : { sourceType : 'module' } ,
33
42
} ,
34
43
{
35
44
code : dedent `
36
45
const { test } = require('@jest/globals');
37
-
38
46
test("foo");
39
47
` ,
40
48
parserOptions : { sourceType : 'module' } ,
@@ -43,13 +51,97 @@ ruleTester.run('prefer-importing-jest-globals', rule, {
43
51
invalid : [
44
52
{
45
53
code : dedent `
54
+ #!/usr/bin/env node
55
+ describe("suite", () => {
56
+ test("foo");
57
+ expect(true).toBeDefined();
58
+ })
59
+ ` ,
60
+ output : dedent `
61
+ #!/usr/bin/env node
62
+ const { describe, test, expect } = require('@jest/globals');
63
+ describe("suite", () => {
64
+ test("foo");
65
+ expect(true).toBeDefined();
66
+ })
67
+ ` ,
68
+ parserOptions : { sourceType : 'module' } ,
69
+ errors : [
70
+ { endColumn : 3 , column : 1 , messageId : 'preferImportingJestGlobal' } ,
71
+ ] ,
72
+ } ,
73
+ {
74
+ code : dedent `
75
+ // with comment above
76
+ describe("suite", () => {
77
+ test("foo");
78
+ expect(true).toBeDefined();
79
+ })
80
+ ` ,
81
+ output : dedent `
82
+ // with comment above
83
+ const { describe, test, expect } = require('@jest/globals');
84
+ describe("suite", () => {
85
+ test("foo");
86
+ expect(true).toBeDefined();
87
+ })
88
+ ` ,
89
+ parserOptions : { sourceType : 'module' } ,
90
+ errors : [
91
+ { endColumn : 3 , column : 1 , messageId : 'preferImportingJestGlobal' } ,
92
+ ] ,
93
+ } ,
94
+ {
95
+ code : dedent `
96
+ 'use strict';
97
+ describe("suite", () => {
98
+ test("foo");
99
+ expect(true).toBeDefined();
100
+ })
101
+ ` ,
102
+ output : dedent `
103
+ 'use strict';
104
+ const { describe, test, expect } = require('@jest/globals');
105
+ describe("suite", () => {
106
+ test("foo");
107
+ expect(true).toBeDefined();
108
+ })
109
+ ` ,
110
+ parserOptions : { sourceType : 'module' } ,
111
+ errors : [
112
+ { endColumn : 3 , column : 1 , messageId : 'preferImportingJestGlobal' } ,
113
+ ] ,
114
+ } ,
115
+ {
116
+ code : dedent `
117
+ import { test } from '@jest/globals';
118
+ describe("suite", () => {
119
+ test("foo");
120
+ expect(true).toBeDefined();
121
+ })
122
+ ` ,
123
+ output : dedent `
124
+ import { test, describe, expect } from '@jest/globals';
125
+ describe("suite", () => {
126
+ test("foo");
127
+ expect(true).toBeDefined();
128
+ })
129
+ ` ,
130
+ parserOptions : { sourceType : 'module' } ,
131
+ errors : [
132
+ { endColumn : 3 , column : 1 , messageId : 'preferImportingJestGlobal' } ,
133
+ ] ,
134
+ } ,
135
+ {
136
+ code : dedent `
137
+ const { test } = require('@jest/globals');
46
138
describe("suite", () => {
47
139
test("foo");
48
140
expect(true).toBeDefined();
49
141
})
50
142
` ,
51
143
output : dedent `
52
- import { describe, test , expect } from '@jest/globals';
144
+ const { test, describe , expect } = require( '@jest/globals') ;
53
145
describe("suite", () => {
54
146
test("foo");
55
147
expect(true).toBeDefined();
@@ -60,5 +152,24 @@ ruleTester.run('prefer-importing-jest-globals', rule, {
60
152
{ endColumn : 3 , column : 1 , messageId : 'preferImportingJestGlobal' } ,
61
153
] ,
62
154
} ,
155
+ {
156
+ code : dedent `
157
+ const { pending } = require('actions');
158
+ describe('foo', () => {
159
+ test.each(['hello', 'world'])("%s", (a) => {});
160
+ });
161
+ ` ,
162
+ output : dedent `
163
+ const { describe, test } = require('@jest/globals');
164
+ const { pending } = require('actions');
165
+ describe('foo', () => {
166
+ test.each(['hello', 'world'])("%s", (a) => {});
167
+ });
168
+ ` ,
169
+ parserOptions : { sourceType : 'module' } ,
170
+ errors : [
171
+ { endColumn : 4 , column : 1 , messageId : 'preferImportingJestGlobal' } ,
172
+ ] ,
173
+ } ,
63
174
] ,
64
175
} ) ;
0 commit comments