11#! /usr/bin/env bash
22# cspell: ignore nullglob
33export DONT_PROMPT_WSL_INSTALL=1
4- set -eu
5- yarn run compile
6- set -o pipefail
4+ set -euo pipefail
75
86DIR=" $( 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
1317cleanup ()
1418{
@@ -38,20 +42,6 @@ cleanup()
3842trap " cleanup OTHER" HUP INT ABRT BUS TERM
3943trap " 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-
5545function 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-
11678function 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