Skip to content

Commit

Permalink
move from environment variable to argument
Browse files Browse the repository at this point in the history
  • Loading branch information
nedsalk committed Jun 23, 2024
1 parent 9d281fd commit c6005be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface LaunchCustomProviderAndGetWalletsOptions {
snapshotConfig: PartialDeep<SnapshotConfigs>;
}
>;
launchNodeServerPort?: string;
}

const defaultWalletConfigOptions: WalletsConfigOptions = {
Expand Down Expand Up @@ -52,6 +53,7 @@ export async function setupTestProviderAndWallets({
walletsConfig: walletsConfigOptions = {},
providerOptions,
nodeOptions = {},
launchNodeServerPort = process.env.LAUNCH_NODE_SERVER_PORT || undefined,
}: Partial<LaunchCustomProviderAndGetWalletsOptions> = {}): Promise<SetupTestProviderAndWalletsReturn> {
// @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');
Expand All @@ -64,7 +66,7 @@ export async function setupTestProviderAndWallets({
}
);

const launchNodeOptions = {
const launchNodeOptions: LaunchNodeOptions = {
loggingEnabled: false,
...nodeOptions,
snapshotConfig: mergeDeepRight(
Expand All @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions packages/fuels/src/setup-launch-node-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
Expand Down Expand Up @@ -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 }
);

0 comments on commit c6005be

Please sign in to comment.