diff --git a/tools/ci-ts/jest.config.js b/tools/ci-ts/jest.config.js index 661a409063b..8cab8469333 100644 --- a/tools/ci-ts/jest.config.js +++ b/tools/ci-ts/jest.config.js @@ -1,5 +1,6 @@ module.exports = { preset: 'ts-jest', + setupFilesAfterEnv: ['/jest.setup.ts'], testEnvironment: 'node', testPathIgnorePatterns: ['/node_modules/', 'dist/'], testRunner: 'jest-circus/runner', diff --git a/tools/ci-ts/jest.setup.ts b/tools/ci-ts/jest.setup.ts new file mode 100644 index 00000000000..ad5e3cd81cc --- /dev/null +++ b/tools/ci-ts/jest.setup.ts @@ -0,0 +1,7 @@ +import { getArgs, waitForService } from './test-helpers/common' + +const { CHAINLINK_URL } = getArgs(['CHAINLINK_URL']) + +beforeAll(async () => { + await waitForService(CHAINLINK_URL) +}) diff --git a/tools/ci-ts/test-helpers/common.ts b/tools/ci-ts/test-helpers/common.ts index 402389e8595..03f499da8d6 100644 --- a/tools/ci-ts/test-helpers/common.ts +++ b/tools/ci-ts/test-helpers/common.ts @@ -107,13 +107,18 @@ export async function wait(ms: number) { }) } +/** + * Makes a simple get request to an endpoint and ensures the service responds. + * Status code doesn't matter - just ensures the service is running. + * @param endpoint the url of the service + * @param timeout the time to wait before erroring + */ export async function waitForService(endpoint: string, timeout = 20000) { await assertAsync( - async () => { - return fetch(endpoint) + async () => + fetch(endpoint) .then(() => true) - .catch(() => false) - }, + .catch(() => false), `${endpoint} is unreachable after ${timeout}ms`, timeout, ) diff --git a/tools/ci-ts/tests/flux-monitor.test.ts b/tools/ci-ts/tests/flux-monitor.test.ts index 6461f1fd848..0e82a805822 100644 --- a/tools/ci-ts/tests/flux-monitor.test.ts +++ b/tools/ci-ts/tests/flux-monitor.test.ts @@ -6,7 +6,6 @@ import { wait, createProvider, fundAddress, - waitForService, } from '../test-helpers/common' import * as clClient from '../test-helpers/chainlink-cli' import { contract, helpers as h, matchers } from '@chainlink/test-helpers' @@ -15,10 +14,7 @@ import { JobSpec } from '../../../operator_ui/@types/operator_ui' import 'isomorphic-unfetch' import { ethers } from 'ethers' -const { EXTERNAL_ADAPTER_URL, CHAINLINK_URL } = getArgs([ - 'EXTERNAL_ADAPTER_URL', - 'CHAINLINK_URL', -]) +const { EXTERNAL_ADAPTER_URL } = getArgs(['EXTERNAL_ADAPTER_URL']) const provider = createProvider() const carol = ethers.Wallet.createRandom().connect(provider) @@ -61,7 +57,6 @@ describe('flux monitor eth client integration', () => { let node1Address: string beforeAll(async () => { - await waitForService(CHAINLINK_URL) clClient.login() node1Address = clClient.getAdminInfo()[0].address await fundAddress(carol.address)