Skip to content

Commit 618ec93

Browse files
authored
Merge branch 'main' into fix_ade_devloper_env_tool_fix
2 parents 7ccdb83 + 857e486 commit 618ec93

File tree

5 files changed

+83
-163
lines changed

5 files changed

+83
-163
lines changed

.config/dictionary.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Containerfile
55
Customizer
66
Devfile
77
Devfiles
8+
EXTEST
89
Elio’s
910
FQCN
1011
FQCNs
@@ -21,7 +22,6 @@ Maciążek
2122
Modeline
2223
Modelines
2324
Npmjs
24-
OPTSTRING
2525
PKGMGR
2626
PYCMD
2727
PYTHONBREAKPOINT
@@ -99,6 +99,7 @@ pydoclint
9999
pyvenv
100100
relogin
101101
rhsso
102+
rimraf
102103
seealso
103104
servernum
104105
shiki

Taskfile.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,57 @@ tasks:
196196
# cannot put coverage option inside .vscode-test.mjs
197197
- "{{.XVFB}}vscode-test --install-extensions ansible-*.vsix --coverage --coverage-output ./out/coverage/e2e --coverage-reporter text --coverage-reporter cobertura --coverage-reporter lcovonly"
198198
interactive: true
199+
ui-prepare:
200+
deps:
201+
- package
202+
generates:
203+
- out/test-resources/driverVersion
204+
- out/test-resources/manifest.json
205+
- out/test-resources/*.zip
206+
- out/test-resources/*.tar.gz
207+
- out/ext/**/*
208+
sources:
209+
- tools/test-launcher.sh
210+
- "*.vsix"
211+
env:
212+
CODE_VERSION: max
213+
cmds:
214+
- extest get-vscode -c "${CODE_VERSION}" -s out/test-resources
215+
- extest get-chromedriver -c "${CODE_VERSION}" -s out/test-resources
216+
- extest install-vsix -f "$( find . -maxdepth 1 -name '*.vsix' )" -e out/ext -s out/test-resources
217+
- extest install-from-marketplace redhat.vscode-yaml ms-python.python -e out/ext -s out/test-resources
218+
- rimraf out/log/.failed out/log/ui* out/junit/ui/ out/coverage/ui/ out/test-resources/test.log out/test-resources/screenshots/ out/test-resources/settings/logs/*
199219
ui:
200220
desc: Run UI tests with extest {{.XVFB}}
201221
deps:
202-
- package
222+
- ui-prepare
223+
env:
224+
TEST_PREFIX: "ui"
203225
sources:
204226
- src/**/*
205227
- test/**/*
206228
- ./tools/test-launcher.sh
207229
generates:
208230
- out/junit/ui/.passed
209231
cmds:
210-
- ' {{.XVFB}}bash -c ''. "{{.VIRTUAL_ENV}}/bin/activate" && COVERAGE=1 MOCK_LIGHTSPEED_API=1 ./tools/test-launcher.sh'''
232+
- ' {{.XVFB}}bash -c ''. "{{.VIRTUAL_ENV}}/bin/activate" && EXTEST_ARGS="--coverage" MOCK_LIGHTSPEED_API=1 ./tools/test-launcher.sh'''
233+
interactive: true
234+
ui-smoke:
235+
desc: Run UI test with extest but no coverage in order to detect packaging issues
236+
env:
237+
TEST_PREFIX: "ui-smoke"
238+
deps:
239+
- ui-prepare
240+
cmds:
241+
# essential cleanup to avoid accidental loading of files from disk instead of from within the package
242+
- rimraf out/client/src out/vitebuild
243+
- ' {{.XVFB}}bash -c ''. "{{.VIRTUAL_ENV}}/bin/activate" && MOCK_LIGHTSPEED_API=1 ./tools/test-launcher.sh'''
211244
interactive: true
212245
ui-oldest:
213246
desc: Run UI tests (CODE_VERSION='min')
214247
env:
215248
CODE_VERSION: min
249+
TEST_PREFIX: "ui-oldest"
216250
deps:
217251
- ui
218252
unit:

test/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ Run the following command:
7171
Run the following command:
7272

7373
```shell
74-
MOCK_LIGHTSPEED_API=1 TEST_TYPE=e2e COVERAGE=1 ./tools/test-launcher.sh
74+
MOCK_LIGHTSPEED_API=1 TEST_TYPE=e2e ./tools/test-launcher.sh
7575
```
7676

7777
#### UI Tests
7878

7979
Run the following command:
8080

8181
```shell
82-
COVERAGE=1 MOCK_LIGHTSPEED_API=1 ./tools/test-launcher.sh
82+
MOCK_LIGHTSPEED_API=1 ./tools/test-launcher.sh
8383
```

test/ui/mockLightspeedServer/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const logger = winston.createLogger({
3838
transports: [
3939
new winston.transports.Console(),
4040
new winston.transports.File({
41-
filename: `out/log/${process.env.TEST_ID ?? ""}-mock-server.log`,
41+
filename: `out/log/${process.env.TEST_ID ?? "ui"}-mock-server.log`,
4242
}),
4343
],
4444
});

tools/test-launcher.sh

Lines changed: 42 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#!/usr/bin/env bash
22
# cspell: ignore nullglob
33
export DONT_PROMPT_WSL_INSTALL=1
4-
set -eu
5-
yarn run compile
6-
set -o pipefail
4+
set -euo pipefail
75

86
DIR="$(dirname "$(realpath "$0")")"
97
# shellcheck source=/dev/null
108
. "$DIR/_utils.sh"
119

10+
CODE_VERSION="${CODE_VERSION:-max}"
11+
TEST_LIGHTSPEED_PORT=3000
12+
TEST_LIGHTSPEED_URL="${TEST_LIGHTSPEED_URL:-}"
13+
MOCK_LIGHTSPEED_API="${MOCK_LIGHTSPEED_API:-}"
14+
UI_TARGET="${UI_TARGET:-*.test.js}"
15+
1216
# shellcheck disable=SC2317
1317
cleanup()
1418
{
@@ -38,20 +42,6 @@ cleanup()
3842
trap "cleanup OTHER" HUP INT ABRT BUS TERM
3943
trap "cleanup EXIT" EXIT
4044

41-
42-
CODE_VERSION="${CODE_VERSION:-max}"
43-
TEST_LIGHTSPEED_PORT=3000
44-
TEST_LIGHTSPEED_URL="${TEST_LIGHTSPEED_URL:-}"
45-
COVERAGE="${COVERAGE:-}"
46-
MOCK_LIGHTSPEED_API="${MOCK_LIGHTSPEED_API:-}"
47-
TEST_TYPE="${TEST_TYPE:-ui}" # e2e or ui
48-
COVERAGE_ARG=""
49-
UI_TARGET="${UI_TARGET:-*.test.js}"
50-
OPTSTRING=":c"
51-
52-
# https://github.com/microsoft/vscode/issues/204005
53-
rm -f out/log/.failed >/dev/null
54-
5545
function start_server() {
5646
log notice "Starting the mockLightspeedServer"
5747
if [[ -n "${TEST_LIGHTSPEED_URL}" ]]; then
@@ -85,34 +75,6 @@ function stop_server() {
8575
fi
8676
}
8777

88-
function retry_command() {
89-
local max_attempts="${1}"
90-
local delay="${2}"
91-
local attempt=1
92-
shift 2
93-
local command=("$@")
94-
95-
while [ $attempt -le "$max_attempts" ]; do
96-
if "${command[@]}"; then
97-
return 0
98-
else
99-
local exit_code=$?
100-
if [ $attempt -lt "$max_attempts" ]; then
101-
log warning "Command failed with exit code $exit_code. Retrying in ${delay}s..."
102-
# Clean up corrupted/partial downloads and unpacked directories
103-
log notice "Cleaning up potentially corrupted VS Code cache..."
104-
rm -vf .vscode-test/ out/test-resources/*stable.zip out/test-resources/*.tar.gz || true
105-
rm -rfv out/test-resources/VSCode-* out/test-resources/"Visual Studio Code.app" || true
106-
sleep "$delay"
107-
attempt=$((attempt + 1))
108-
else
109-
log error "Command failed after $max_attempts attempts"
110-
return $exit_code
111-
fi
112-
fi
113-
done
114-
}
115-
11678
function refresh_settings() {
11779
local test_path=$1
11880
local test_id=$2
@@ -131,117 +93,40 @@ function refresh_settings() {
13193
cp -f out/settings.json "out/log/${test_id}-settings.json"
13294
}
13395

134-
135-
while getopts ${OPTSTRING} opt; do
136-
case ${opt} in
137-
c)
138-
log notice "Coverage enabled"
139-
COVERAGE="1"
140-
;;
141-
?)
142-
log error "Invalid option: -${OPTARG}."
143-
exit 1
144-
;;
145-
esac
146-
done
147-
148-
if [[ "${COVERAGE}" == "1" ]]; then
149-
COVERAGE_ARG="--coverage"
150-
fi
151-
152-
153-
154-
# Start the mock Lightspeed server and run UI tests with the new VS Code
155-
156-
retry_command 3 2 extest get-vscode -c "${CODE_VERSION}" -s out/test-resources
157-
158-
log notice "Downloading ChromeDriver..."
159-
retry_command 3 2 extest get-chromedriver -c "${CODE_VERSION}" -s out/test-resources
160-
161-
# Pre-pull ansible-navigator container image for UI tests (non-macOS only)
162-
if [[ "$OSTYPE" != "darwin"* ]]; then
163-
CONTAINER_ENGINE=${CONTAINER_ENGINE:-podman}
164-
ANSIBLE_IMAGE="ghcr.io/ansible/community-ansible-dev-tools:latest"
165-
166-
log notice "Pre-pulling container image for ansible-navigator tests..."
167-
if command -v "$CONTAINER_ENGINE" &> /dev/null; then
168-
if $CONTAINER_ENGINE pull "$ANSIBLE_IMAGE" 2>&1 | tee /dev/stderr; then
169-
log notice "Container image pulled successfully"
170-
else
171-
log warning "Failed to pull container image, tests may be slower"
96+
# shellcheck disable=SC2044
97+
find out/client/test/ui/ -name "${UI_TARGET}" -print0 | while IFS= read -r -d '' test_file; do
98+
basename="${test_file##*/}"
99+
TEST_ID="${TEST_PREFIX:-ui}-${basename%.*}"
100+
TEST_JUNIT_FILE="./out/junit/ui/${TEST_ID}-test-results.xml"
101+
export TEST_ID
102+
{
103+
log notice "Testing ${test_file}"
104+
log notice "Cleaning existing User settings..."
105+
rm -rfv ./out/test-resources/settings/User/ > /dev/null
106+
107+
if [[ "$MOCK_LIGHTSPEED_API" == "1" ]]; then
108+
stop_server
109+
start_server
172110
fi
173-
else
174-
log warning "$CONTAINER_ENGINE not found, skipping container image pre-pull"
175-
fi
176-
fi
177-
if [[ "$COVERAGE" == "" ]]; then
178-
vsix=$(find . -maxdepth 1 -name '*.vsix')
179-
if [ -z "${vsix}" ]; then
180-
log notice "Building the vsix package"
181-
yarn package
182-
vsix=$(find . -maxdepth 1 -name '*.vsix')
183-
fi
184-
# shellcheck disable=SC2086
185-
if [ "$(find src -newer ${vsix})" != "" ]; then
186-
log notice "Rebuilding the vsix package (it was outdated)"
187-
yarn package
188-
vsix=$(find . -maxdepth 1 -name '*.vsix')
189-
fi
190-
yarn compile
191-
192-
extest install-vsix -f "${vsix}" -e out/ext -s out/test-resources
193-
fi
194-
extest install-from-marketplace redhat.vscode-yaml ms-python.python -e out/ext -s out/test-resources
195-
196-
export COVERAGE
197-
198-
if [[ "${TEST_TYPE}" == "ui" ]]; then
199-
# shellcheck disable=SC2044
200-
rm -f out/junit/ui/*.* >/dev/null
201-
mkdir -p out/log/ui
202-
203-
find out/client/test/ui/ -name "${UI_TARGET}" -print0 | while IFS= read -r -d '' test_file; do
204-
basename="${test_file##*/}"
205-
TEST_ID="ui-${basename%.*}"
206-
TEST_JUNIT_FILE="./out/junit/ui/${TEST_ID}-test-results.xml"
207-
export TEST_ID
208-
{
209-
log notice "Testing ${test_file}"
210-
log notice "Cleaning existing User settings..."
211-
rm -rfv ./out/test-resources/settings/User/ > /dev/null
212-
213-
if [[ "$MOCK_LIGHTSPEED_API" == "1" ]]; then
214-
stop_server
215-
start_server
216-
fi
217-
refresh_settings "${test_file}" "${TEST_ID}"
218-
timeout --kill-after=15 --preserve-status 150s npm exec -- extest run-tests "${COVERAGE_ARG}" \
219-
--mocha_config test/ui/.mocharc.js \
220-
-s out/test-resources \
221-
-e out/ext \
222-
--code_settings out/settings.json \
223-
-c "${CODE_VERSION}" \
224-
"${test_file}" || {
225-
if [[ -f $TEST_JUNIT_FILE ]] && ! grep -o 'failures="[1-9][0-9]*"' "$TEST_JUNIT_FILE"; then
226-
log warning "Apparently extest got stuck closing after running test ${TEST_ID} but reported success."
227-
else
228-
echo "${TEST_ID}" >> out/log/.failed;
229-
fi
230-
}
231-
if [[ -f ./out/coverage/ui/cobertura-coverage.xml ]]; then
232-
mv ./out/coverage/ui/cobertura-coverage.xml "./out/coverage/ui/${TEST_ID}-cobertura-coverage.xml"
233-
fi
234-
src_dir="out/test-resources/screenshots"
235-
if [ -d "$src_dir" ]; then
236-
shopt -s nullglob
237-
files=("$src_dir"/*.png)
238-
shopt -u nullglob
239-
if [ ${#files[@]} -gt 0 ]; then
240-
mv "${files[@]}" "out/log/"
111+
refresh_settings "${test_file}" "${TEST_ID}"
112+
timeout --kill-after=15 --preserve-status 150s npm exec -- extest run-tests \
113+
--mocha_config test/ui/.mocharc.js \
114+
-s out/test-resources \
115+
-e out/ext \
116+
--code_settings out/settings.json \
117+
-c "${CODE_VERSION}" \
118+
"${EXTEST_ARGS:-}" \
119+
"${test_file}" || {
120+
if [[ -f $TEST_JUNIT_FILE ]] && ! grep -o 'failures="[1-9][0-9]*"' "$TEST_JUNIT_FILE"; then
121+
log warning "Apparently extest got stuck closing after running test ${TEST_ID} but reported success."
122+
else
123+
echo "${TEST_ID}" >> out/log/.failed;
241124
fi
242-
fi
243-
} | tee >(sed -r "s/\x1B\[[0-9;]*[mK]//g" > "out/log/ui/${TEST_ID}.log") 2>&1
244-
done
245-
ls out/junit/ui/*-test-results.xml 1>/dev/null 2>&1 || { echo "No junit reports files reported, failing the build."; exit 1; }
246-
touch out/junit/ui/.passed
247-
fi
125+
}
126+
if [[ -f ./out/coverage/ui/cobertura-coverage.xml ]]; then
127+
mv ./out/coverage/ui/cobertura-coverage.xml "./out/coverage/ui/${TEST_ID}-cobertura-coverage.xml"
128+
fi
129+
} | tee >(sed -r "s/\x1B\[[0-9;]*[mK]//g" > "out/log/${TEST_ID}.log") 2>&1
130+
done
131+
ls out/junit/ui/*-test-results.xml 1>/dev/null 2>&1 || { echo "No junit reports files reported, failing the build."; exit 1; }
132+
touch out/junit/ui/.passed

0 commit comments

Comments
 (0)