Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Adds Cypress E2E tests and GitHub Action Cypress workflow (from a fork repo) #158

Closed
wants to merge 11 commits into from
Closed
103 changes: 103 additions & 0 deletions .github/workflows/cypress-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: E2E Cypress tests
on:
pull_request:
branches:
- master

jobs:
tests:
name: Run Cypress E2E tests
runs-on: ubuntu-latest
env:
# prevents extra Cypress installation progress messages
CI: 1
# avoid warnings like "tput: No value for $TERM and no -T specified"
TERM: xterm
steps:
- name: Set up JDK
uses: actions/setup-java@v1
with:
# TODO: Parse this from alerting plugin
java-version: 14
- name: Checkout
uses: actions/checkout@v2
with:
path: alerting
# TODO: Move this after Kibana plugin setup so we can pull down the correct branch to support all opendistro branches
repository: opendistro-for-elasticsearch/alerting
- name: Run elasticsearch with plugin
run: |
cd alerting
./gradlew run &
timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done'
- name: Checkout Alerting Kibana plugin
uses: actions/checkout@v2
with:
path: alerting-kibana-plugin
- name: Get Kibana version
id: kibana_version
run: |
echo "::set-output name=kibana_version::$(node -p "(require('./alerting-kibana-plugin/package.json').kibana.version).match(/[.0-9]+/)[0]")"
- name: Checkout Kibana
uses: actions/checkout@v2
with:
repository: opendistro-for-elasticsearch/kibana-oss
ref: ${{ steps.kibana_version.outputs.kibana_version }}
token: ${{ secrets.GITHUB_KIBANA_OSS }}
path: kibana
- name: Get node and yarn versions
id: versions
run: |
echo "::set-output name=node_version::$(node -p "(require('./kibana/package.json').engines.node).match(/[.0-9]+/)[0]")"
echo "::set-output name=yarn_version::$(node -p "(require('./kibana/package.json').engines.yarn).match(/[.0-9]+/)[0]")"
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ steps.versions.outputs.node_version }}
registry-url: 'https://registry.npmjs.org'
- name: Install correct yarn version for Kibana
run: |
npm uninstall -g yarn
echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}"
npm i -g yarn@${{ steps.versions.outputs.yarn_version }}
- name: Bootstrap plugin/kibana
env:
CYPRESS_INSTALL_BINARY: 0
run: |
mkdir -p kibana/plugins
mv alerting-kibana-plugin kibana/plugins
cd kibana/plugins/alerting-kibana-plugin
yarn kbn bootstrap
- name: Run kibana server
run: |
cd kibana/plugins/alerting-kibana-plugin
yarn start --no-base-path --no-watch &
sleep 300
curl localhost:5601/api/status
# timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:5601/api/status)" != "200" ]]; do sleep 5; done'
- name: Cache Cypress
id: cache-cypress
uses: actions/cache@v1
with:
path: ~/.cache/Cypress
key: cypress-cache-v2-${{ runner.os }}-${{ hashFiles('**/package.json') }}
# now let's install Cypress binary
- run: npx cypress install
- run: npx cypress cache list
# for now just chrome, use matrix to do all browsers later
- name: Cypress tests
run: |
cd kibana/plugins/alerting-kibana-plugin
yarn run cypress run --browser chrome
# Screenshots are only captured on failure, will change this once we do visual regression tests
- uses: actions/upload-artifact@v1
if: failure()
with:
name: cypress-screenshots
path: kibana/plugins/alerting-kibana-plugin/cypress/screenshots
# Test run video was always captured, so this action uses "always()" condition
- uses: actions/upload-artifact@v1
if: always()
with:
name: cypress-videos
path: kibana/plugins/alerting-kibana-plugin/cypress/videos
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ build
.kibana-plugin-helpers.dev.json
coverage
yarn-error.log
/cypress/screenshots/
/cypress/videos/
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,30 @@ Example output: `./build/opendistro-alerting-0.7.0.0.zip`

- `yarn start`

Starts Kibana and includes this plugin. Kibana will be available on `localhost:5601`.
- Starts Kibana and includes this plugin. Kibana will be available on `localhost:5601`.
- You must have Elasticsearch running with the Alerting plugin

## Test

There are unit/stubbed integration tests and Cypress e2e/integration tests.

- `yarn test:jest`

Runs the plugin tests.
- Runs the plugin unit tests.

- `yarn run cypress open`

- Opens the Cypress test runner.

- `yarn run cypress run`

- Runs all Cypress tests headlessly in the Electron browser.

To run the Cypress tests, you must have both Elasticsearch and Kibana running with the Alerting plugin.

If you are running Cypress tests with Kibana development server, pass these 2 options to `yarn start`:
1. `--no-base-path`: opt out the BasePathProxy.
1. `--no-watch`: make sure your server is not restarted.


## Contributing to Open Distro for Elasticsearch Alerting Kibana
Expand All @@ -62,7 +81,6 @@ Example output: `./build/opendistro-alerting-0.7.0.0.zip`
- Since this is a Kibana plugin, it can be useful to review the [Kibana contributing guide](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md) alongside the documentation around [Kibana plugins](https://www.elastic.co/guide/en/kibana/master/kibana-plugins.html) and [plugin development](https://www.elastic.co/guide/en/kibana/master/plugin-development.html).



## License

This code is licensed under the Apache 2.0 License.
Expand Down
7 changes: 7 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"defaultCommandTimeout": 10000,
"env": {
"elasticsearch": "localhost:9200",
"kibana": "localhost:5601"
}
}
10 changes: 10 additions & 0 deletions cypress/fixtures/sample_destination.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "sample_destination",
"type": "custom_webhook",
"custom_webhook": {
"header_params": {
"Content-Type": "application/json"
},
"url": "http://www.sample.com"
}
}
7 changes: 7 additions & 0 deletions cypress/fixtures/sample_destination_chime.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "sample_destination_chime",
"type": "chime",
"chime": {
"url": "https://hooks.chime.aws/incomingwebhooks/XXX?token=XXX"
}
}
25 changes: 25 additions & 0 deletions cypress/fixtures/sample_monitor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "sample_monitor",
"enabled": true,
"schedule": {
"period": {
"interval": "1",
"unit": "MINUTES"
}
},
"inputs": [
{
"search": {
"indices": ["*"],
"query": {
"query": {
"match_all": {}
}
}
}
}
],
"ui_metadata": {
"schedule": {}
}
}
37 changes: 37 additions & 0 deletions cypress/fixtures/sample_monitor_with_always_true_trigger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "sample_monitor_with_always_true_trigger",
"enabled": true,
"schedule": {
"period": {
"interval": "1",
"unit": "MINUTES"
}
},
"inputs": [
{
"search": {
"indices": ["*"],
"query": {
"query": {
"match_all": {}
}
}
}
}
],
"triggers": [
{
"name": "always_true_trigger",
"severity": "3",
"condition": {
"script": {
"source": "return true",
"lang": "painless"
}
}
}
],
"ui_metadata": {
"schedule": {}
}
}
35 changes: 35 additions & 0 deletions cypress/fixtures/sample_monitor_workflow_7.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "sample_monitor_workflow",
"enabled": true,
"schedule": {
"period": {
"interval": "1",
"unit": "MINUTES"
}
},
"inputs": [
{
"search": {
"indices": [".*"],
"query": {
"query": {
"term": { "monitor.type": "monitor" }
}
}
}
}
],
"triggers": [
{
"name": "sample_trigger",
"severity": "3",
"condition": {
"script": {
"source": "ctx.results[0].hits.total.value > 1",
"lang": "painless"
}
},
"actions": []
}
]
}
Loading