diff --git a/.envrc b/.envrc index 384c50d8a..ad5949970 100644 --- a/.envrc +++ b/.envrc @@ -9,6 +9,17 @@ export HOSTNAME="${HOSTNAME:-${HOST:-$(hostname)}}" # for build and testing purposes. export VIRTUAL_ENV="${HOME}/.local/share/virtualenvs/vsa" +# determine which TEST_LIGHTSPEED_URL value to use, as on macos we need a +# different value than on linux due to how ipv4/ipv6 hostnames are resolved. + +if [[ "$OSTYPE" == "darwin"* ]]; then + TEST_LIGHTSPEED_URL='http://127.0.0.1:3000' +else + TEST_LIGHTSPEED_URL='http://ip6-localhost:3000' +fi +export TEST_LIGHTSPEED_URL + + # Activate virtualenv (creates it if needed) layout python source_up 2>/dev/null || true diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b01b9bc77..4889ba695 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -237,7 +237,7 @@ jobs: # # 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' }}" + # TEST_LIGHTSPEED_URL: "${{ contains(matrix.name, 'macos') && 'http://127.0.0.1:3000' || 'http://ip6-localhost:3000' }}" # Set environment variables using matrix properties. SKIP_PODMAN: "${{ matrix.env.SKIP_PODMAN || '0' }}" diff --git a/package.json b/package.json index aee4a9d84..ef431c1d4 100644 --- a/package.json +++ b/package.json @@ -839,7 +839,7 @@ "_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", + "test-ui-with-mock-lightspeed-server": "./tools/run-ui-test-with-mock-lightspeed-server.sh", "vscode-prepublish": "yarn run webpack", "watch": "tsc -b -w", "watch-server": "tsc -p ../ansible-language-server --outDir out/server -w", @@ -853,10 +853,10 @@ "coverage-e2e": "COVERAGE=1 yarn run test-e2e", "test-e2e-withserver": "yarn run test-compile-withserver && node ./out/client/test/testRunner", "coverage-e2e-withserver": "COVERAGE=1 yarn run test-e2e-withserver", - "mock-lightspeed-server": "DEBUG='express:*' node ./out/client/test/mockLightspeedServer/server.js", + "mock-lightspeed-server": "node ./out/client/test/mockLightspeedServer/server.js", "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", + "coverage-all": "yarn _coverage-all", "als-compile": "yarn workspace @ansible/ansible-language-server compile" }, "version": "24.4.0", diff --git a/test/helper.ts b/test/helper.ts index 43d8881a2..a0b316c8d 100644 --- a/test/helper.ts +++ b/test/helper.ts @@ -157,13 +157,6 @@ export async function canRunLightspeedTests(): Promise { return false; } - if (!process.env.TEST_LIGHTSPEED_URL) { - console.warn( - "Skipping lightspeed tests because TEST_LIGHTSPEED_URL variable is not set.", - ); - return false; - } - // next, check if the access token is valid or not const lightspeedBaseURL: string | undefined = vscode.workspace .getConfiguration("ansible") diff --git a/test/mockLightspeedServer/server.ts b/test/mockLightspeedServer/server.ts index 4a6290206..94869febd 100644 --- a/test/mockLightspeedServer/server.ts +++ b/test/mockLightspeedServer/server.ts @@ -12,9 +12,12 @@ import { openUrl } from "./openUrl"; const API_VERSION = "v0"; const API_ROOT = `/api/${API_VERSION}`; -let url = new URL("http://127.0.0.1:3000"); -// Do not try to use envvars on macos -- ref: https://github.com/microsoft/vscode/issues/204005 -if (process.platform !== "darwin" && process.env.TEST_LIGHTSPEED_URL) { +let url = new URL( + process.platform === "darwin" + ? "http://127.0.0.1:3000" + : "http://ip6-localhost:3000", +); +if (process.env.TEST_LIGHTSPEED_URL) { url = new URL(process.env.TEST_LIGHTSPEED_URL); } diff --git a/tools/coverage-all.sh b/tools/coverage-all.sh index a977c667d..d0a337208 100755 --- a/tools/coverage-all.sh +++ b/tools/coverage-all.sh @@ -1,13 +1,7 @@ #!/bin/bash -# If TEST_LIGHTSPEED_URL is not defined, set a URL with the ipv6 callback hostname, -# which is available in the GitHub Actions Linux environment. -if [[ -z "${TEST_LIGHTSPEED_URL}" ]]; then - TEST_LIGHTSPEED_URL="http://ip6-localhost:3000" -fi - # Start the mock Lightspeed server and run e2e tests with code coverage enabled. npx start-server-and-test \ - "TEST_LIGHTSPEED_URL=${TEST_LIGHTSPEED_URL} yarn mock-lightspeed-server" \ + "yarn mock-lightspeed-server" \ "${TEST_LIGHTSPEED_URL}" \ - "TEST_LIGHTSPEED_ACCESS_TOKEN=dummy TEST_LIGHTSPEED_URL=${TEST_LIGHTSPEED_URL} yarn coverage-e2e" + "TEST_LIGHTSPEED_ACCESS_TOKEN=dummy yarn coverage-e2e" diff --git a/tools/run-ui-test-with-mock-lightspeed-server.sh b/tools/run-ui-test-with-mock-lightspeed-server.sh index d495d5d7d..324e9ce6a 100755 --- a/tools/run-ui-test-with-mock-lightspeed-server.sh +++ b/tools/run-ui-test-with-mock-lightspeed-server.sh @@ -1,13 +1,7 @@ #!/bin/bash -# If TEST_LIGHTSPEED_URL is not defined, set a URL with the ipv6 callback hostname, -# which is available in the GitHub Actions Linux environment. -if [[ -z "${TEST_LIGHTSPEED_URL}" ]]; then - TEST_LIGHTSPEED_URL="http://ip6-localhost:3000" -fi - # Start the mock Lightspeed server and run UI tests with the new VS Code npx start-server-and-test \ - "TEST_LIGHTSPEED_URL=${TEST_LIGHTSPEED_URL} yarn mock-lightspeed-server" \ + "yarn mock-lightspeed-server" \ "${TEST_LIGHTSPEED_URL}" \ - "TEST_LIGHTSPEED_ACCESS_TOKEN=dummy TEST_LIGHTSPEED_URL=${TEST_LIGHTSPEED_URL} yarn test-ui-current" + "TEST_LIGHTSPEED_ACCESS_TOKEN=dummy yarn test-ui-current"