Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e test poc #116

Merged
merged 17 commits into from
Nov 25, 2020
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
examples
__tests__/e2e/tmp/
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ tmp

# Vim temp files
*.swp

__tests__/e2e/tmp/

.idea/
1 change: 1 addition & 0 deletions __tests__/e2e/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
68 changes: 68 additions & 0 deletions __tests__/e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
version: '3.7'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
container_name: es01
healthcheck:
test: ["CMD-SHELL", "curl -s http://localhost:9200/_cluster/health | grep -vq '\"status\":\"red\"'"]
retries: 10
interval: 20s
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- cluster.initial_master_nodes=es01
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
kib01:
image: docker.elastic.co/kibana/kibana:${STACK_VERSION}
container_name: kib01
healthcheck:
test: ["CMD", "curl", "-I", "http://localhost:5601/status"]
interval: 30s
retries: 10
start_period: 30s
ports:
- 5601:5601
environment:
ELASTICSEARCH_URL: http://es01:9200
ELASTICSEARCH_HOSTS: http://es01:9200
networks:
- elastic
synth01:
image: docker.elastic.co/experimental/synthetics:${STACK_VERSION}-synthetics
container_name: synthetics
depends_on:
- es01
- kib01
volumes:
- ../../examples/docker/heartbeat.docker.yml:/usr/share/heartbeat/heartbeat.yml:ro
- ../../:/opt/elastic-synthetics:rw
security_opt:
- seccomp=../../examples/docker/seccomp_profile.json
environment:
ELASTICSEARCH_URL: http://es01:9200
ELASTICSEARCH_HOSTS: http://es01:9200
command:
-E output.elasticsearch.hosts=["es01:9200"]

networks:
- elastic

volumes:
data01:
driver: local


networks:
elastic:
driver: bridge
13 changes: 13 additions & 0 deletions __tests__/e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "e2e-synthetics",
"private": true,
"main": "index.js",
"license": "MIT",
"scripts": {
"setup": "bash scripts/setup.sh",
"test": "npm i && npm run setup && bash scripts/test.sh"
},
"devDependencies": {
"@elastic/synthetics": "../../"
}
}
35 changes: 35 additions & 0 deletions __tests__/e2e/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -e

# variables

# ensure Docker is running
docker ps &> /dev/null
if [ $? -ne 0 ]; then
echo "⚠️ Please start Docker"
exit 1
fi

# formatting
bold=$(tput bold)
normal=$(tput sgr0)

# paths
E2E_DIR="./"
TMP_DIR="tmp"

#
# Create tmp folder
##################################################
echo "" # newline
echo "${bold}Temporary folder${normal}"
echo "Temporary files will be stored in: ${E2E_DIR}${TMP_DIR}"
mkdir -p ${TMP_DIR}


echo "" # newline
echo "${bold}Starting elasticsearch , kibana and synthetics docker${normal}"
echo "" # newline

STACK_VERSION=7.10.0 docker-compose --file docker-compose.yml up --remove-orphans > ${TMP_DIR}/docker-logs.log 2>&1 &

26 changes: 26 additions & 0 deletions __tests__/e2e/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -e


# formatting
bold=$(tput bold)
normal=$(tput sgr0)


# Wait for synthetics docker to start
##################################################
echo "" # newline
echo "${bold}Waiting for synthetics docker to start...${normal}"
until [ "`docker inspect -f {{.State.Running}} synthetics`" == "true" ]; do
sleep 0.1;
done;

echo "✅ Setup completed successfully. Running e2e tests..."

#
# run e2e tests journey
##################################################

npx @elastic/synthetics uptime.journey.ts


45 changes: 45 additions & 0 deletions __tests__/e2e/uptime.journey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* MIT License
*
* Copyright (c) 2020-present, Elastic NV
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

import { journey, step } from '@elastic/synthetics';

journey('E2e test synthetics', async ({ page }) => {
step('Go to kibana uptime app', async () => {
await page.goto('http://localhost:5601/app/uptime');
});

step('Check if there is table data', async () => {
await page.click('[data-test-subj=uptimeOverviewPage]');
await page.click('div.euiBasicTable', { timeout: 60 * 1000 });
});

step('Click on my monitor', async () => {
await page.click('[data-test-subj=monitor-page-link-my-monitor]');
});

step('It navigates to details page', async () => {
await page.click('[data-test-subj=uptimeMonitorPage]');
});
});