diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index e34683360..72cad7462 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -1,73 +1,127 @@ +## +# 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 @@ -75,6 +129,34 @@ jobs: 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: @@ -82,15 +164,19 @@ jobs: 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 diff --git a/public/components/DeleteModal/DeleteModal.test.tsx b/public/components/DeleteModal/DeleteModal.test.tsx new file mode 100644 index 000000000..4a187ea45 --- /dev/null +++ b/public/components/DeleteModal/DeleteModal.test.tsx @@ -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(' spec', () => { + it('renders the component', () => { + const tree = render( + jest.fn()} + ids={'some ids'} + onClickDelete={() => jest.fn()} + type={'some type'} + /> + ); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/public/components/DeleteModal/__snapshots__/DeleteModal.test.tsx.snap b/public/components/DeleteModal/__snapshots__/DeleteModal.test.tsx.snap new file mode 100644 index 000000000..b53356b0f --- /dev/null +++ b/public/components/DeleteModal/__snapshots__/DeleteModal.test.tsx.snap @@ -0,0 +1,184 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` spec renders the component 1`] = ` +Object { + "asFragment": [Function], + "baseElement": +