From 9a5aef8775864f8e5dbc4421fbb01dec49e27998 Mon Sep 17 00:00:00 2001 From: Jost Schulte Date: Mon, 30 May 2022 19:19:19 -0600 Subject: [PATCH] feat(scenario): add options to runScenario fn --- docs/tryorama.md | 1 + docs/tryorama.runscenario.md | 2 +- docs/tryorama.scenario._constructor_.md | 6 ++---- docs/tryorama.scenariooptions.md | 20 ++++++++++++++++++++ docs/tryorama.scenariooptions.timeout.md | 11 +++++++++++ package.json | 2 +- ts/src/local/scenario.ts | 17 ++++++++++++++--- 7 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 docs/tryorama.scenariooptions.md create mode 100644 docs/tryorama.scenariooptions.timeout.md diff --git a/docs/tryorama.md b/docs/tryorama.md index 0df8ca22..c6a18dde 100644 --- a/docs/tryorama.md +++ b/docs/tryorama.md @@ -76,6 +76,7 @@ TryCP stands for Tryorama Control Protocol (TryCP) and is a protocol to enable r | [RequestSaveDna](./tryorama.requestsavedna.md) | Request to save a DNA to the server's file system. | | [RequestShutdown](./tryorama.requestshutdown.md) | Request shutdown of a conductor. | | [RequestStartup](./tryorama.requeststartup.md) | Request startup of a conductor. | +| [ScenarioOptions](./tryorama.scenariooptions.md) | Options when creating a scenario. | | [TryCpConductorOptions](./tryorama.trycpconductoroptions.md) | | | [TryCpPlayer](./tryorama.trycpplayer.md) | A player tied to a [TryCpConductor](./tryorama.trycpconductor.md). | diff --git a/docs/tryorama.runscenario.md b/docs/tryorama.runscenario.md index 420056cd..7e6385fd 100644 --- a/docs/tryorama.runscenario.md +++ b/docs/tryorama.runscenario.md @@ -9,5 +9,5 @@ A wrapper function to create and run a scenario. A scenario is created and all i Signature: ```typescript -runScenario: (testScenario: (scenario: Scenario) => Promise, cleanUp?: boolean) => Promise +runScenario: (testScenario: (scenario: Scenario) => Promise, cleanUp?: boolean, options?: ScenarioOptions) => Promise ``` diff --git a/docs/tryorama.scenario._constructor_.md b/docs/tryorama.scenario._constructor_.md index a1e6cbc2..0e53081b 100644 --- a/docs/tryorama.scenario._constructor_.md +++ b/docs/tryorama.scenario._constructor_.md @@ -9,14 +9,12 @@ Scenario constructor. Signature: ```typescript -constructor(options?: { - timeout?: number; - }); +constructor(options?: ScenarioOptions); ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| options | { timeout?: number; } | (Optional) Timeout for requests to Admin and App API calls. | +| options | [ScenarioOptions](./tryorama.scenariooptions.md) | (Optional) Timeout for requests to Admin and App API calls. | diff --git a/docs/tryorama.scenariooptions.md b/docs/tryorama.scenariooptions.md new file mode 100644 index 00000000..cf90ccef --- /dev/null +++ b/docs/tryorama.scenariooptions.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [@holochain/tryorama](./tryorama.md) > [ScenarioOptions](./tryorama.scenariooptions.md) + +## ScenarioOptions interface + +Options when creating a scenario. + +Signature: + +```typescript +export interface ScenarioOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [timeout?](./tryorama.scenariooptions.timeout.md) | number | (Optional) | + diff --git a/docs/tryorama.scenariooptions.timeout.md b/docs/tryorama.scenariooptions.timeout.md new file mode 100644 index 00000000..4d554c2c --- /dev/null +++ b/docs/tryorama.scenariooptions.timeout.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@holochain/tryorama](./tryorama.md) > [ScenarioOptions](./tryorama.scenariooptions.md) > [timeout](./tryorama.scenariooptions.timeout.md) + +## ScenarioOptions.timeout property + +Signature: + +```typescript +timeout?: number; +``` diff --git a/package.json b/package.json index a61ad7c5..018efde5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@holochain/tryorama", "description": "Toolset to manage Holochain conductors and facilitate running test scenarios", - "version": "0.5.1", + "version": "0.5.2", "author": "Holochain Foundation", "keywords": [ "holochain", diff --git a/ts/src/local/scenario.ts b/ts/src/local/scenario.ts index f400c51e..a5b30a92 100644 --- a/ts/src/local/scenario.ts +++ b/ts/src/local/scenario.ts @@ -18,6 +18,16 @@ export interface Player extends IPlayer { conductor: Conductor; } +/** + * Options when creating a scenario. + * + * @public + */ +export interface ScenarioOptions { + // Timeout for requests to Admin and App API calls. + timeout?: number; +} + /** * An abstraction of a test scenario to write tests against Holochain hApps, * running on a local conductor. @@ -34,7 +44,7 @@ export class Scenario implements IScenario { * * @param options - Timeout for requests to Admin and App API calls. */ - constructor(options?: { timeout?: number }) { + constructor(options?: ScenarioOptions) { this.timeout = options?.timeout; this.uid = uuidv4(); this.conductors = []; @@ -180,9 +190,10 @@ export class Scenario implements IScenario { */ export const runScenario = async ( testScenario: (scenario: Scenario) => Promise, - cleanUp = true + cleanUp = true, + options?: ScenarioOptions ) => { - const scenario = new Scenario(); + const scenario = new Scenario(options); try { await testScenario(scenario); } finally {