Skip to content

Commit

Permalink
Correctly lint test helpers (#1281)
Browse files Browse the repository at this point in the history
Our test helper modules have been covered by ESLint as though they were
production code. This resulted in misleading coverage statistics and
various erronous lint errors (which we've handled by disabling rules in
affected files).

The ESLint configuration has been updated to consider any modules under
a `tests` directory to be test helpers.

This helps reduce the scope of #1116
  • Loading branch information
Gudahtt authored and MajorLift committed Oct 11, 2023
1 parent 158611e commit 061bbc1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
16 changes: 15 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,23 @@ module.exports = {
],
overrides: [
{
files: ['*.test.ts', '*.test.js'],
files: ['*.test.{ts,js}', '**/tests/**/*.{ts,js}'],
extends: ['@metamask/eslint-config-jest'],
},
{
// These files are test helpers, not tests. We still use the Jest ESLint
// config here to ensure that ESLint expects a test-like environment, but
// various rules meant just to apply to tests have been disabled.
files: ['**/tests/**/*.{ts,js}', '!*.test.{ts,js}'],
rules: {
'jest/no-export': 'off',
'jest/require-top-level-describe': 'off',
'jest/no-if': 'off',
'jest/no-test-return-statement': 'off',
// TODO: Re-enable this rule; we can accomodate this even in our test helpers
'jest/expect-expect': 'off',
},
},
{
files: ['*.js'],
parserOptions: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-loop-func */
import {
ProviderType,
waitForNextBlockTracker,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-loop-func */
import {
buildMockParams,
buildRequestWithReplacedBlockParam,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-loop-func */

import {
MockCommunications,
ProviderType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable jest/require-top-level-describe, jest/no-export, jest/no-identical-title, jest/no-if */

import { NetworkType } from '@metamask/controller-utils';
import { testsForRpcMethodsThatCheckForBlockHashInResponse } from './block-hash-in-response';
import { testsForRpcMethodSupportingBlockParam } from './block-param';
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const originalSetTimeout = global.setTimeout;
* times) until it returns a value.
*
* @param expectedValue - The value that the function should return.
* @param test - The function to call.
* @param operation - The function to call.
* @returns A promise that either resolves to a successful result as soon as it
* returns the expected value, or a failure result if that never happens.
*/
export async function waitForResult(
expectedValue: any,
test: () => any,
operation: () => any,
): Promise<{ pass: boolean; lastActualValue?: any }> {
const approximateRunTime = 10000;
const intervalBetweenRetries = 25;
Expand All @@ -22,7 +22,7 @@ export async function waitForResult(
let lastActualValue: any;

while (numIterations < maxNumIterations) {
const actualValue = test();
const actualValue = operation();
if (actualValue === expectedValue) {
return { pass: true };
}
Expand Down

0 comments on commit 061bbc1

Please sign in to comment.