diff --git a/package.json b/package.json index fac3b10..e676427 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,8 @@ "test": "pezkuwi-dev-run-test --experimental-test-module-mocks --env browser ^typesBundle ^chainEndpoints ^chainTypes ^:.slow.", "test:all": "pezkuwi-dev-run-test --experimental-test-module-mocks --env browser ^chainEndpoints ^chainTypes", "test:one": "pezkuwi-dev-run-test --experimental-test-module-mocks --env browser", - "test:skipped": "echo 'tests skipped'" + "test:skipped": "echo 'tests skipped'", + "test:slow": "pezkuwi-dev-run-test --experimental-test-module-mocks --env browser :.slow." }, "devDependencies": { "@pezkuwi/dev": "^0.86.8", diff --git a/packages/page-accounts/src/CreateAccount.slow.spec.tsx b/packages/page-accounts/src/CreateAccount.slow.spec.tsx index 52135eb..bc6690e 100644 --- a/packages/page-accounts/src/CreateAccount.slow.spec.tsx +++ b/packages/page-accounts/src/CreateAccount.slow.spec.tsx @@ -5,7 +5,7 @@ import '@pezkuwi/react-components/i18n'; -import { cleanup, fireEvent, render, waitForElementToBeRemoved } from '@testing-library/react'; +import { cleanup, configure, fireEvent, getConfig, render, waitForElementToBeRemoved } from '@testing-library/react'; import React from 'react'; import { MemoryRouter } from 'react-router-dom'; import { ThemeProvider } from 'styled-components'; @@ -15,7 +15,7 @@ import { ApiCtxRoot } from '@pezkuwi/react-api'; import { statics } from '@pezkuwi/react-api/statics'; import { lightTheme } from '@pezkuwi/react-components'; import { KeyringCtxRoot } from '@pezkuwi/react-hooks/ctx/Keyring'; -import { BIZINIKIWI_PORT } from '@pezkuwi/test-support/bizinikiwi'; +import { assertDevNode, BIZINIKIWI_PORT } from '@pezkuwi/test-support/bizinikiwi'; import { MemoryStore } from '@pezkuwi/test-support/keyring'; import { WaitForApi } from '@pezkuwi/test-support/react'; import { settings } from '@pezkuwi/ui-settings'; @@ -53,19 +53,31 @@ const renderAccounts = () => { ); }; -// eslint-disable-next-line jest/no-disabled-tests -describe.skip('--SLOW--: Account Create', () => { +describe('--SLOW--: Account Create', () => { + // every step waits on a live chain and a page that draws once the api and + // keyring are ready, which takes longer than the 1s default on a busy machine + let asyncUtilTimeout: number; + + beforeAll(async () => { + await assertDevNode(); + asyncUtilTimeout = getConfig().asyncUtilTimeout; + configure({ asyncUtilTimeout: 20_000 }); + }); + // each render opens its own connection, and an open one keeps the process alive afterEach(async () => { cleanup(); await statics.api.disconnect(); }); + afterAll(() => { + configure({ asyncUtilTimeout }); + }); + it('created account is added to list', async () => { const { findByRole, findByTestId, findByText, queryByText } = renderAccounts(); - // the page draws once the api and keyring are ready, later than the 1s default on a busy machine - fireEvent.click(await findByRole('button', { name: 'Account' }, { timeout: 20_000 })); + fireEvent.click(await findByRole('button', { name: 'Account' })); const isSeedSavedCheckbox = await findByText('I have saved my mnemonic seed safely'); const hiddenCheckbox = isSeedSavedCheckbox as HTMLInputElement; @@ -104,7 +116,7 @@ describe.skip('--SLOW--: Account Create', () => { it('gives an error message when entering invalid derivation path', async () => { const { findByRole, findByTestId, findByText } = renderAccounts(); - fireEvent.click(await findByRole('button', { name: 'Account' }, { timeout: 20_000 })); + fireEvent.click(await findByRole('button', { name: 'Account' })); const showAdvancedOptionsButton = await findByText('Advanced creation options', {}); diff --git a/packages/page-bounties/src/Bounties.slow.spec.tsx b/packages/page-bounties/src/Bounties.slow.spec.tsx index bc2ab60..08557a4 100644 --- a/packages/page-bounties/src/Bounties.slow.spec.tsx +++ b/packages/page-bounties/src/Bounties.slow.spec.tsx @@ -7,7 +7,7 @@ import '@pezkuwi/react-components/i18n'; import type { ApiPromise } from '@pezkuwi/api'; -import { cleanup, render } from '@testing-library/react'; +import { cleanup, configure, getConfig, render } from '@testing-library/react'; import React, { Suspense } from 'react'; import { MemoryRouter } from 'react-router-dom'; import { ThemeProvider } from 'styled-components'; @@ -16,6 +16,7 @@ import { ApiCtxRoot } from '@pezkuwi/react-api'; import { statics } from '@pezkuwi/react-api/statics'; import { lightTheme } from '@pezkuwi/react-components'; import { createApi } from '@pezkuwi/test-support/api'; +import { assertDevNode, BIZINIKIWI_PORT } from '@pezkuwi/test-support/bizinikiwi'; import { aliceSigner, MemoryStore } from '@pezkuwi/test-support/keyring'; import { WaitForApi } from '@pezkuwi/test-support/react'; import { execute } from '@pezkuwi/test-support/transaction'; @@ -23,8 +24,6 @@ import { BN } from '@pezkuwi/util'; import BountiesApp from './index.js'; -const BIZINIKIWI_PORT = Number.parseInt(process.env.TEST_BIZINIKIWI_PORT || '30333'); - const renderBounties = () => { const memoryStore = new MemoryStore(); @@ -48,12 +47,22 @@ const renderBounties = () => { ); }; -// eslint-disable-next-line jest/no-disabled-tests -describe.skip('--SLOW--: Bounties', () => { +describe('--SLOW--: Bounties', () => { + // every step waits on a live chain and a page that draws once the api and + // keyring are ready, which takes longer than the 1s default on a busy machine + let asyncUtilTimeout: number; + + beforeAll(async () => { + await assertDevNode(); + asyncUtilTimeout = getConfig().asyncUtilTimeout; + configure({ asyncUtilTimeout: 20_000 }); + }); + let api: ApiPromise | undefined; // both connections stay open otherwise, and keep the process alive afterAll(async () => { + configure({ asyncUtilTimeout }); cleanup(); await api?.disconnect(); await statics.api.disconnect(); @@ -69,6 +78,6 @@ describe.skip('--SLOW--: Bounties', () => { const { findByText } = renderBounties(); - expect(await findByText(title, {}, { timeout: 20_000 })).toBeTruthy(); + expect(await findByText(title)).toBeTruthy(); }); }); diff --git a/packages/test-support/src/bizinikiwi/assertDevNode.ts b/packages/test-support/src/bizinikiwi/assertDevNode.ts new file mode 100644 index 0000000..0fb72c4 --- /dev/null +++ b/packages/test-support/src/bizinikiwi/assertDevNode.ts @@ -0,0 +1,26 @@ +// Copyright 2017-2026 @pezkuwi/test-support authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { BIZINIKIWI_PORT } from './constants.js'; + +/** + * Fails at once when no dev node answers on BIZINIKIWI_PORT. Without it an + * api keeps reconnecting and a spec waits until the job's timeout. + */ +export async function assertDevNode (timeoutMs = 5_000): Promise { + const url = `http://127.0.0.1:${BIZINIKIWI_PORT}`; + const res = await fetch(url, { + body: JSON.stringify({ id: 1, jsonrpc: '2.0', method: 'system_chain' }), + headers: { 'Content-Type': 'application/json' }, + method: 'POST', + signal: AbortSignal.timeout(timeoutMs) + }).catch((error: Error) => error); + + if (res instanceof Error || !res.ok) { + const reason = res instanceof Error + ? res.message + : `HTTP ${res.status}`; + + throw new Error(`No dev node answers on ${url} (${reason}); the .slow. specs need one`); + } +} diff --git a/packages/test-support/src/bizinikiwi/index.ts b/packages/test-support/src/bizinikiwi/index.ts index 20ce05d..e32fd4a 100644 --- a/packages/test-support/src/bizinikiwi/index.ts +++ b/packages/test-support/src/bizinikiwi/index.ts @@ -1,4 +1,5 @@ // Copyright 2017-2026 @pezkuwi/test-support authors & contributors // SPDX-License-Identifier: Apache-2.0 +export * from './assertDevNode.js'; export * from './constants.js';