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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BRIDGE_BASE_ADDRESS="https://console-openshift-console.apps.your-cluster.example.com"
BRIDGE_KUBEADMIN_PASSWORD=""
TEST_NS=cy-test-ns
HIDE_XHR=true
Comment thread
lkladnit marked this conversation as resolved.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,11 @@ cypress/screenshots
## Helm gitignore

tmp/
.DS_Store
.DS_Store

## ui-tests-cy gitignore
ui-tests-cy/node_modules/
ui-tests-cy/gui-test-screenshots/

#Jetbrains
.idea/
15 changes: 15 additions & 0 deletions cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

# Cleanup nmstate test resources from previous runs
# Sources .env for namespace names

source .env 2>/dev/null || true
#TEST_NS="${TEST_NS:-cy-test-ns}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Uncomment and use the TEST_NS default.

Line 7 is commented out, so TEST_NS has no fallback when .env doesn't provide it. Without this line, the cleanup function cannot reliably determine which namespace to target.

🔧 Proposed fix
-#TEST_NS="${TEST_NS:-cy-test-ns}"
+TEST_NS="${TEST_NS:-cy-test-ns}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#TEST_NS="${TEST_NS:-cy-test-ns}"
TEST_NS="${TEST_NS:-cy-test-ns}"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cleanup.sh` at line 7, Uncomment and restore the default TEST_NS assignment
so the cleanup function has a fallback namespace: remove the leading comment
from the line that sets TEST_NS using parameter expansion
(TEST_NS="${TEST_NS:-cy-test-ns}") in cleanup.sh, ensuring any references to
TEST_NS inside the cleanup function (and related logic) will use the provided
env value or fall back to "cy-test-ns" when .env does not supply it.


cleanup () {
echo "Cleaning up nmstate ui test resources..."
# NNCPs and VirtualMachineNetworks are cluster-scoped resources — no namespace flag needed
oc delete nncp test-form-nncp test-req-nncp example test-nncp-physical-network --ignore-not-found --wait=true --timeout=180s
oc delete --ignore-not-found=true virtualmachinenetwork test-project-vmn test-labeled-vmn --wait=true --timeout=60s 2>/dev/null || true
echo "Cleanup done."
}
72 changes: 0 additions & 72 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Setup test namespaces (create if they don't exist)
# Sources .env for namespace names

source .env 2>/dev/null || true
TEST_NS="${TEST_NS:-cy-test-ns}"
Comment thread
coderabbitai[bot] marked this conversation as resolved.

setup () {
echo "Setting up test namespaces..."
oc get namespace "${TEST_NS}" 2>/dev/null || oc create namespace "${TEST_NS}"
echo "Setup done."
}
44 changes: 44 additions & 0 deletions test-cypress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

set +e

source ./cleanup.sh
source ./setup.sh

set -x

while getopts g:s: flag
do
case "${flag}" in
g) gui=${OPTARG};;
s) spec=${OPTARG};;
esac
done

if [ -z "${spec-}" ]; then
spec="tests/all.cy.ts"
fi

# Run cleanup and setup before tests
cleanup
setup

cd ui-tests-cy

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add error handling to the cd command.

If cd ui-tests-cy fails (directory missing or inaccessible), the script continues in the wrong directory. Lines 26-27 then run npm ci and mkdir in an unintended location, corrupting the environment or producing confusing failures.

🛡️ Proposed fix
-cd ui-tests-cy
+cd ui-tests-cy || exit 1
 npm ci
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cd ui-tests-cy
cd ui-tests-cy || exit 1
npm ci
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 25-25: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test-cypress.sh` at line 25, The script uses a bare "cd ui-tests-cy" which
can fail and cause subsequent "npm ci" and "mkdir" to run in the wrong
directory; after the cd command (referencing the literal cd ui-tests-cy) add
explicit error handling to detect failure and abort the script (e.g., check the
exit status and print an error before exit) so that npm ci and mkdir only run
when the directory change succeeds.

npm ci
mkdir -p gui-test-screenshots

if [ -n "${gui-}" ]; then
npx cypress open --env openshift=true --spec "$spec"
else
node --max-old-space-size=4096 ./node_modules/.bin/cypress run --env openshift=true --browser "${BRIDGE_E2E_BROWSER_NAME:=electron}" --spec "$spec" | tee ./gui-test-screenshots/build.log
test_exit_code=${PIPESTATUS[0]}
cd ..
cd ui-tests-cy && npm run cypress-postreport && cd ..

# Copy JUnit XML to path expected by Jenkins pipeline
mkdir -p cypress/gui-test-screenshots
cp ui-tests-cy/gui-test-screenshots/junit_cypress-*.xml cypress/gui-test-screenshots/ 2>/dev/null || true

cleanup
exit "${test_exit_code}"
fi
15 changes: 15 additions & 0 deletions ui-tests-cy/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"cypress/globals": true,
"node": true
},
"extends": ["plugin:cypress/recommended"],
"plugins": ["cypress"],
"rules": {
"no-console": "off",
"no-namespace": "off",
"no-redeclare": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-namespace": "off"
}
}
28 changes: 28 additions & 0 deletions ui-tests-cy/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { defineConfig } = require('cypress');

module.exports = defineConfig({
chromeWebSecurity: false,
defaultCommandTimeout: 60000,
e2e: {
setupNodeEvents(on, config) {
return require('./plugins/index.ts')(on, config);
},
specPattern: 'tests/**/*.cy.ts',
supportFile: 'support/index.ts',
testIsolation: false,
},
fixturesFolder: false,
pageLoadTimeout: 120000,
reporter: './node_modules/cypress-multi-reporters',
reporterOptions: { configFile: 'reporter-config.json' },
retries: { openMode: 0, runMode: 0 },
screenshotOnRunFailure: true,
screenshotsFolder: './gui-test-screenshots/screenshots/',
trashAssetsBeforeRuns: true,
video: true,
videoCompression: false,
videosFolder: './gui-test-screenshots/videos/',
viewportHeight: 1080,
viewportWidth: 1920,
watchForFileChanges: false,
});
Loading