From 468b7ccca2823e4e710bc45bf73436c28c95bf1a Mon Sep 17 00:00:00 2001 From: Lucas <31957045+SketchingDev@users.noreply.github.com> Date: Fri, 4 Aug 2023 12:33:37 +0100 Subject: [PATCH] Add timeout option (#96) --- README.md | 2 + docs/api/README.md | 2 +- .../{Transcriber.md => SessionTranscriber.md} | 207 ++++++++++++------ examples/cli/run.sh | 3 + .../README.md | 2 + .../package.json | 4 +- .../src/cli.ts | 8 +- .../src/testScript/parseTestScript.ts | 13 +- 8 files changed, 169 insertions(+), 72 deletions(-) rename docs/api/classes/{Transcriber.md => SessionTranscriber.md} (63%) diff --git a/README.md b/README.md index 7d2be10..5fa2060 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,8 @@ Options: GENESYSCLOUD_OAUTHCLIENT_ID GENESYSCLOUD_OAUTHCLIENT_SECRET (default: false) -fo, --failures-only Only output failures (default: false) + -t, --timeout Seconds to wait for a response before + failing the test (default: 10) -h, --help display help for command ``` diff --git a/docs/api/README.md b/docs/api/README.md index d99cb3e..b349d5c 100644 --- a/docs/api/README.md +++ b/docs/api/README.md @@ -8,8 +8,8 @@ Genesys Web Messaging Tester - [BotDisconnectedWaitingForResponseError](classes/BotDisconnectedWaitingForResponseError.md) - [Conversation](classes/Conversation.md) +- [SessionTranscriber](classes/SessionTranscriber.md) - [TimeoutWaitingForResponseError](classes/TimeoutWaitingForResponseError.md) -- [Transcriber](classes/Transcriber.md) - [WebMessengerGuestSession](classes/WebMessengerGuestSession.md) ### Interfaces diff --git a/docs/api/classes/Transcriber.md b/docs/api/classes/SessionTranscriber.md similarity index 63% rename from docs/api/classes/Transcriber.md rename to docs/api/classes/SessionTranscriber.md index a56ebc7..e53eb8c 100644 --- a/docs/api/classes/Transcriber.md +++ b/docs/api/classes/SessionTranscriber.md @@ -1,6 +1,6 @@ -[Genesys Web Messaging Tester](../README.md) / Transcriber +[Genesys Web Messaging Tester](../README.md) / SessionTranscriber -# Class: Transcriber +# Class: SessionTranscriber Transcribes a Web Messenger session into an array of transcribed messages. @@ -8,48 +8,48 @@ Transcribes a Web Messenger session into an array of transcribed messages. - `EventEmitter` - ↳ **`Transcriber`** + ↳ **`SessionTranscriber`** ## Table of contents ### Constructors -- [constructor](Transcriber.md#constructor) +- [constructor](SessionTranscriber.md#constructor) ### Properties -- [captureRejectionSymbol](Transcriber.md#capturerejectionsymbol) -- [captureRejections](Transcriber.md#capturerejections) -- [defaultMaxListeners](Transcriber.md#defaultmaxlisteners) -- [errorMonitor](Transcriber.md#errormonitor) +- [captureRejectionSymbol](SessionTranscriber.md#capturerejectionsymbol) +- [captureRejections](SessionTranscriber.md#capturerejections) +- [defaultMaxListeners](SessionTranscriber.md#defaultmaxlisteners) +- [errorMonitor](SessionTranscriber.md#errormonitor) ### Methods -- [addListener](Transcriber.md#addlistener) -- [emit](Transcriber.md#emit) -- [eventNames](Transcriber.md#eventnames) -- [getMaxListeners](Transcriber.md#getmaxlisteners) -- [getTranscript](Transcriber.md#gettranscript) -- [listenerCount](Transcriber.md#listenercount) -- [listeners](Transcriber.md#listeners) -- [off](Transcriber.md#off) -- [on](Transcriber.md#on) -- [once](Transcriber.md#once) -- [prependListener](Transcriber.md#prependlistener) -- [prependOnceListener](Transcriber.md#prependoncelistener) -- [rawListeners](Transcriber.md#rawlisteners) -- [removeAllListeners](Transcriber.md#removealllisteners) -- [removeListener](Transcriber.md#removelistener) -- [setMaxListeners](Transcriber.md#setmaxlisteners) -- [listenerCount](Transcriber.md#listenercount-1) -- [on](Transcriber.md#on-1) -- [once](Transcriber.md#once-1) +- [addListener](SessionTranscriber.md#addlistener) +- [emit](SessionTranscriber.md#emit) +- [eventNames](SessionTranscriber.md#eventnames) +- [getMaxListeners](SessionTranscriber.md#getmaxlisteners) +- [getTranscript](SessionTranscriber.md#gettranscript) +- [listenerCount](SessionTranscriber.md#listenercount) +- [listeners](SessionTranscriber.md#listeners) +- [off](SessionTranscriber.md#off) +- [on](SessionTranscriber.md#on) +- [once](SessionTranscriber.md#once) +- [prependListener](SessionTranscriber.md#prependlistener) +- [prependOnceListener](SessionTranscriber.md#prependoncelistener) +- [rawListeners](SessionTranscriber.md#rawlisteners) +- [removeAllListeners](SessionTranscriber.md#removealllisteners) +- [removeListener](SessionTranscriber.md#removelistener) +- [setMaxListeners](SessionTranscriber.md#setmaxlisteners) +- [listenerCount](SessionTranscriber.md#listenercount-1) +- [on](SessionTranscriber.md#on-1) +- [once](SessionTranscriber.md#once-1) ## Constructors ### constructor -• **new Transcriber**(`messengerSession`, `«destructured»?`) +• **new SessionTranscriber**(`messengerSession`, `«destructured»?`) #### Parameters @@ -60,6 +60,10 @@ Transcribes a Web Messenger session into an array of transcribed messages. | › `nameForClient?` | `string` | | › `nameForServer?` | `string` | +#### Overrides + +EventEmitter.constructor + #### Defined in [packages/genesys-web-messaging-tester/src/transcribe/Transcriber.ts:27](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/transcribe/Transcriber.ts#L27) @@ -70,6 +74,10 @@ Transcribes a Web Messenger session into an array of transcribed messages. ▪ `Static` `Readonly` **captureRejectionSymbol**: typeof [`captureRejectionSymbol`](WebMessengerGuestSession.md#capturerejectionsymbol) +#### Inherited from + +EventEmitter.captureRejectionSymbol + #### Defined in node_modules/@types/node/events.d.ts:38 @@ -82,6 +90,10 @@ ___ Sets or gets the default captureRejection value for all emitters. +#### Inherited from + +EventEmitter.captureRejections + #### Defined in node_modules/@types/node/events.d.ts:44 @@ -92,6 +104,10 @@ ___ ▪ `Static` **defaultMaxListeners**: `number` +#### Inherited from + +EventEmitter.defaultMaxListeners + #### Defined in node_modules/@types/node/events.d.ts:45 @@ -110,6 +126,10 @@ Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted, therefore the process will still crash if no regular `'error'` listener is installed. +#### Inherited from + +EventEmitter.errorMonitor + #### Defined in node_modules/@types/node/events.d.ts:37 @@ -118,7 +138,7 @@ node_modules/@types/node/events.d.ts:37 ### addListener -▸ **addListener**(`event`, `listener`): [`Transcriber`](Transcriber.md) +▸ **addListener**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) #### Parameters @@ -129,7 +149,11 @@ node_modules/@types/node/events.d.ts:37 #### Returns -[`Transcriber`](Transcriber.md) +[`SessionTranscriber`](SessionTranscriber.md) + +#### Inherited from + +EventEmitter.addListener #### Defined in @@ -152,6 +176,10 @@ ___ `boolean` +#### Inherited from + +EventEmitter.emit + #### Defined in node_modules/@types/node/events.d.ts:67 @@ -166,6 +194,10 @@ ___ (`string` \| `symbol`)[] +#### Inherited from + +EventEmitter.eventNames + #### Defined in node_modules/@types/node/events.d.ts:72 @@ -180,6 +212,10 @@ ___ `number` +#### Inherited from + +EventEmitter.getMaxListeners + #### Defined in node_modules/@types/node/events.d.ts:64 @@ -214,6 +250,10 @@ ___ `number` +#### Inherited from + +EventEmitter.listenerCount + #### Defined in node_modules/@types/node/events.d.ts:68 @@ -234,6 +274,10 @@ ___ `Function`[] +#### Inherited from + +EventEmitter.listeners + #### Defined in node_modules/@types/node/events.d.ts:65 @@ -242,7 +286,7 @@ ___ ### off -▸ **off**(`event`, `listener`): [`Transcriber`](Transcriber.md) +▸ **off**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) #### Parameters @@ -253,7 +297,11 @@ ___ #### Returns -[`Transcriber`](Transcriber.md) +[`SessionTranscriber`](SessionTranscriber.md) + +#### Inherited from + +EventEmitter.off #### Defined in @@ -263,45 +311,32 @@ ___ ### on -▸ **on**(`event`, `listener`): [`Transcriber`](Transcriber.md) +▸ **on**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) #### Parameters | Name | Type | | :------ | :------ | -| `event` | ``"messageTranscribed"`` | -| `listener` | (`event`: [`TranscribedMessage`](../interfaces/TranscribedMessage.md)) => `void` | +| `event` | `string` \| `symbol` | +| `listener` | (...`args`: `any`[]) => `void` | #### Returns -[`Transcriber`](Transcriber.md) +[`SessionTranscriber`](SessionTranscriber.md) -#### Defined in +#### Inherited from -[packages/genesys-web-messaging-tester/src/transcribe/Transcriber.ts:14](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/transcribe/Transcriber.ts#L14) - -▸ **on**(`event`, `listener`): [`Transcriber`](Transcriber.md) - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `event` | `string` | -| `listener` | (...`args`: `unknown`[]) => `void` | - -#### Returns - -[`Transcriber`](Transcriber.md) +EventEmitter.on #### Defined in -[packages/genesys-web-messaging-tester/src/transcribe/Transcriber.ts:15](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/transcribe/Transcriber.ts#L15) +node_modules/@types/node/events.d.ts:58 ___ ### once -▸ **once**(`event`, `listener`): [`Transcriber`](Transcriber.md) +▸ **once**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) #### Parameters @@ -312,7 +347,11 @@ ___ #### Returns -[`Transcriber`](Transcriber.md) +[`SessionTranscriber`](SessionTranscriber.md) + +#### Inherited from + +EventEmitter.once #### Defined in @@ -322,7 +361,7 @@ ___ ### prependListener -▸ **prependListener**(`event`, `listener`): [`Transcriber`](Transcriber.md) +▸ **prependListener**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) #### Parameters @@ -333,7 +372,11 @@ ___ #### Returns -[`Transcriber`](Transcriber.md) +[`SessionTranscriber`](SessionTranscriber.md) + +#### Inherited from + +EventEmitter.prependListener #### Defined in @@ -343,7 +386,7 @@ ___ ### prependOnceListener -▸ **prependOnceListener**(`event`, `listener`): [`Transcriber`](Transcriber.md) +▸ **prependOnceListener**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) #### Parameters @@ -354,7 +397,11 @@ ___ #### Returns -[`Transcriber`](Transcriber.md) +[`SessionTranscriber`](SessionTranscriber.md) + +#### Inherited from + +EventEmitter.prependOnceListener #### Defined in @@ -376,6 +423,10 @@ ___ `Function`[] +#### Inherited from + +EventEmitter.rawListeners + #### Defined in node_modules/@types/node/events.d.ts:66 @@ -384,7 +435,7 @@ ___ ### removeAllListeners -▸ **removeAllListeners**(`event?`): [`Transcriber`](Transcriber.md) +▸ **removeAllListeners**(`event?`): [`SessionTranscriber`](SessionTranscriber.md) #### Parameters @@ -394,7 +445,11 @@ ___ #### Returns -[`Transcriber`](Transcriber.md) +[`SessionTranscriber`](SessionTranscriber.md) + +#### Inherited from + +EventEmitter.removeAllListeners #### Defined in @@ -404,7 +459,7 @@ ___ ### removeListener -▸ **removeListener**(`event`, `listener`): [`Transcriber`](Transcriber.md) +▸ **removeListener**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) #### Parameters @@ -415,7 +470,11 @@ ___ #### Returns -[`Transcriber`](Transcriber.md) +[`SessionTranscriber`](SessionTranscriber.md) + +#### Inherited from + +EventEmitter.removeListener #### Defined in @@ -425,7 +484,7 @@ ___ ### setMaxListeners -▸ **setMaxListeners**(`n`): [`Transcriber`](Transcriber.md) +▸ **setMaxListeners**(`n`): [`SessionTranscriber`](SessionTranscriber.md) #### Parameters @@ -435,7 +494,11 @@ ___ #### Returns -[`Transcriber`](Transcriber.md) +[`SessionTranscriber`](SessionTranscriber.md) + +#### Inherited from + +EventEmitter.setMaxListeners #### Defined in @@ -462,6 +525,10 @@ since v4.0.0 `number` +#### Inherited from + +EventEmitter.listenerCount + #### Defined in node_modules/@types/node/events.d.ts:26 @@ -483,6 +550,10 @@ ___ `AsyncIterableIterator`<`any`\> +#### Inherited from + +EventEmitter.on + #### Defined in node_modules/@types/node/events.d.ts:23 @@ -504,6 +575,10 @@ ___ `Promise`<`any`[]\> +#### Inherited from + +EventEmitter.once + #### Defined in node_modules/@types/node/events.d.ts:21 @@ -521,6 +596,10 @@ node_modules/@types/node/events.d.ts:21 `Promise`<`any`[]\> +#### Inherited from + +EventEmitter.once + #### Defined in node_modules/@types/node/events.d.ts:22 diff --git a/examples/cli/run.sh b/examples/cli/run.sh index 1fa6b62..ed86331 100755 --- a/examples/cli/run.sh +++ b/examples/cli/run.sh @@ -7,6 +7,9 @@ function cleanup { } trap cleanup EXIT +## Help message for updating the docs +web-messaging-tester --help + ## Passing example exits with exit code 0 web-messaging-tester example-pass.yml -id $DEPLOYMENT_ID -r $REGION -p 10 if [ $? -ne 0 ] diff --git a/packages/genesys-web-messaging-tester-cli/README.md b/packages/genesys-web-messaging-tester-cli/README.md index 7d2be10..5fa2060 100644 --- a/packages/genesys-web-messaging-tester-cli/README.md +++ b/packages/genesys-web-messaging-tester-cli/README.md @@ -119,6 +119,8 @@ Options: GENESYSCLOUD_OAUTHCLIENT_ID GENESYSCLOUD_OAUTHCLIENT_SECRET (default: false) -fo, --failures-only Only output failures (default: false) + -t, --timeout Seconds to wait for a response before + failing the test (default: 10) -h, --help display help for command ``` diff --git a/packages/genesys-web-messaging-tester-cli/package.json b/packages/genesys-web-messaging-tester-cli/package.json index 31d98a4..4eed77d 100644 --- a/packages/genesys-web-messaging-tester-cli/package.json +++ b/packages/genesys-web-messaging-tester-cli/package.json @@ -1,6 +1,6 @@ { "name": "@ovotech/genesys-web-messaging-tester-cli", - "version": "1.0.12", + "version": "1.0.13", "main": "lib/index.js", "types": "lib/index.d.ts", "license": "Apache-2.0", @@ -19,7 +19,7 @@ "scripts": { "build": "rm -rf ./lib && tsc -p tsconfig.json", "test": "jest __tests__/", - "test:execute": "ts-node src/index.ts ../../examples/cli/example-pass.yml -id $DEPLOYMENT_ID -r $REGION -p 10", + "test:execute": "ts-node src/index.ts ../../examples/cli/example-pass.yml -id $DEPLOYMENT_ID -r $REGION -p 10 -t 10", "test:execute:help": "ts-node src/index.ts --help", "lint": "eslint 'src/**/*.ts'" }, diff --git a/packages/genesys-web-messaging-tester-cli/src/cli.ts b/packages/genesys-web-messaging-tester-cli/src/cli.ts index 5ed9f8f..a74d514 100644 --- a/packages/genesys-web-messaging-tester-cli/src/cli.ts +++ b/packages/genesys-web-messaging-tester-cli/src/cli.ts @@ -109,6 +109,12 @@ GENESYSCLOUD_OAUTHCLIENT_SECRET`, false, ); program?.option('-fo, --failures-only', 'Only output failures', false); + program?.option( + '-t, --timeout ', + 'Seconds to wait for a response before failing the test', + parsePositiveInt, + 10, + ); const yamlFileReader = createYamlFileReader(fsReadFileSync); @@ -234,7 +240,7 @@ GENESYSCLOUD_OAUTHCLIENT_SECRET`, await convo.waitForConversationToStart(); for (const step of scenario.steps) { - await step(convo, {}); + await step(convo, { timeoutInSeconds: options.timeout }); } } catch (error) { context.scenarioResults.push({ diff --git a/packages/genesys-web-messaging-tester-cli/src/testScript/parseTestScript.ts b/packages/genesys-web-messaging-tester-cli/src/testScript/parseTestScript.ts index 184bf75..b12b29d 100644 --- a/packages/genesys-web-messaging-tester-cli/src/testScript/parseTestScript.ts +++ b/packages/genesys-web-messaging-tester-cli/src/testScript/parseTestScript.ts @@ -22,7 +22,9 @@ export interface TestScriptFile { }; } -export type StepContext = Record; +export interface StepContext { + timeoutInSeconds: number; +} export interface TestScriptScenario { sessionConfig: SessionConfig; @@ -38,14 +40,17 @@ export function parseScenarioStep( } if ('waitForReplyContaining' in step) { - return async (convo) => - await convo.waitForResponseWithTextContaining(step.waitForReplyContaining); + return async (convo, context) => + await convo.waitForResponseWithTextContaining(step.waitForReplyContaining, { + timeoutInSeconds: context.timeoutInSeconds, + }); } if ('waitForReplyMatching' in step) { - return async (convo) => + return async (convo, context) => await convo.waitForResponseWithTextMatchingPattern( new RegExp(step.waitForReplyMatching, 'im'), + { timeoutInSeconds: context.timeoutInSeconds }, ); }