Skip to content

Commit ed889bc

Browse files
authored
chore(eslint): Add lint rules for disabled or focused tests (#8489)
We sometimes forget to remove focused or disabled annotations after debugging tests. This of course isn't ideal and as brought up in #8485 we should add checks against this. Therefore, this patch: * Adds the [`eslint-plugin-jest` package ](https://github.com/jest-community/eslint-plugin-jest/tree/main)which contains a bunch of jest-syntax-specific rules * Enables the `no-focused-tests` rule to throw a lint error if a test is focused with `it.only`, `fit` or similar functions. * Enables the `no-disabled-tests` rule to throw a lint error if a test (suite) from a suite is disabled/skipped with `it.skip`, `xit` or similar functions. While we sometimes skip tests on purpose, I'd argue that we generally want to avoid this, as it can also happen accidentally. For the few exceptions of this rule, we can always ignore it.
1 parent cfd2149 commit ed889bc

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-1
lines changed

packages/core/test/lib/transports/offline.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ describe('makeOfflineTransport', () => {
326326
expect(getCalls()).toEqual([]);
327327
});
328328

329+
// eslint-disable-next-line jest/no-disabled-tests
329330
it.skip(
330331
'Follows the Retry-After header',
331332
async () => {

packages/eslint-config-sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"eslint-config-prettier": "^6.11.0",
2727
"eslint-plugin-deprecation": "^1.1.0",
2828
"eslint-plugin-import": "^2.22.0",
29+
"eslint-plugin-jest": "^27.2.2",
2930
"eslint-plugin-jsdoc": "^30.0.3",
3031
"eslint-plugin-simple-import-sort": "^5.0.3"
3132
},

packages/eslint-config-sdk/src/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module.exports = {
167167
},
168168
},
169169
{
170-
// Configuration for test files
170+
// Configuration for files in test directories
171171
env: {
172172
jest: true,
173173
},
@@ -186,6 +186,24 @@ module.exports = {
186186
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
187187
},
188188
},
189+
{
190+
// Configuration only for test files (this won't apply to utils or other files in test directories)
191+
plugins: ['jest'],
192+
env: {
193+
jest: true,
194+
},
195+
files: ['test.ts', '*.test.ts', '*.test.tsx', '*.test.js', '*.test.jsx'],
196+
rules: {
197+
// Prevent permanent usage of `it.only`, `fit`, `test.only` etc
198+
// We want to avoid debugging leftovers making their way into the codebase
199+
'jest/no-focused-tests': 'error',
200+
201+
// Prevent permanent usage of `it.skip`, `xit`, `test.skip` etc
202+
// We want to avoid debugging leftovers making their way into the codebase
203+
// If there's a good reason to skip a test (e.g. bad flakiness), just add an ignore comment
204+
'jest/no-disabled-tests': 'error',
205+
},
206+
},
189207
{
190208
// Configuration for config files like webpack/rollup
191209
files: ['*.config.js'],

packages/node/test/integrations/undici.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
194194
});
195195

196196
// This flakes on CI for some reason: https://github.com/getsentry/sentry-javascript/pull/8449
197+
// eslint-disable-next-line jest/no-disabled-tests
197198
it.skip('attaches the sentry trace and baggage headers if there is an active span', async () => {
198199
expect.assertions(3);
199200

@@ -214,6 +215,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
214215
});
215216

216217
// This flakes on CI for some reason: https://github.com/getsentry/sentry-javascript/pull/8449
218+
// eslint-disable-next-line jest/no-disabled-tests
217219
it.skip('attaches the sentry trace and baggage headers if there is no active span', async () => {
218220
const scope = hub.getScope();
219221

@@ -228,6 +230,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
228230
});
229231

230232
// This flakes on CI for some reason: https://github.com/getsentry/sentry-javascript/pull/8449
233+
// eslint-disable-next-line jest/no-disabled-tests
231234
it.skip('attaches headers if `shouldCreateSpanForRequest` does not create a span using propagation context', async () => {
232235
const transaction = hub.startTransaction({ name: 'test-transaction' }) as Transaction;
233236
const scope = hub.getScope();
@@ -259,6 +262,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
259262
});
260263

261264
// This flakes on CI for some reason: https://github.com/getsentry/sentry-javascript/pull/8449
265+
// eslint-disable-next-line jest/no-disabled-tests
262266
it.skip('uses tracePropagationTargets', async () => {
263267
const transaction = hub.startTransaction({ name: 'test-transaction' }) as Transaction;
264268
hub.getScope().setSpan(transaction);

yarn.lock

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,13 @@
24832483
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.16.17.tgz#c5a1a4bfe1b57f0c3e61b29883525c6da3e5c091"
24842484
integrity sha512-y+EHuSchhL7FjHgvQL/0fnnFmO4T1bhvWANX6gcnqTjtnKWbTvUMCpGnv2+t+31d7RzyEAYAd4u2fnIhHL6N/Q==
24852485

2486+
"@eslint-community/eslint-utils@^4.2.0":
2487+
version "4.4.0"
2488+
resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59"
2489+
integrity sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==
2490+
dependencies:
2491+
eslint-visitor-keys "^3.3.0"
2492+
24862493
"@eslint/eslintrc@^0.4.3":
24872494
version "0.4.3"
24882495
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.3.tgz#9e42981ef035beb3dd49add17acb96e8ff6f394c"
@@ -5304,6 +5311,14 @@
53045311
"@typescript-eslint/types" "5.48.0"
53055312
"@typescript-eslint/visitor-keys" "5.48.0"
53065313

5314+
"@typescript-eslint/[email protected]":
5315+
version "5.62.0"
5316+
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz#d9457ccc6a0b8d6b37d0eb252a23022478c5460c"
5317+
integrity sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w==
5318+
dependencies:
5319+
"@typescript-eslint/types" "5.62.0"
5320+
"@typescript-eslint/visitor-keys" "5.62.0"
5321+
53075322
"@typescript-eslint/[email protected]":
53085323
version "5.48.0"
53095324
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.48.0.tgz#40496dccfdc2daa14a565f8be80ad1ae3882d6d6"
@@ -5329,6 +5344,11 @@
53295344
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.48.0.tgz#d725da8dfcff320aab2ac6f65c97b0df30058449"
53305345
integrity sha512-UTe67B0Ypius0fnEE518NB2N8gGutIlTojeTg4nt0GQvikReVkurqxd2LvYa9q9M5MQ6rtpNyWTBxdscw40Xhw==
53315346

5347+
"@typescript-eslint/[email protected]":
5348+
version "5.62.0"
5349+
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f"
5350+
integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==
5351+
53325352
"@typescript-eslint/[email protected]":
53335353
version "3.10.1"
53345354
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.10.1.tgz#fd0061cc38add4fad45136d654408569f365b853"
@@ -5356,6 +5376,19 @@
53565376
semver "^7.3.7"
53575377
tsutils "^3.21.0"
53585378

5379+
"@typescript-eslint/[email protected]":
5380+
version "5.62.0"
5381+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz#7d17794b77fabcac615d6a48fb143330d962eb9b"
5382+
integrity sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==
5383+
dependencies:
5384+
"@typescript-eslint/types" "5.62.0"
5385+
"@typescript-eslint/visitor-keys" "5.62.0"
5386+
debug "^4.3.4"
5387+
globby "^11.1.0"
5388+
is-glob "^4.0.3"
5389+
semver "^7.3.7"
5390+
tsutils "^3.21.0"
5391+
53595392
"@typescript-eslint/typescript-estree@^4.8.2":
53605393
version "4.23.0"
53615394
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.23.0.tgz#0753b292097523852428a6f5a1aa8ccc1aae6cd9"
@@ -5383,6 +5416,20 @@
53835416
eslint-utils "^3.0.0"
53845417
semver "^7.3.7"
53855418

5419+
"@typescript-eslint/utils@^5.10.0":
5420+
version "5.62.0"
5421+
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.62.0.tgz#141e809c71636e4a75daa39faed2fb5f4b10df86"
5422+
integrity sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==
5423+
dependencies:
5424+
"@eslint-community/eslint-utils" "^4.2.0"
5425+
"@types/json-schema" "^7.0.9"
5426+
"@types/semver" "^7.3.12"
5427+
"@typescript-eslint/scope-manager" "5.62.0"
5428+
"@typescript-eslint/types" "5.62.0"
5429+
"@typescript-eslint/typescript-estree" "5.62.0"
5430+
eslint-scope "^5.1.1"
5431+
semver "^7.3.7"
5432+
53865433
"@typescript-eslint/[email protected]":
53875434
version "3.10.1"
53885435
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-3.10.1.tgz#cd4274773e3eb63b2e870ac602274487ecd1e931"
@@ -5406,6 +5453,14 @@
54065453
"@typescript-eslint/types" "5.48.0"
54075454
eslint-visitor-keys "^3.3.0"
54085455

5456+
"@typescript-eslint/[email protected]":
5457+
version "5.62.0"
5458+
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz#2174011917ce582875954ffe2f6912d5931e353e"
5459+
integrity sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw==
5460+
dependencies:
5461+
"@typescript-eslint/types" "5.62.0"
5462+
eslint-visitor-keys "^3.3.0"
5463+
54095464
"@vitest/coverage-c8@^0.29.2":
54105465
version "0.29.2"
54115466
resolved "https://registry.yarnpkg.com/@vitest/coverage-c8/-/coverage-c8-0.29.2.tgz#30b81e32ff11c20e2f3ab78c84e21b4c6c08190c"
@@ -12491,6 +12546,13 @@ eslint-plugin-import@^2.22.0:
1249112546
resolve "^1.17.0"
1249212547
tsconfig-paths "^3.9.0"
1249312548

12549+
eslint-plugin-jest@^27.2.2:
12550+
version "27.2.2"
12551+
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-27.2.2.tgz#be4ded5f91905d9ec89aa8968d39c71f3b072c0c"
12552+
integrity sha512-euzbp06F934Z7UDl5ZUaRPLAc9MKjh0rMPERrHT7UhlCEwgb25kBj37TvMgWeHZVkR5I9CayswrpoaqZU1RImw==
12553+
dependencies:
12554+
"@typescript-eslint/utils" "^5.10.0"
12555+
1249412556
eslint-plugin-jsdoc@^30.0.3:
1249512557
version "30.7.13"
1249612558
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-30.7.13.tgz#52e5c74fb806d3bbeb51d04a0c829508c3c6b563"

0 commit comments

Comments
 (0)