diff --git a/packages/account/src/test-utils/setup-test-provider-and-wallets.ts b/packages/account/src/test-utils/setup-test-provider-and-wallets.ts index 6ff99aca921..e96963923ab 100644 --- a/packages/account/src/test-utils/setup-test-provider-and-wallets.ts +++ b/packages/account/src/test-utils/setup-test-provider-and-wallets.ts @@ -23,6 +23,7 @@ export interface LaunchCustomProviderAndGetWalletsOptions { snapshotConfig: PartialDeep; } >; + launchNodeServerPort?: string; } const defaultWalletConfigOptions: WalletsConfigOptions = { @@ -52,6 +53,7 @@ export async function setupTestProviderAndWallets({ walletsConfig: walletsConfigOptions = {}, providerOptions, nodeOptions = {}, + launchNodeServerPort = process.env.LAUNCH_NODE_SERVER_PORT || undefined, }: Partial = {}): Promise { // @ts-expect-error this is a polyfill (see https://devblogs.microsoft.com/typescript/announcing-typescript-5-2/#using-declarations-and-explicit-resource-management) Symbol.dispose ??= Symbol('Symbol.dispose'); @@ -64,7 +66,7 @@ export async function setupTestProviderAndWallets({ } ); - const launchNodeOptions = { + const launchNodeOptions: LaunchNodeOptions = { loggingEnabled: false, ...nodeOptions, snapshotConfig: mergeDeepRight( @@ -76,8 +78,8 @@ export async function setupTestProviderAndWallets({ let cleanup: () => void; let url: string; - if (process.env.LAUNCH_NODE_SERVER_PORT) { - const serverUrl = `http://localhost:${process.env.LAUNCH_NODE_SERVER_PORT}`; + if (launchNodeServerPort) { + const serverUrl = `http://localhost:${launchNodeServerPort}`; url = await ( await fetch(serverUrl, { method: 'POST', body: JSON.stringify(launchNodeOptions) }) ).text(); diff --git a/packages/fuels/src/setup-launch-node-server.test.ts b/packages/fuels/src/setup-launch-node-server.test.ts index 090b82b1df9..92479b00e54 100644 --- a/packages/fuels/src/setup-launch-node-server.test.ts +++ b/packages/fuels/src/setup-launch-node-server.test.ts @@ -2,6 +2,8 @@ import { Provider } from '@fuel-ts/account'; import { waitUntilUnreachable } from '@fuel-ts/utils/test-utils'; import { spawn } from 'node:child_process'; +import { launchTestNode } from './test-utils'; + interface ServerInfo extends Disposable { serverUrl: string; closeServer: () => Promise; @@ -112,6 +114,18 @@ describe( await waitUntilUnreachable(url1); await waitUntilUnreachable(url2); }); + + test('launchTestNode launches and kills node ', async () => { + using launchedServer = await startServer(); + const port = launchedServer.serverUrl.split(':')[2]; + const { cleanup, provider } = await launchTestNode({ + launchNodeServerPort: port, + }); + + cleanup(); + + await waitUntilUnreachable(provider.url); + }); }, { timeout: 25000 } );