Skip to content

Commit

Permalink
Add test for exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
SketchingDev committed Jul 20, 2023
1 parent 25f8e71 commit 1972734
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ against scenarios in a YAML file. This makes testing:

The above test is using the test-script:

> [examples/cli/example.yml](https://github.com/ovotech/genesys-web-messaging-tester/tree/main/examples/cli/example.yml)
> [examples/cli/example-pass.yml](https://github.com/ovotech/genesys-web-messaging-tester/tree/main/examples/cli/example-pass.yml)
```yaml
config:
Expand Down Expand Up @@ -67,7 +67,7 @@ npm install -g @ovotech/genesys-web-messaging-tester-cli
Write a test-script containing all the scenarios you wish to run along with
the [ID and region of your Web Messenger Deployment](https://help.mypurecloud.com/articles/deploy-messenger/).

> [examples/cli/example.yml](https://github.com/ovotech/genesys-web-messaging-tester/tree/main/examples/cli/example.yml)
> [examples/cli/example-pass.yml](https://github.com/ovotech/genesys-web-messaging-tester/tree/main/examples/cli/example-pass.yml)

```yaml
config:
Expand Down Expand Up @@ -95,7 +95,7 @@ scenarios:
Then run the test by pointing to the test-script in the terminal:

```shell
web-messaging-tester tests/example.yml
web-messaging-tester tests/example-pass.yml
```

## Examples
Expand Down
10 changes: 10 additions & 0 deletions examples/cli/example-fail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
config:
deploymentId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
region: xxxx.pure.cloud
scenarios:
"Failing test using Containing":
- say: hi
- waitForReplyContaining: This is deliberately wrong
"Failing test using Matching":
- say: hi
- waitForReplyMatching: This is [0-9]+ wrong
File renamed without changes.
21 changes: 18 additions & 3 deletions examples/cli/run.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
#sh

# exit when any command fails
set -e

RED='\033[0;31m'
NO_COLOUR='\033[0m'

npm install -g ../../packages/genesys-web-messaging-tester-cli

function cleanup {
npm uninstall -g ../../packages/genesys-web-messaging-tester-cli
}
trap cleanup EXIT

web-messaging-tester example.yml -id $DEPLOYMENT_ID -r $REGION -p 10
## Passing test exits with code 0
web-messaging-tester example-pass.yml -id $DEPLOYMENT_ID -r $REGION -p 10
if [ $? -ne 0 ]
then
echo "${RED}Passing test did not result in Exit Code of 0. Exit code was $?${NO_COLOUR}"
exit 1
fi

## Failing test exists with code 1
web-messaging-tester example-fail.yml -id $DEPLOYMENT_ID -r $REGION -p 10
if [ $? -ne 1 ]
then
echo "${RED}Failing test did not result in Exit Code of 1. Exit code was $?${NO_COLOUR}"
exit 1
fi
4 changes: 2 additions & 2 deletions packages/genesys-web-messaging-tester-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ against scenarios in a YAML file. This makes testing:

The above test is using the test-script:

> [examples/cli/example.yml](https://github.com/ovotech/genesys-web-messaging-tester/tree/main/examples/cli/example.yml)
> [examples/cli/example-pass.yml](https://github.com/ovotech/genesys-web-messaging-tester/tree/main/examples/cli/example-pass.yml)
```yaml
config:
Expand Down Expand Up @@ -67,7 +67,7 @@ npm install -g @ovotech/genesys-web-messaging-tester-cli
Write a test-script containing all the scenarios you wish to run along with
the [ID and region of your Web Messenger Deployment](https://help.mypurecloud.com/articles/deploy-messenger/).

> [examples/cli/example.yml](https://github.com/ovotech/genesys-web-messaging-tester/tree/main/examples/cli/example.yml)
> [examples/cli/example-pass.yml](https://github.com/ovotech/genesys-web-messaging-tester/tree/main/examples/cli/example-pass.yml)

```yaml
config:
Expand Down
2 changes: 1 addition & 1 deletion packages/genesys-web-messaging-tester-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.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",
"test:execute:help": "ts-node src/index.ts --help",
"lint": "eslint 'src/**/*.ts'"
},
Expand Down

0 comments on commit 1972734

Please sign in to comment.