@vitest/eslint-plugin 1.1.17 → 1.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +22 -6
- package/dist/index.d.cts +8 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.mjs +22 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ function _interopNamespaceCompat(e) {
|
|
|
23
23
|
const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
24
24
|
const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
|
|
25
25
|
|
|
26
|
-
const version = "1.1.
|
|
26
|
+
const version = "1.1.17";
|
|
27
27
|
|
|
28
28
|
function createEslintRule(rule) {
|
|
29
29
|
const createRule = utils.ESLintUtils.RuleCreator(
|
|
@@ -228,7 +228,7 @@ const parseVitestFnCallWithReasonInner = (node, context) => {
|
|
|
228
228
|
return null;
|
|
229
229
|
const name = resolved.original ?? resolved.local;
|
|
230
230
|
const links = [name, ...rest.map(getAccessorValue)];
|
|
231
|
-
if (name !== "vi" && name !== "expect" && name !== "expectTypeOf" && !ValidVitestFnCallChains.has(links.join(".")))
|
|
231
|
+
if (resolved.type !== "testContext" && name !== "vi" && name !== "expect" && name !== "expectTypeOf" && !ValidVitestFnCallChains.has(links.join(".")))
|
|
232
232
|
return null;
|
|
233
233
|
const parsedVitestFnCall = {
|
|
234
234
|
name,
|
|
@@ -313,6 +313,9 @@ const resolveScope = (scope, identifier) => {
|
|
|
313
313
|
if (key?.name === identifier)
|
|
314
314
|
return "testContext";
|
|
315
315
|
}
|
|
316
|
+
const namedParam = isFunction(def.node) ? def.node.params.find((params) => params.type === utils.AST_NODE_TYPES.Identifier) : void 0;
|
|
317
|
+
if (namedParam)
|
|
318
|
+
return "testContext";
|
|
316
319
|
const importDetails = describePossibleImportDef(def);
|
|
317
320
|
if (importDetails?.local === identifier)
|
|
318
321
|
return importDetails;
|
|
@@ -4088,6 +4091,7 @@ const preferExpectAssertions = createEslintRule({
|
|
|
4088
4091
|
let hasExpectInCallBack = false;
|
|
4089
4092
|
let hasExpectInLoop = false;
|
|
4090
4093
|
let hasExpectAssertAsFirstStatement = false;
|
|
4094
|
+
let testContextName = null;
|
|
4091
4095
|
let inTestCaseCall = false;
|
|
4092
4096
|
let inForLoop = false;
|
|
4093
4097
|
const shouldCheckFunction = (testFunction) => {
|
|
@@ -4161,6 +4165,9 @@ const preferExpectAssertions = createEslintRule({
|
|
|
4161
4165
|
inTestCaseCall = true;
|
|
4162
4166
|
return;
|
|
4163
4167
|
}
|
|
4168
|
+
if (vitestFnCall?.head.type === "testContext" && vitestFnCall.members[0].type === utils.AST_NODE_TYPES.Identifier && vitestFnCall.members[0].name === "expect") {
|
|
4169
|
+
testContextName = `${vitestFnCall.head.local}`;
|
|
4170
|
+
}
|
|
4164
4171
|
if (vitestFnCall?.type === "expect" && inTestCaseCall) {
|
|
4165
4172
|
if (expressionDepth === 1 && isFirstStatement(node) && vitestFnCall.head.node.parent?.type === utils.AST_NODE_TYPES.MemberExpression && vitestFnCall.members.length === 1 && ["assertions", "hasAssertions"].includes(getAccessorValue(vitestFnCall.members[0]))) {
|
|
4166
4173
|
checkExpectHasAssertions(vitestFnCall, node);
|
|
@@ -4189,9 +4196,10 @@ const preferExpectAssertions = createEslintRule({
|
|
|
4189
4196
|
}
|
|
4190
4197
|
const suggestions = [];
|
|
4191
4198
|
if (secondArg.body.type === utils.AST_NODE_TYPES.BlockStatement) {
|
|
4199
|
+
const prefix = testContextName ? `${testContextName}.` : "";
|
|
4192
4200
|
suggestions.push(
|
|
4193
|
-
["suggestAddingHasAssertions",
|
|
4194
|
-
["suggestAddingAssertions",
|
|
4201
|
+
["suggestAddingHasAssertions", `${prefix}expect.hasAssertions();`],
|
|
4202
|
+
["suggestAddingAssertions", `${prefix}expect.assertions();`]
|
|
4195
4203
|
);
|
|
4196
4204
|
}
|
|
4197
4205
|
context.report({
|
|
@@ -5009,6 +5017,8 @@ const plugin = {
|
|
|
5009
5017
|
test: "writable",
|
|
5010
5018
|
describe: "writable",
|
|
5011
5019
|
it: "writable",
|
|
5020
|
+
expectTypeOf: "writable",
|
|
5021
|
+
assertType: "writable",
|
|
5012
5022
|
expect: "writable",
|
|
5013
5023
|
assert: "writable",
|
|
5014
5024
|
vitest: "writable",
|
|
@@ -5016,7 +5026,9 @@ const plugin = {
|
|
|
5016
5026
|
beforeAll: "writable",
|
|
5017
5027
|
afterAll: "writable",
|
|
5018
5028
|
beforeEach: "writable",
|
|
5019
|
-
afterEach: "writable"
|
|
5029
|
+
afterEach: "writable",
|
|
5030
|
+
onTestFailed: "writable",
|
|
5031
|
+
onTestFinished: "writable"
|
|
5020
5032
|
}
|
|
5021
5033
|
}
|
|
5022
5034
|
}
|
|
@@ -5028,6 +5040,8 @@ const plugin = {
|
|
|
5028
5040
|
test: true,
|
|
5029
5041
|
describe: true,
|
|
5030
5042
|
it: true,
|
|
5043
|
+
expectTypeOf: true,
|
|
5044
|
+
assertType: true,
|
|
5031
5045
|
expect: true,
|
|
5032
5046
|
assert: true,
|
|
5033
5047
|
vitest: true,
|
|
@@ -5035,7 +5049,9 @@ const plugin = {
|
|
|
5035
5049
|
beforeAll: true,
|
|
5036
5050
|
afterAll: true,
|
|
5037
5051
|
beforeEach: true,
|
|
5038
|
-
afterEach: true
|
|
5052
|
+
afterEach: true,
|
|
5053
|
+
onTestFailed: true,
|
|
5054
|
+
onTestFinished: true
|
|
5039
5055
|
}
|
|
5040
5056
|
}
|
|
5041
5057
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -170,6 +170,8 @@ declare const plugin: {
|
|
|
170
170
|
test: "writable";
|
|
171
171
|
describe: "writable";
|
|
172
172
|
it: "writable";
|
|
173
|
+
expectTypeOf: "writable";
|
|
174
|
+
assertType: "writable";
|
|
173
175
|
expect: "writable";
|
|
174
176
|
assert: "writable";
|
|
175
177
|
vitest: "writable";
|
|
@@ -178,6 +180,8 @@ declare const plugin: {
|
|
|
178
180
|
afterAll: "writable";
|
|
179
181
|
beforeEach: "writable";
|
|
180
182
|
afterEach: "writable";
|
|
183
|
+
onTestFailed: "writable";
|
|
184
|
+
onTestFinished: "writable";
|
|
181
185
|
};
|
|
182
186
|
};
|
|
183
187
|
};
|
|
@@ -189,6 +193,8 @@ declare const plugin: {
|
|
|
189
193
|
test: true;
|
|
190
194
|
describe: true;
|
|
191
195
|
it: true;
|
|
196
|
+
expectTypeOf: true;
|
|
197
|
+
assertType: true;
|
|
192
198
|
expect: true;
|
|
193
199
|
assert: true;
|
|
194
200
|
vitest: true;
|
|
@@ -197,6 +203,8 @@ declare const plugin: {
|
|
|
197
203
|
afterAll: true;
|
|
198
204
|
beforeEach: true;
|
|
199
205
|
afterEach: true;
|
|
206
|
+
onTestFailed: true;
|
|
207
|
+
onTestFinished: true;
|
|
200
208
|
};
|
|
201
209
|
};
|
|
202
210
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -170,6 +170,8 @@ declare const plugin: {
|
|
|
170
170
|
test: "writable";
|
|
171
171
|
describe: "writable";
|
|
172
172
|
it: "writable";
|
|
173
|
+
expectTypeOf: "writable";
|
|
174
|
+
assertType: "writable";
|
|
173
175
|
expect: "writable";
|
|
174
176
|
assert: "writable";
|
|
175
177
|
vitest: "writable";
|
|
@@ -178,6 +180,8 @@ declare const plugin: {
|
|
|
178
180
|
afterAll: "writable";
|
|
179
181
|
beforeEach: "writable";
|
|
180
182
|
afterEach: "writable";
|
|
183
|
+
onTestFailed: "writable";
|
|
184
|
+
onTestFinished: "writable";
|
|
181
185
|
};
|
|
182
186
|
};
|
|
183
187
|
};
|
|
@@ -189,6 +193,8 @@ declare const plugin: {
|
|
|
189
193
|
test: true;
|
|
190
194
|
describe: true;
|
|
191
195
|
it: true;
|
|
196
|
+
expectTypeOf: true;
|
|
197
|
+
assertType: true;
|
|
192
198
|
expect: true;
|
|
193
199
|
assert: true;
|
|
194
200
|
vitest: true;
|
|
@@ -197,6 +203,8 @@ declare const plugin: {
|
|
|
197
203
|
afterAll: true;
|
|
198
204
|
beforeEach: true;
|
|
199
205
|
afterEach: true;
|
|
206
|
+
onTestFailed: true;
|
|
207
|
+
onTestFinished: true;
|
|
200
208
|
};
|
|
201
209
|
};
|
|
202
210
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -170,6 +170,8 @@ declare const plugin: {
|
|
|
170
170
|
test: "writable";
|
|
171
171
|
describe: "writable";
|
|
172
172
|
it: "writable";
|
|
173
|
+
expectTypeOf: "writable";
|
|
174
|
+
assertType: "writable";
|
|
173
175
|
expect: "writable";
|
|
174
176
|
assert: "writable";
|
|
175
177
|
vitest: "writable";
|
|
@@ -178,6 +180,8 @@ declare const plugin: {
|
|
|
178
180
|
afterAll: "writable";
|
|
179
181
|
beforeEach: "writable";
|
|
180
182
|
afterEach: "writable";
|
|
183
|
+
onTestFailed: "writable";
|
|
184
|
+
onTestFinished: "writable";
|
|
181
185
|
};
|
|
182
186
|
};
|
|
183
187
|
};
|
|
@@ -189,6 +193,8 @@ declare const plugin: {
|
|
|
189
193
|
test: true;
|
|
190
194
|
describe: true;
|
|
191
195
|
it: true;
|
|
196
|
+
expectTypeOf: true;
|
|
197
|
+
assertType: true;
|
|
192
198
|
expect: true;
|
|
193
199
|
assert: true;
|
|
194
200
|
vitest: true;
|
|
@@ -197,6 +203,8 @@ declare const plugin: {
|
|
|
197
203
|
afterAll: true;
|
|
198
204
|
beforeEach: true;
|
|
199
205
|
afterEach: true;
|
|
206
|
+
onTestFailed: true;
|
|
207
|
+
onTestFinished: true;
|
|
200
208
|
};
|
|
201
209
|
};
|
|
202
210
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { isAbsolute, posix } from 'node:path';
|
|
|
4
4
|
import ts from 'typescript';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
|
|
7
|
-
const version = "1.1.
|
|
7
|
+
const version = "1.1.17";
|
|
8
8
|
|
|
9
9
|
function createEslintRule(rule) {
|
|
10
10
|
const createRule = ESLintUtils.RuleCreator(
|
|
@@ -209,7 +209,7 @@ const parseVitestFnCallWithReasonInner = (node, context) => {
|
|
|
209
209
|
return null;
|
|
210
210
|
const name = resolved.original ?? resolved.local;
|
|
211
211
|
const links = [name, ...rest.map(getAccessorValue)];
|
|
212
|
-
if (name !== "vi" && name !== "expect" && name !== "expectTypeOf" && !ValidVitestFnCallChains.has(links.join(".")))
|
|
212
|
+
if (resolved.type !== "testContext" && name !== "vi" && name !== "expect" && name !== "expectTypeOf" && !ValidVitestFnCallChains.has(links.join(".")))
|
|
213
213
|
return null;
|
|
214
214
|
const parsedVitestFnCall = {
|
|
215
215
|
name,
|
|
@@ -294,6 +294,9 @@ const resolveScope = (scope, identifier) => {
|
|
|
294
294
|
if (key?.name === identifier)
|
|
295
295
|
return "testContext";
|
|
296
296
|
}
|
|
297
|
+
const namedParam = isFunction(def.node) ? def.node.params.find((params) => params.type === AST_NODE_TYPES.Identifier) : void 0;
|
|
298
|
+
if (namedParam)
|
|
299
|
+
return "testContext";
|
|
297
300
|
const importDetails = describePossibleImportDef(def);
|
|
298
301
|
if (importDetails?.local === identifier)
|
|
299
302
|
return importDetails;
|
|
@@ -4069,6 +4072,7 @@ const preferExpectAssertions = createEslintRule({
|
|
|
4069
4072
|
let hasExpectInCallBack = false;
|
|
4070
4073
|
let hasExpectInLoop = false;
|
|
4071
4074
|
let hasExpectAssertAsFirstStatement = false;
|
|
4075
|
+
let testContextName = null;
|
|
4072
4076
|
let inTestCaseCall = false;
|
|
4073
4077
|
let inForLoop = false;
|
|
4074
4078
|
const shouldCheckFunction = (testFunction) => {
|
|
@@ -4142,6 +4146,9 @@ const preferExpectAssertions = createEslintRule({
|
|
|
4142
4146
|
inTestCaseCall = true;
|
|
4143
4147
|
return;
|
|
4144
4148
|
}
|
|
4149
|
+
if (vitestFnCall?.head.type === "testContext" && vitestFnCall.members[0].type === AST_NODE_TYPES.Identifier && vitestFnCall.members[0].name === "expect") {
|
|
4150
|
+
testContextName = `${vitestFnCall.head.local}`;
|
|
4151
|
+
}
|
|
4145
4152
|
if (vitestFnCall?.type === "expect" && inTestCaseCall) {
|
|
4146
4153
|
if (expressionDepth === 1 && isFirstStatement(node) && vitestFnCall.head.node.parent?.type === AST_NODE_TYPES.MemberExpression && vitestFnCall.members.length === 1 && ["assertions", "hasAssertions"].includes(getAccessorValue(vitestFnCall.members[0]))) {
|
|
4147
4154
|
checkExpectHasAssertions(vitestFnCall, node);
|
|
@@ -4170,9 +4177,10 @@ const preferExpectAssertions = createEslintRule({
|
|
|
4170
4177
|
}
|
|
4171
4178
|
const suggestions = [];
|
|
4172
4179
|
if (secondArg.body.type === AST_NODE_TYPES.BlockStatement) {
|
|
4180
|
+
const prefix = testContextName ? `${testContextName}.` : "";
|
|
4173
4181
|
suggestions.push(
|
|
4174
|
-
["suggestAddingHasAssertions",
|
|
4175
|
-
["suggestAddingAssertions",
|
|
4182
|
+
["suggestAddingHasAssertions", `${prefix}expect.hasAssertions();`],
|
|
4183
|
+
["suggestAddingAssertions", `${prefix}expect.assertions();`]
|
|
4176
4184
|
);
|
|
4177
4185
|
}
|
|
4178
4186
|
context.report({
|
|
@@ -4990,6 +4998,8 @@ const plugin = {
|
|
|
4990
4998
|
test: "writable",
|
|
4991
4999
|
describe: "writable",
|
|
4992
5000
|
it: "writable",
|
|
5001
|
+
expectTypeOf: "writable",
|
|
5002
|
+
assertType: "writable",
|
|
4993
5003
|
expect: "writable",
|
|
4994
5004
|
assert: "writable",
|
|
4995
5005
|
vitest: "writable",
|
|
@@ -4997,7 +5007,9 @@ const plugin = {
|
|
|
4997
5007
|
beforeAll: "writable",
|
|
4998
5008
|
afterAll: "writable",
|
|
4999
5009
|
beforeEach: "writable",
|
|
5000
|
-
afterEach: "writable"
|
|
5010
|
+
afterEach: "writable",
|
|
5011
|
+
onTestFailed: "writable",
|
|
5012
|
+
onTestFinished: "writable"
|
|
5001
5013
|
}
|
|
5002
5014
|
}
|
|
5003
5015
|
}
|
|
@@ -5009,6 +5021,8 @@ const plugin = {
|
|
|
5009
5021
|
test: true,
|
|
5010
5022
|
describe: true,
|
|
5011
5023
|
it: true,
|
|
5024
|
+
expectTypeOf: true,
|
|
5025
|
+
assertType: true,
|
|
5012
5026
|
expect: true,
|
|
5013
5027
|
assert: true,
|
|
5014
5028
|
vitest: true,
|
|
@@ -5016,7 +5030,9 @@ const plugin = {
|
|
|
5016
5030
|
beforeAll: true,
|
|
5017
5031
|
afterAll: true,
|
|
5018
5032
|
beforeEach: true,
|
|
5019
|
-
afterEach: true
|
|
5033
|
+
afterEach: true,
|
|
5034
|
+
onTestFailed: true,
|
|
5035
|
+
onTestFinished: true
|
|
5020
5036
|
}
|
|
5021
5037
|
}
|
|
5022
5038
|
}
|