Skip to content

Commit

Permalink
test: use test-ui.sh to run the tests
Browse files Browse the repository at this point in the history
Use one single script called `./tools/test-ui.sh` to trigger all the
different UI tests:

- `COVERAGE=1` or `-c` to enable the code coverage
- `COVE_VERSION` to set the vscode-extension-tester parameter (e.g `max` or `min`)
- `MOCK_LIGHTSPEED_API` (`1` or ``): set it to `1` to dynamically start the mocked server and set `TEST_LIGHTSPEED_URL`
  • Loading branch information
goneri committed Nov 7, 2024
1 parent b54e651 commit def053d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 58 deletions.
4 changes: 4 additions & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ABRT
Ansible
Anson
CFLAGS
Expand All @@ -15,6 +16,7 @@ Jenkinsfile
Launay
Maciążek
Nalawade
OPTSTRING
OSTYPE
Ondrej
PYTHONBREAKPOINT
Expand All @@ -31,6 +33,7 @@ TLDR
Taskfile
Testenvs
Tomasz
WITHTEST
WSLENV
Webviews
YOLO
Expand Down Expand Up @@ -180,6 +183,7 @@ pgrep
piptools
pipx
pkgcache
pkill
podman
precheck
preid
Expand Down
22 changes: 0 additions & 22 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,6 @@ jobs:
SKIP_DOCKER: ${{ matrix.env.SKIP_DOCKER || 0 }}
SKIP_PODMAN: ${{ matrix.env.SKIP_PODMAN || 0 }}
TASKFILE_ARGS: --output=group --output-group-begin='::group::{{.TASK}}' --output-group-end='::endgroup::'
# For using the mock Lightspeed server.
TEST_LIGHTSPEED_ACCESS_TOKEN: "dummy"
# The mock server runs on localhost. However, just using "localhost" as the hostname causes a few issues in
# GitHub Actions environment:
#
# On Linux: When "localhost" is used as the hostname, the mock server uses the ipv6 loopback address [::1] . However,
# the axios library, which is used in the extension tries to access to the ipv4 loopback 127.0.0.1 when "localhost"
# is specified and the axios library does not support URLs that contains ipv6 addresses, e.g. http://[::1]:3000.
# Also, If 127.0.0.1 is specified for the mock server, the server fails to start. Those issues are resolved by
# using the special ipv6-only hostname "ip6-localhost", which is available in GitHub Actions Linux environment.
#
# On MacOS: The hostname "ip6-localhost" is not available. However, 127.0.0.1 can be used for starting the mock
# server on MacOS and the axios library can connect to that address. So we can use 127.0.0.1 for MacOS.
#
# Once the axios library starts supporting URLs that contain ipv6 addresses, we will be able to use
# http://[::1]:3000 both on Linux and MacOS to get rid of the following conditional statement.
TEST_LIGHTSPEED_URL: "${{ contains(matrix.name, 'macos') && 'http://127.0.0.1:3000' || 'http://ip6-localhost:3000' }}"

# Set environment variables using matrix properties.
# For using an actual Lightspeed server instance, uncomment following two lines.
# TEST_LIGHTSPEED_ACCESS_TOKEN: ${{ secrets.TEST_LIGHTSPEED_ACCESS_TOKEN }}
# TEST_LIGHTSPEED_URL: ${{ secrets.TEST_LIGHTSPEED_URL }}

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ tasks:
- yarn webpack-dev
- "{{.VIRTUAL_ENV}}/bin/python3 --version"
- bash -c 'rm -rf ./out/test-resources ./out/ext'
- ' {{.XVFB}} bash -c ''source "{{.VIRTUAL_ENV}}/bin/activate" && yarn _coverage-ui-with-mock-lightspeed-server'''
- ' {{.XVFB}} bash -c ''source "{{.VIRTUAL_ENV}}/bin/activate" && COVERAGE=1 MOCK_LIGHTSPEED_API=1 ./tools/test-ui.sh'''
interactive: true
test-unit:
desc: Run unit tests with coverage report
Expand Down
17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1022,15 +1022,12 @@
"pretest": "yarn run compile",
"unit-tests": "sh -c \"nyc mocha --recursive test/units/lightspeed ${MOCHA_OPTS:-}\"",
"test-ui": "yarn run test-ui-current && yarn run test-ui-oldest",
"_test-ui": "extest get-vscode -c ${CODE_VERSION} -s out/test-resources && extest get-chromedriver -c ${CODE_VERSION} -s out/test-resources && extest install-vsix -f ansible-*.vsix -e out/ext -s out/test-resources && extest install-from-marketplace redhat.vscode-yaml ms-python.python -e out/ext -s out/test-resources && extest run-tests -s out/test-resources -e out/ext --code_settings test/testFixtures/settings.json out/client/test/ui-test/allTestsSuite.js",
"test-ui-current": "CODE_VERSION='max' yarn _test-ui",
"test-ui-oldest": "CODE_VERSION='min' yarn _test-ui",
"test-ui-with-mock-lightspeed-server": "TEST_LIGHTSPEED_URL='http://127.0.0.1:3000' ./tools/run-ui-test-with-mock-lightspeed-server.sh",
"_coverage-ui": "extest get-vscode -c ${CODE_VERSION} -s out/test-resources && extest get-chromedriver -c ${CODE_VERSION} -s out/test-resources && extest install-from-marketplace redhat.vscode-yaml ms-python.python -e out/ext -s out/test-resources && extest run-tests --coverage -s out/test-resources -e out/ext --code_settings test/testFixtures/settings.json out/client/test/ui-test/allTestsSuite.js",
"coverage-ui-current": "COVERAGE=1 CODE_VERSION='max' yarn _coverage-ui",
"coverage-ui-oldest": "COVERAGE=1 CODE_VERSION='min' yarn _coverage-ui",
"_coverage-ui-with-mock-lightspeed-server": "./tools/run-ui-test-with-mock-lightspeed-server.sh --coverage",
"coverage-ui-with-mock-lightspeed-server": "TEST_LIGHTSPEED_URL='http://127.0.0.1:3000' yarn _coverage-ui-with-mock-lightspeed-server",
"test-ui-current": "CODE_VERSION='max' ./tools/test-ui.sh",
"test-ui-oldest": "CODE_VERSION='min' ./tools/test-ui.sh",
"test-ui-with-mock-lightspeed-server": "MOCK_LIGHTSPEED_API=1 ./tools/test-ui.sh",
"coverage-ui-current": "COVERAGE=1 CODE_VERSION='max' ./tools/test-ui.sh",
"coverage-ui-oldest": "COVERAGE=1 CODE_VERSION='min' ./tools/test-ui.sh",
"coverage-ui-with-mock-lightspeed-server": "COVERAGE=1 MOCK_LIGHTSPEED_API=1 ./tools/test-ui.sh",
"vscode-prepublish": "yarn run webpack",
"watch": "tsc -b -w",
"watch-server": "tsc -p ../ansible-language-server --outDir out/server -w",
Expand All @@ -1041,8 +1038,6 @@
"test-compile": "yarn run clean && yarn run compile && tsc -p ./ --sourceMap",
"test-e2e": "yarn run test-compile && node ./out/client/test/testRunner",
"coverage-e2e": "COVERAGE=1 yarn run test-e2e",
"mock-lightspeed-server": "DEBUG='express:*' node ./out/client/test/mockLightspeedServer/server.js >>out/log/express.log 2>&1",
"kill-mock-lightspeed-server": "pkill -f mockLightspeedServer/server.js",
"_coverage-all": "./tools/coverage-all.sh",
"coverage-all": "TEST_LIGHTSPEED_URL='http://127.0.0.1:3000' yarn _coverage-all",
"als-compile": "yarn workspace @ansible/ansible-language-server compile"
Expand Down
24 changes: 0 additions & 24 deletions tools/run-ui-test-with-mock-lightspeed-server.sh

This file was deleted.

71 changes: 71 additions & 0 deletions tools/test-ui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env sh

set -eux
set -o pipefail

cleanup()
{
pkill -P $$
wait
}

trap "cleanup" HUP INT ABRT BUS TERM EXIT


CODE_VERSION="${CODE_VERSION:-max}"
TEST_LIGHTSPEED_URL="${TEST_LIGHTSPEED_URL:-}"
COVERAGE="${COVERAGE:-}"
EXTEST=./node_modules/.bin/extest
START_SERVER_WITHTEST="npx start-server-and-test"
MOCK_LIGHTSPEED_API="${MOCK_LIGHTSPEED_API:-}"



OPTSTRING=":c"

while getopts ${OPTSTRING} opt; do
case ${opt} in
c)
echo "Coverage enabled"
COVERAGE="1"
;;
?)
echo "Invalid option: -${OPTARG}."
exit 1
;;
esac
done

if [[ -n $COVERAGE ]]; then
COVERAGE_ARG="--coverage"
fi




if [[ "$MOCK_LIGHTSPEED_API" != "" ]]; then
if [[ -n "${TEST_LIGHTSPEED_URL}" ]]; then
echo "the existing TEST_LIGHTSPEED_URL envvar will be ignored!"
fi
mkdir -p out/log
TEST_LIGHTSPEED_ACCESS_TOKEN=dummy
(DEBUG='express:*' node ./out/client/test/mockLightspeedServer/server.js >>out/log/express.log 2>&1 ) &
sleep 5
TEST_LIGHTSPEED_URL=$(sed -n 's,.*Listening on port \([0-9]\+\) at \([.0-9]\+\).*,http://\2:\1,p' out/log/express.log|tail -n1)
fi


# Start the mock Lightspeed server and run UI tests with the new VS Code

${EXTEST} get-vscode -c "${CODE_VERSION}" -s out/test-resources
${EXTEST} get-chromedriver -c "${CODE_VERSION}" -s out/test-resources
if [[ "$COVERAGE" == "" ]]; then
${EXTEST} install-vsix -f ansible-*.vsix -e out/ext -s out/test-resources
fi
${EXTEST} install-from-marketplace redhat.vscode-yaml ms-python.python -e out/ext -s out/test-resources


export TEST_LIGHTSPEED_URL
export TEST_LIGHTSPEED_ACCESS_TOKEN

${EXTEST} run-tests "${COVERAGE_ARG}" -s out/test-resources -e out/ext --code_settings test/testFixtures/settings.json out/client/test/ui-test/allTestsSuite.js

0 comments on commit def053d

Please sign in to comment.