diff --git a/packages/dockest/src/@types.ts b/packages/dockest/src/@types.ts index eb75051e..3334ae33 100644 --- a/packages/dockest/src/@types.ts +++ b/packages/dockest/src/@types.ts @@ -63,7 +63,7 @@ export interface DockerComposeFileServicePostgres extends DockerComposeFileServi } } -export type Commands = string[] +export type Commands = (string | ((containerId: string) => string))[] export interface DockestService { serviceName: ServiceName diff --git a/packages/dockest/src/run/waitForServices/runRunnerCommands.ts b/packages/dockest/src/run/waitForServices/runRunnerCommands.ts index b22045e5..ad1bb350 100644 --- a/packages/dockest/src/run/waitForServices/runRunnerCommands.ts +++ b/packages/dockest/src/run/waitForServices/runRunnerCommands.ts @@ -4,7 +4,10 @@ import { Runner } from '../../@types' const logPrefix = '[Dockest Service Commands]' export const runRunnerCommands = async ({ runner, runner: { commands } }: { runner: Runner }) => { - for (const command of commands) { + for (let command of commands) { + if (typeof command === 'function') { + command = command(runner.containerId) + } await execaWrapper(command, { runner, logPrefix, logStdout: true }) } } diff --git a/packages/examples/multiple-resources/dockest.ts b/packages/examples/multiple-resources/dockest.ts index 14b88114..365c7b41 100644 --- a/packages/examples/multiple-resources/dockest.ts +++ b/packages/examples/multiple-resources/dockest.ts @@ -18,6 +18,7 @@ dockest.run([ 'sequelize db:migrate', 'sequelize db:seed:undo:all', 'sequelize db:seed --seed 20190101001337-demo-user', + containerId => `echo "The container id is ${containerId}"`, ], healthcheck: ({ defaultHealthchecks: { postgres } }) => postgres(), },