From 2fbb2cc3fca2540736acab89c1cab7460b2a38d2 Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Thu, 31 Oct 2024 11:03:00 +0100 Subject: [PATCH] chore: test code quality improvements (#520) --- .editorconfig | 2 +- .eslintrc.cjs | 2 -- app.vue | 4 +--- components/__tests__/AppLinks.spec.ts | 4 ---- components/__tests__/AssetStandardBadge.spec.ts | 1 - components/__tests__/FollowCounters.spec.ts | 5 +++-- components/__tests__/LinkButton.spec.ts | 4 ---- .../__tests__/AppNavbarProfileSearchGraph.spec.ts | 1 - domains/grid/components/__tests__/GridFloatingMenu.spec.ts | 1 + domains/grid/utils/__tests__/buildGrid.spec.ts | 2 +- domains/grid/utils/__tests__/compareGridWidgets.spec.ts | 1 + domains/grid/utils/__tests__/compareGrids.spec.ts | 1 + domains/grid/utils/__tests__/createGridId.spec.ts | 1 + domains/grid/utils/__tests__/createWidgetObject.spec.ts | 1 + domains/grid/utils/__tests__/gridParser.spec.ts | 1 + domains/grid/utils/__tests__/gridToConfig.spec.ts | 3 ++- domains/grid/utils/__tests__/purifyGridConfig.spec.ts | 3 ++- pages/settings/data-provider/__tests__/index.spec.ts | 3 +-- services/ipfs/formdata-base-client.ts | 4 +--- tests/e2e/404.spec.ts | 1 + tests/e2e/index.spec.ts | 1 + utils/__tests__/assetChecks.spec.ts | 6 +----- utils/__tests__/assetTypes.spec.ts | 1 + utils/__tests__/cloneObject.spec.ts | 1 + utils/__tests__/decodeParameter.spec.ts | 1 + utils/__tests__/deepEqual.spec.ts | 1 + utils/__tests__/externalUrls.spec.ts | 1 + utils/__tests__/groupAttributes.spec.ts | 1 + utils/__tests__/hexToNumber.spec.ts | 1 + utils/__tests__/hexToUtf8.spec.ts | 1 + utils/__tests__/isValidURL.spec.ts | 1 + utils/__tests__/paddedToAddress.spec.ts | 1 + utils/__tests__/queryParamsString.spec.ts | 1 + utils/__tests__/slug.spec.ts | 1 + utils/__tests__/sort.spec.ts | 1 + utils/__tests__/tokenConversionWithDecimals.spec.ts | 1 + utils/__tests__/truncate.spec.ts | 1 + utils/__tests__/unflatArray.spec.ts | 3 ++- utils/__tests__/validateLspMetadata.spec.ts | 2 +- utils/__tests__/validators.spec.ts | 1 + 40 files changed, 40 insertions(+), 33 deletions(-) diff --git a/.editorconfig b/.editorconfig index 1ed453a3..673aefad 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,7 +4,7 @@ root = true end_of_line = lf insert_final_newline = true -[*.{js,json,yml}] +[*.{js,ts,json,yml}] charset = utf-8 indent_style = space indent_size = 2 diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 3baa2ac8..35f205f7 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -78,8 +78,6 @@ module.exports = { files: ['**/*.spec.ts'], extends: ['plugin:playwright/playwright-test'], rules: { - 'import/order': 'off', - '@typescript-eslint/no-unused-vars': 'off', 'playwright/no-standalone-expect': 'off', 'playwright/no-networkidle': 'off', 'playwright/no-skipped-test': 'off', diff --git a/app.vue b/app.vue index ea43d67f..d5454ada 100644 --- a/app.vue +++ b/app.vue @@ -120,9 +120,7 @@ const setupNetwork = async () => { } } else { console.warn( - `Invalid network: ${network}, valid networks are ${SUPPORTED_NETWORK_IDS.join( - ', ' - )}` + `Invalid network: ${network}, valid networks are ${SUPPORTED_NETWORK_IDS.join(', ')}` ) } } diff --git a/components/__tests__/AppLinks.spec.ts b/components/__tests__/AppLinks.spec.ts index f06117e1..bf7df62f 100644 --- a/components/__tests__/AppLinks.spec.ts +++ b/components/__tests__/AppLinks.spec.ts @@ -4,10 +4,6 @@ import { describe, expect, it } from 'vitest' import AppLinks from '@/components/AppLinks.vue' describe('AppLinks', () => { - const profile: Profile = { - address: '0x1234567890abcdef1234567890abcdef12345678', - } - it('should render empty links', async () => { const component = await renderSuspended(AppLinks, { props: { diff --git a/components/__tests__/AssetStandardBadge.spec.ts b/components/__tests__/AssetStandardBadge.spec.ts index c2ee18e8..228dcc00 100644 --- a/components/__tests__/AssetStandardBadge.spec.ts +++ b/components/__tests__/AssetStandardBadge.spec.ts @@ -1,5 +1,4 @@ import { renderSuspended } from '@nuxt/test-utils/runtime' -import { fireEvent, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it } from 'vitest' import AssetStandardBadge from '@/components/AssetStandardBadge.vue' diff --git a/components/__tests__/FollowCounters.spec.ts b/components/__tests__/FollowCounters.spec.ts index 7040065e..686376aa 100644 --- a/components/__tests__/FollowCounters.spec.ts +++ b/components/__tests__/FollowCounters.spec.ts @@ -1,9 +1,10 @@ import { renderSuspended } from '@nuxt/test-utils/runtime' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it } from 'vitest' -import type { ProfileFollowers } from '@/types/profile' import FollowCounters from '../FollowCounters.vue' +import type { ProfileFollowers } from '@/types/profile' + describe('FollowCounters', () => { beforeEach(() => { useIntl().setupIntl(defaultConfig) diff --git a/components/__tests__/LinkButton.spec.ts b/components/__tests__/LinkButton.spec.ts index 118f244d..991ec11b 100644 --- a/components/__tests__/LinkButton.spec.ts +++ b/components/__tests__/LinkButton.spec.ts @@ -4,10 +4,6 @@ import { describe, expect, it } from 'vitest' import LinkButton from '@/components/LinkButton.vue' describe('LinkButton', () => { - const profile: Profile = { - address: '0x1234567890abcdef1234567890abcdef12345678', - } - it('should render empty state', async () => { const component = await renderSuspended(LinkButton, {}) diff --git a/domains/graph/components/__tests__/AppNavbarProfileSearchGraph.spec.ts b/domains/graph/components/__tests__/AppNavbarProfileSearchGraph.spec.ts index ad444424..90c6a9b7 100644 --- a/domains/graph/components/__tests__/AppNavbarProfileSearchGraph.spec.ts +++ b/domains/graph/components/__tests__/AppNavbarProfileSearchGraph.spec.ts @@ -1,5 +1,4 @@ import { renderSuspended } from '@nuxt/test-utils/runtime' -import { fireEvent, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it } from 'vitest' import AppNavbarProfileSearchGraph from '../AppNavbarProfileSearchGraph.vue' diff --git a/domains/grid/components/__tests__/GridFloatingMenu.spec.ts b/domains/grid/components/__tests__/GridFloatingMenu.spec.ts index d0060fe0..4007065d 100644 --- a/domains/grid/components/__tests__/GridFloatingMenu.spec.ts +++ b/domains/grid/components/__tests__/GridFloatingMenu.spec.ts @@ -1,6 +1,7 @@ import { renderSuspended } from '@nuxt/test-utils/runtime' import { createTestingPinia } from '@pinia/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' + import GridFloatingMenu from '../GridFloatingMenu.vue' vi.mock('/utils/getCurrentProfileAddress', () => ({ diff --git a/domains/grid/utils/__tests__/buildGrid.spec.ts b/domains/grid/utils/__tests__/buildGrid.spec.ts index a7be65cb..6c47f3f6 100644 --- a/domains/grid/utils/__tests__/buildGrid.spec.ts +++ b/domains/grid/utils/__tests__/buildGrid.spec.ts @@ -1,5 +1,5 @@ -import { e } from 'pinia-orm/dist/shared/pinia-orm.ed84a779' import { describe, expect, it } from 'vitest' + import { buildGrid } from '../buildGrid' describe('buildGrid', () => { diff --git a/domains/grid/utils/__tests__/compareGridWidgets.spec.ts b/domains/grid/utils/__tests__/compareGridWidgets.spec.ts index 69cd8d9f..8acb8406 100644 --- a/domains/grid/utils/__tests__/compareGridWidgets.spec.ts +++ b/domains/grid/utils/__tests__/compareGridWidgets.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { compareGridWidgets } from '../compareGridWidgets' describe('compareGridWidgets', () => { diff --git a/domains/grid/utils/__tests__/compareGrids.spec.ts b/domains/grid/utils/__tests__/compareGrids.spec.ts index 5f94d49a..8af892f4 100644 --- a/domains/grid/utils/__tests__/compareGrids.spec.ts +++ b/domains/grid/utils/__tests__/compareGrids.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { compareGrids } from '../compareGrids' describe('compareGrids', () => { diff --git a/domains/grid/utils/__tests__/createGridId.spec.ts b/domains/grid/utils/__tests__/createGridId.spec.ts index 8d610a14..c39d3049 100644 --- a/domains/grid/utils/__tests__/createGridId.spec.ts +++ b/domains/grid/utils/__tests__/createGridId.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { createGridId } from '../createGridId' describe('createGridId', () => { diff --git a/domains/grid/utils/__tests__/createWidgetObject.spec.ts b/domains/grid/utils/__tests__/createWidgetObject.spec.ts index 4089882d..4fe2bb1d 100644 --- a/domains/grid/utils/__tests__/createWidgetObject.spec.ts +++ b/domains/grid/utils/__tests__/createWidgetObject.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it, vi } from 'vitest' + import { createWidgetObject } from '../createWidgetObject' vi.mock('/domains/grid/utils/generateItemId', () => ({ diff --git a/domains/grid/utils/__tests__/gridParser.spec.ts b/domains/grid/utils/__tests__/gridParser.spec.ts index 13b282af..0c1b1dc7 100644 --- a/domains/grid/utils/__tests__/gridParser.spec.ts +++ b/domains/grid/utils/__tests__/gridParser.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { parsePlatformInput } from '../gridParser' const YOUTUBE_IFRAME_ALLOW = diff --git a/domains/grid/utils/__tests__/gridToConfig.spec.ts b/domains/grid/utils/__tests__/gridToConfig.spec.ts index d3348443..b3930470 100644 --- a/domains/grid/utils/__tests__/gridToConfig.spec.ts +++ b/domains/grid/utils/__tests__/gridToConfig.spec.ts @@ -1,4 +1,5 @@ -import { describe, expect, it, vi } from 'vitest' +import { describe, expect, it } from 'vitest' + import { gridToConfig } from '../gridToConfig' describe('gridToConfig', () => { diff --git a/domains/grid/utils/__tests__/purifyGridConfig.spec.ts b/domains/grid/utils/__tests__/purifyGridConfig.spec.ts index bbfd4d08..e2313ea6 100644 --- a/domains/grid/utils/__tests__/purifyGridConfig.spec.ts +++ b/domains/grid/utils/__tests__/purifyGridConfig.spec.ts @@ -1,4 +1,5 @@ -import { describe, expect, it, vi } from 'vitest' +import { describe, expect, it } from 'vitest' + import { purifyGridConfig } from '../purifyGridConfig' describe('purifyGridConfig', () => { diff --git a/pages/settings/data-provider/__tests__/index.spec.ts b/pages/settings/data-provider/__tests__/index.spec.ts index 74b3f8c1..50408990 100644 --- a/pages/settings/data-provider/__tests__/index.spec.ts +++ b/pages/settings/data-provider/__tests__/index.spec.ts @@ -1,8 +1,7 @@ import { renderSuspended } from '@nuxt/test-utils/runtime' import { createTestingPinia } from '@pinia/testing' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it } from 'vitest' -import { useAppStore } from '@/stores/app' import Index from '../index.vue' describe('Settings data-provider page', () => { diff --git a/services/ipfs/formdata-base-client.ts b/services/ipfs/formdata-base-client.ts index 1be416d1..53a2568c 100644 --- a/services/ipfs/formdata-base-client.ts +++ b/services/ipfs/formdata-base-client.ts @@ -131,9 +131,7 @@ export class BaseFormDataUploader { error = (error as any).error || error throw new NetworkError( new Error( - `unknown server response while pinning File to IPFS: ${ - error || response.status - }` + `unknown server response while pinning File to IPFS: ${error || response.status}` ), response.status ) diff --git a/tests/e2e/404.spec.ts b/tests/e2e/404.spec.ts index dcf8ba79..35d21eda 100644 --- a/tests/e2e/404.spec.ts +++ b/tests/e2e/404.spec.ts @@ -1,4 +1,5 @@ import { expect } from '@playwright/test' + import { test } from './helpers/fixtures' test('can access 404 page', async ({ page }) => { diff --git a/tests/e2e/index.spec.ts b/tests/e2e/index.spec.ts index 22040702..fb16bb90 100644 --- a/tests/e2e/index.spec.ts +++ b/tests/e2e/index.spec.ts @@ -1,4 +1,5 @@ import { expect } from '@playwright/test' + import { test } from './helpers/fixtures' test('landing page when no browser extension', async ({ page }) => { diff --git a/utils/__tests__/assetChecks.spec.ts b/utils/__tests__/assetChecks.spec.ts index a5ef096b..76101170 100644 --- a/utils/__tests__/assetChecks.spec.ts +++ b/utils/__tests__/assetChecks.spec.ts @@ -1,10 +1,6 @@ +import { LSP4_TOKEN_TYPES } from '@lukso/lsp-smart-contracts' import { describe, expect, test } from 'vitest' -import { LSP4_TOKEN_TYPES } from '@lukso/lsp-smart-contracts' -import type { - SelectProfileOption, - SelectStringOption, -} from '@lukso/web-components' import { getBalance, hasBalance, diff --git a/utils/__tests__/assetTypes.spec.ts b/utils/__tests__/assetTypes.spec.ts index 3671cdb8..5f1c090b 100644 --- a/utils/__tests__/assetTypes.spec.ts +++ b/utils/__tests__/assetTypes.spec.ts @@ -1,4 +1,5 @@ import { expect, test } from 'vitest' + import { getAssetType } from '../assetTypes' test('getAssetType', () => { diff --git a/utils/__tests__/cloneObject.spec.ts b/utils/__tests__/cloneObject.spec.ts index d47d5fa2..482bbbd6 100644 --- a/utils/__tests__/cloneObject.spec.ts +++ b/utils/__tests__/cloneObject.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { cloneObject } from '../cloneObject' describe('cloneObject', () => { diff --git a/utils/__tests__/decodeParameter.spec.ts b/utils/__tests__/decodeParameter.spec.ts index b5468643..33b15c16 100644 --- a/utils/__tests__/decodeParameter.spec.ts +++ b/utils/__tests__/decodeParameter.spec.ts @@ -1,5 +1,6 @@ import { describe, expect, test, vi } from 'vitest' import ABICoder from 'web3-eth-abi' + import { decodeParameter } from '../decodeParameter' describe('decodeParameter function', () => { diff --git a/utils/__tests__/deepEqual.spec.ts b/utils/__tests__/deepEqual.spec.ts index f401e632..01cce619 100644 --- a/utils/__tests__/deepEqual.spec.ts +++ b/utils/__tests__/deepEqual.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { deepEqual } from '../deepEqual' describe('deepEqual', () => { diff --git a/utils/__tests__/externalUrls.spec.ts b/utils/__tests__/externalUrls.spec.ts index 9f0babf4..0ffc795b 100644 --- a/utils/__tests__/externalUrls.spec.ts +++ b/utils/__tests__/externalUrls.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, test } from 'vitest' + import { universalPageProfileUrl, universalSwapsProfileUrl, diff --git a/utils/__tests__/groupAttributes.spec.ts b/utils/__tests__/groupAttributes.spec.ts index 4c671e90..2f9bd8a6 100644 --- a/utils/__tests__/groupAttributes.spec.ts +++ b/utils/__tests__/groupAttributes.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { groupAttributes } from '../groupAttributes' describe('groupAttributes', () => { diff --git a/utils/__tests__/hexToNumber.spec.ts b/utils/__tests__/hexToNumber.spec.ts index 54e7ed01..2a1c8d1d 100644 --- a/utils/__tests__/hexToNumber.spec.ts +++ b/utils/__tests__/hexToNumber.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, test, vi } from 'vitest' + import { hexToNumber } from '../hexToNumber' describe('hexToNumber function', () => { diff --git a/utils/__tests__/hexToUtf8.spec.ts b/utils/__tests__/hexToUtf8.spec.ts index 5938ac4b..8448a766 100644 --- a/utils/__tests__/hexToUtf8.spec.ts +++ b/utils/__tests__/hexToUtf8.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, test, vi } from 'vitest' + import { hexToUtf8 } from '../hexToUtf8' describe('hexToUtf8 function', () => { diff --git a/utils/__tests__/isValidURL.spec.ts b/utils/__tests__/isValidURL.spec.ts index 78990844..9e5b87f4 100644 --- a/utils/__tests__/isValidURL.spec.ts +++ b/utils/__tests__/isValidURL.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { isValidURL } from '../isValidURL' describe('isValidURL', () => { diff --git a/utils/__tests__/paddedToAddress.spec.ts b/utils/__tests__/paddedToAddress.spec.ts index e311785f..bdc8bd1b 100644 --- a/utils/__tests__/paddedToAddress.spec.ts +++ b/utils/__tests__/paddedToAddress.spec.ts @@ -1,4 +1,5 @@ import { expect, test } from 'vitest' + import { paddedToAddress } from '../paddedToAddress' test('paddedToAddress should remove zero padding from an address', async () => { diff --git a/utils/__tests__/queryParamsString.spec.ts b/utils/__tests__/queryParamsString.spec.ts index 0b9c5950..8e66843c 100644 --- a/utils/__tests__/queryParamsString.spec.ts +++ b/utils/__tests__/queryParamsString.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { queryParamsString } from '../queryParamsString' describe('queryParamsString', () => { diff --git a/utils/__tests__/slug.spec.ts b/utils/__tests__/slug.spec.ts index c5b8a754..4d2a9eea 100644 --- a/utils/__tests__/slug.spec.ts +++ b/utils/__tests__/slug.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { slug } from '../slug' describe('slug', () => { diff --git a/utils/__tests__/sort.spec.ts b/utils/__tests__/sort.spec.ts index 68466424..b5ae0988 100644 --- a/utils/__tests__/sort.spec.ts +++ b/utils/__tests__/sort.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { stringSort } from '../sort' describe('stringSort', () => { diff --git a/utils/__tests__/tokenConversionWithDecimals.spec.ts b/utils/__tests__/tokenConversionWithDecimals.spec.ts index 4fcbb4ab..3a20b1e1 100644 --- a/utils/__tests__/tokenConversionWithDecimals.spec.ts +++ b/utils/__tests__/tokenConversionWithDecimals.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { fromTokenUnitWithDecimals, toTokenUnitWithDecimals, diff --git a/utils/__tests__/truncate.spec.ts b/utils/__tests__/truncate.spec.ts index 6b05e73e..86609132 100644 --- a/utils/__tests__/truncate.spec.ts +++ b/utils/__tests__/truncate.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest' + import { truncate } from '../truncate' describe('truncate', () => { diff --git a/utils/__tests__/unflatArray.spec.ts b/utils/__tests__/unflatArray.spec.ts index 324f69b6..40a6666a 100644 --- a/utils/__tests__/unflatArray.spec.ts +++ b/utils/__tests__/unflatArray.spec.ts @@ -1,4 +1,5 @@ -import { describe, expect, test } from 'vitest' +import { expect, test } from 'vitest' + import { unflatArray } from '../unflatArray' test('handles consecutive indexes', () => { diff --git a/utils/__tests__/validateLspMetadata.spec.ts b/utils/__tests__/validateLspMetadata.spec.ts index 0d3e4392..8dae3455 100644 --- a/utils/__tests__/validateLspMetadata.spec.ts +++ b/utils/__tests__/validateLspMetadata.spec.ts @@ -1,9 +1,9 @@ import { describe, expect, test } from 'vitest' + import { validateAssets, validateAttributes, validateDescription, - validateImage, validateImages, validateLinks, validateName, diff --git a/utils/__tests__/validators.spec.ts b/utils/__tests__/validators.spec.ts index 55d3b8a0..40bbc45b 100644 --- a/utils/__tests__/validators.spec.ts +++ b/utils/__tests__/validators.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, test } from 'vitest' + import { assertAddress, assertAddresses,