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

Add windows support for cypress workflow #220

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 97 additions & 11 deletions .github/workflows/cypress-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,96 +1,182 @@
##
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
##

name: Cypress integration tests workflow
on:
pull_request:
branches:
- "*"
push:
branches:
- "*"

on: [pull_request, push]

env:
PLUGIN_NAME: security-analytics-dashboards
OPENSEARCH_DASHBOARDS_VERSION: '2.4.0'
OPENSEARCH_VERSION: '2.4.0-SNAPSHOT'
SECURITY_ANALYTICS_BRANCH: '2.4'

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
WORKING_DIR: ${{ matrix.working_directory }}.

strategy:
# This setting says that all jobs should finish, even if one fails
fail-fast: false
matrix:
# TODO: macos-latest was removed due to CI flakiness, we can revisit adding it back later
os: [ ubuntu-latest, windows-latest ]
include:
- os: windows-latest
working_directory: X:\
os_java_options: -Xmx4096M
cypress_cache_folder: ~/AppData/Local/Cypress/Cache
- os: ubuntu-latest
jest_test_args: --coverage
cypress_cache_folder: ~/.cache/Cypress
# TODO: Add back when macos-latest is back in the test matrix
# - os: macos-latest
# cypress_cache_folder: ~/Library/Caches/Cypress

name: Run Cypress E2E tests on ${{ matrix.os }}

runs-on: ${{ matrix.os }}

steps:
- name: Set up JDK
uses: actions/setup-java@v1
with:
# TODO: Parse this from security analytics plugin (https://github.com/opensearch-project/security-analytics/issues/170)
java-version: 11

- name: Checkout security analytics
uses: actions/checkout@v2
with:
path: security-analytics
repository: opensearch-project/security-analytics
ref: ${{ env.SECURITY_ANALYTICS_BRANCH }}

# This is a hack, but this step creates a link to the X: mounted drive, which makes the path
# short enough to work on Windows
- name: Shorten Path
if: ${{ matrix.os == 'windows-latest' }}
run: subst 'X:' .

- name: Run opensearch with plugin
working-directory: ${{ env.WORKING_DIR }}
run: |
# Install coreutils for macOS since timeout doesn't seem to available on that OS even when forcing bash shell
if [ "$RUNNER_OS" == "macOS" ]; then
brew install coreutils
fi
cd security-analytics
./gradlew run -Dopensearch.version=${{ env.OPENSEARCH_VERSION }} &
sleep 300
# timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done'
shell: bash
env:
_JAVA_OPTIONS: ${{ matrix.os_java_options }}

- name: Checkout Security Analytics Dashboards plugin
uses: actions/checkout@v2
with:
path: security-analytics-dashboards-plugin

- name: Checkout OpenSearch-Dashboards
uses: actions/checkout@v2
with:
repository: opensearch-project/OpenSearch-Dashboards
path: OpenSearch-Dashboards
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}

- name: Get node and yarn versions
id: versions
run: |
echo "::set-output name=node_version::$(node -p "(require('./OpenSearch-Dashboards/package.json').engines.node).match(/[.0-9]+/)[0]")"
echo "::set-output name=yarn_version::$(node -p "(require('./OpenSearch-Dashboards/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 OpenSearch-Dashboards
run: |
npm uninstall -g yarn
echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}"
npm i -g yarn@${{ steps.versions.outputs.yarn_version }}

- name: Set npm to use bash for shell
if: ${{ matrix.os == 'windows-latest' }}
run: |
# Sets Windows to use bash for npm shell so the script commands work as intended
npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"

- name: Bootstrap plugin/OpenSearch-Dashboards
run: |
mkdir -p OpenSearch-Dashboards/plugins
mv security-analytics-dashboards-plugin OpenSearch-Dashboards/plugins
cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin
yarn osd bootstrap

- name: Run OpenSearch-Dashboards server
run: |
cd OpenSearch-Dashboards
yarn start --no-base-path --no-watch &
sleep 300
# timeout 300 bash -c 'while [[ "$(curl -s localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done'
# for now just chrome, use matrix to do all browsers later

- name: Install Cypress
run: |
cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin
# This will install Cypress in case the binary is missing which can happen on Windows and Mac
# If the binary exists, this will exit quickly so it should not be an expensive operation
npx cypress install
shell: bash

- name: Get Cypress version
id: cypress_version
run: |
cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin
echo "::set-output name=cypress_version::$(cat ./package.json | jq '.dependencies.cypress' | tr -d '"')"

- name: Cache Cypress
id: cache-cypress
uses: actions/cache@v2
with:
path: ${{ matrix.cypress_cache_folder }}
key: cypress-cache-v2-${{ runner.os }}-${{ hashFiles('**/package.json') }}

- name: Reset npm's script shell
if: ${{ matrix.os == 'windows-latest' }}
run: |
# Resetting npm's script shell for Windows so `yarn run cypress` doesn't have conflicts
npm config delete script-shell

- name: Cypress tests
uses: cypress-io/github-action@v2
with:
working-directory: OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin
command: yarn run cypress run
wait-on: 'http://localhost:5601'
browser: chrome
env:
CYPRESS_CACHE_FOLDER: ${{ matrix.cypress_cache_folder }}
# 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
name: cypress-screenshots-${{ matrix.os }}
path: OpenSearch-Dashboards/plugins/security-analytics-dashboards-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
name: cypress-videos-${{ matrix.os }}
path: OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin/cypress/videos
22 changes: 22 additions & 0 deletions public/components/DeleteModal/DeleteModal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render } from '@testing-library/react';
import DeleteModal from './DeleteModal';

describe('<DeleteModal /> spec', () => {
it('renders the component', () => {
const tree = render(
<DeleteModal
closeDeleteModal={() => jest.fn()}
ids={'some ids'}
onClickDelete={() => jest.fn()}
type={'some type'}
/>
);
expect(tree).toMatchSnapshot();
});
});
Loading