Skip to content
Open
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
11 changes: 4 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,13 @@ You should create new Cypress tests when:
#### Quick Test Commands

```bash
cd web/cypress

# Run all regression tests
npm run cypress:run --spec "cypress/e2e/**/regression/**"
cd web

# Run BVT (Build Verification Tests)
npm run cypress:run --spec "cypress/e2e/monitoring/00.bvt_admin.cy.ts"
# Run monitoring tests (changed files only)
npm run test-cypress-monitoring

# Run COO tests
npm run cypress:run --spec "cypress/e2e/coo/*.cy.ts"
npx cypress run --env grepTags='@acm-alerting @perses-dashboards @cluster-health-analyzer --@flaky --@xfail'

# Interactive mode
npm run cypress:open
Expand Down
11 changes: 7 additions & 4 deletions web/cypress/CYPRESS_TESTING_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ export const runAlertTests = (perspective: string) => {
### Common Commands

```bash
cd web/cypress
cd web

# Run all monitoring tests (changed files only)
npm run test-cypress-monitoring

# Run specific tests
npm run cypress:run -- --spec "cypress/e2e/alerts/alerts_regression.cy.ts"
npm run cypress:run -- --spec "cypress/e2e/metrics/metrics_regression.cy.ts"
npx cypress run --spec "cypress/e2e/alerts/alerts_regression.cy.ts"
npx cypress run --spec "cypress/e2e/metrics/metrics_regression.cy.ts"

# Interactive mode (GUI)
npm run cypress:open
Expand Down Expand Up @@ -278,7 +281,7 @@ source ./configure-env.sh
3. **Run with debug**:
```bash
export CYPRESS_DEBUG=true
npm run cypress:run
npm run test-cypress-monitoring
```
4. **Run interactively**:
```bash
Expand Down
62 changes: 62 additions & 0 deletions web/cypress/run-changed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

CHANGED_FILES=$(git diff --name-only origin/main...HEAD)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target branch might be different we should provide it from env defaulting to main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add error handling, in shallow checkouts the main branch might not exist.


RUN_ALL=false
declare -A TAGS_TO_RUN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to change this into something POSIX compatible, I got the following issue while trying to run on mac:

./cypress/run-changed.sh: line 6: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]


# Create frontend folder to tag map
declare -A FEATURE_MAP
FEATURE_MAP["incidents"]="@cluster-health-analyzer"
FEATURE_MAP["alerts"]="@alerting"
FEATURE_MAP["legacy-dashboards"]="@legacy-dashboards"
FEATURE_MAP["metrics"]="@metrics"
FEATURE_MAP["perses-dashboards"]="@perses-dashboards"
FEATURE_MAP["targets"]="@targets"

for FILE in $CHANGED_FILES; do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we have file paths with white spaces, but this will split on white space


# Check if any file is outside of web/src/features/
if [[ ! "$FILE" =~ ^web/src/features/ ]]; then
echo "Global or shared file changed: $FILE"
RUN_ALL=true
break
fi

# File is in features and looks like: web/src/features/incidents/components/App.tsx
# awk splits by '/' and grabs the 4th segment
FEATURE_DIR=$(echo "$FILE" | awk -F'/' '{print $4}')
CYPRESS_TAG=${FEATURE_MAP[$FEATURE_DIR]}

if [ -n "$CYPRESS_TAG" ]; then
TAGS_TO_RUN["$CYPRESS_TAG"]=1
else
echo "Error: Unmapped feature directory changed: $FEATURE_DIR"
exit 1
fi
done

if [ "$RUN_ALL" = true ]; then
echo "Changes affect global scope or unmapped features. Running ALL monitoring tests..."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unmapped features already exits

Suggested change
echo "Changes affect global scope or unmapped features. Running ALL monitoring tests..."
echo "Changes affect global scope. Running ALL monitoring tests..."


DEFAULT_TAGS="@alerting @legacy-dashboards @metrics @targets acm-alerting @cluster-health-analyzer @perses-dashboards --@flaky --@xfail"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DEFAULT_TAGS="@alerting @legacy-dashboards @metrics @targets acm-alerting @cluster-health-analyzer @perses-dashboards --@flaky --@xfail"
DEFAULT_TAGS="@alerting @legacy-dashboards @metrics @targets @acm-alerting @cluster-health-analyzer @perses-dashboards --@flaky --@xfail"

npm run test-cypress-monitoring:base -- --env grepTags="${DEFAULT_TAGS}"
else
UNIQUE_TAGS=("${!TAGS_TO_RUN[@]}")

if [ ${#UNIQUE_TAGS[@]} -eq 0 ]; then
echo "No relevant source files changed. Skipping tests."
exit 0
fi

FEATURE_TAGS=$(
IFS=" "
echo "${UNIQUE_TAGS[*]}"
)

GREP_TAGS="${FEATURE_TAGS} --@flaky --@xfail"

echo "Running specific tests for tags: $GREP_TAGS"

npm run test-cypress-monitoring:base -- --env grepTags="${GREP_TAGS}"
fi
2 changes: 1 addition & 1 deletion web/cypress/support/alerts/alerts_regressions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
WatchdogAlert,
} from '../../fixtures/shared/cluster-monitoring-operator/constants';
import { FilterOUIAIDs } from '@/shared/constants/data-test';
import { listPage } from 'cypress/views/shared/list-page';
import { listPage } from '../../views/shared/list-page';

export interface PerspectiveConfig {
name: string;
Expand Down
3 changes: 2 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"test": "npm run cypress:run:ci",
"test-cypress-console": "./node_modules/.bin/cypress open --browser chrome",
"test-cypress-console-headless": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless",
"test-cypress-monitoring": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@alerting @legacy-dashboards @metrics @targets --@flaky --@xfail --@virtualization --@coo --@acm'",
"test-cypress-monitoring": "../scripts/run-selective-e2e.sh",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this script in a different PR or should be ./cypress/run-changed.sh

"test-cypress-monitoring:base": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@alerting @legacy-dashboards @metrics @targets --@flaky --@xfail --@virtualization --@coo --@acm'",
"test-cypress-monitoring-dev": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@alerting @legacy-dashboards @metrics @targets --@xfail --@virtualization --@coo --@acm'",
"test-cypress-monitoring-bvt": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@alerting @legacy-dashboards @metrics @targets --@xfail --@virtualization --@coo --@acm'",
"test-cypress-monitoring-regression": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@alerting @legacy-dashboards @metrics @targets --@flaky --@xfail --@acm --@coo --@virtualization'",
Expand Down