diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml new file mode 100644 index 00000000000..2bfd4915a5b --- /dev/null +++ b/.github/workflows/test-browser.yml @@ -0,0 +1,83 @@ +name: Browser Tests +on: + push: + branches: + - master + pull_request: + +defaults: + run: + shell: bash + +jobs: + test-prev: + strategy: + fail-fast: false + matrix: + go-version: [1.22.x, 1.23.x] + platform: [ubuntu-latest] + runs-on: ${{ matrix.platform }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get the k6 version + id: get_k6_version + run: | + echo "Running tests on '${GITHUB_REF}' with '$(git describe --tags --always --long --dirty)' checked out..." + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + check-latest: true + - name: Run tests + run: | + set -x + go version + export GOMAXPROCS=2 + args=("-p" "2" "-race") + # Run with less concurrency on Windows/MacOS to minimize flakiness. + if [[ "${{ matrix.platform }}" == windows* || "${{ matrix.platform }}" == macos* ]]; then + unset args[2] + args[1]="1" + export GOMAXPROCS=1 + fi + K6_BROWSER_EXECUTABLE_PATH=/usr/bin/google-chrome K6_BROWSER_HEADLESS=true go test "${args[@]}" -timeout 800s -tags=browser_tests go.k6.io/k6/js/modules/k6/browser/tests + + test-tip: + strategy: + fail-fast: false + matrix: + platform: [ubuntu-latest] + runs-on: ${{ matrix.platform }} + continue-on-error: true + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Download Go tip + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release download ${{ matrix.platform }} --repo grafana/gotip --pattern 'go.zip' + - name: Install Go tip + run: | + unzip go.zip -d $HOME/sdk + echo "GOROOT=$HOME/sdk/gotip" >> "$GITHUB_ENV" + echo "GOPATH=$HOME/go" >> "$GITHUB_ENV" + echo "$HOME/go/bin" >> "$GITHUB_PATH" + echo "$HOME/sdk/gotip/bin" >> "$GITHUB_PATH" + - name: Run tests + run: | + set -x + which go + go version + export GOMAXPROCS=2 + args=("-p" "2" "-race") + # Run with less concurrency on Windows/MacOS to minimize flakiness. + if [[ "${{ matrix.platform }}" == windows* || "${{ matrix.platform }}" == macos* ]]; then + unset args[2] + args[1]="1" + export GOMAXPROCS=1 + fi + K6_BROWSER_EXECUTABLE_PATH=/usr/bin/google-chrome K6_BROWSER_HEADLESS=true go test "${args[@]}" -timeout 800s -tags=browser_tests go.k6.io/k6/js/modules/k6/browser/tests diff --git a/Makefile b/Makefile index e9f117a25f0..bea5f4b3ef9 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,10 @@ lint: check-linter-version tests: go test -race -timeout 210s ./... +## test: Executes browser tests. +browser-tests: + go test -race -timeout 120s ./... -tags=browser_tests + ## check: Runs the linters and tests. check: lint tests diff --git a/js/modules/k6/browser/tests/browser_context_options_test.go b/js/modules/k6/browser/tests/browser_context_options_test.go index 5b8814f80dc..6075a8ed225 100644 --- a/js/modules/k6/browser/tests/browser_context_options_test.go +++ b/js/modules/k6/browser/tests/browser_context_options_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/browser_context_test.go b/js/modules/k6/browser/tests/browser_context_test.go index 3779e959b00..e1847f6246d 100644 --- a/js/modules/k6/browser/tests/browser_context_test.go +++ b/js/modules/k6/browser/tests/browser_context_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/browser_test.go b/js/modules/k6/browser/tests/browser_test.go index 8503e10ecca..61245b8b083 100644 --- a/js/modules/k6/browser/tests/browser_test.go +++ b/js/modules/k6/browser/tests/browser_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/browser_type_test.go b/js/modules/k6/browser/tests/browser_type_test.go index 67907e1b10b..a88c07db8a4 100644 --- a/js/modules/k6/browser/tests/browser_type_test.go +++ b/js/modules/k6/browser/tests/browser_type_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/doc.go b/js/modules/k6/browser/tests/doc.go index 6abb9ccc8c7..75b85ce7618 100644 --- a/js/modules/k6/browser/tests/doc.go +++ b/js/modules/k6/browser/tests/doc.go @@ -1,3 +1,5 @@ +//go:build browser_tests + // Package tests provides integration tests. // The `testBrowser` type enables us to test the browser module with a real browser. package tests diff --git a/js/modules/k6/browser/tests/element_handle_test.go b/js/modules/k6/browser/tests/element_handle_test.go index 1f52583d0d8..7fa7ad4dc39 100644 --- a/js/modules/k6/browser/tests/element_handle_test.go +++ b/js/modules/k6/browser/tests/element_handle_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/frame_manager_test.go b/js/modules/k6/browser/tests/frame_manager_test.go index 7f1ff5a6df2..7148c92a4a4 100644 --- a/js/modules/k6/browser/tests/frame_manager_test.go +++ b/js/modules/k6/browser/tests/frame_manager_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/frame_test.go b/js/modules/k6/browser/tests/frame_test.go index 5cc0fe388e3..a0dbb932569 100644 --- a/js/modules/k6/browser/tests/frame_test.go +++ b/js/modules/k6/browser/tests/frame_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/helpers.go b/js/modules/k6/browser/tests/helpers.go index 5e73a2451d7..4834253d79a 100644 --- a/js/modules/k6/browser/tests/helpers.go +++ b/js/modules/k6/browser/tests/helpers.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/js_handle_get_properties_test.go b/js/modules/k6/browser/tests/js_handle_get_properties_test.go index 59355640460..f854aed7f4d 100644 --- a/js/modules/k6/browser/tests/js_handle_get_properties_test.go +++ b/js/modules/k6/browser/tests/js_handle_get_properties_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/js_handle_test.go b/js/modules/k6/browser/tests/js_handle_test.go index 7b1bb33e3b6..8024f3ed978 100644 --- a/js/modules/k6/browser/tests/js_handle_test.go +++ b/js/modules/k6/browser/tests/js_handle_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/keyboard_test.go b/js/modules/k6/browser/tests/keyboard_test.go index 091892438f6..6b3ab0e8250 100644 --- a/js/modules/k6/browser/tests/keyboard_test.go +++ b/js/modules/k6/browser/tests/keyboard_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/launch_options_slowmo_test.go b/js/modules/k6/browser/tests/launch_options_slowmo_test.go index 190763b6c4c..e62f66d3d3d 100644 --- a/js/modules/k6/browser/tests/launch_options_slowmo_test.go +++ b/js/modules/k6/browser/tests/launch_options_slowmo_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/lifecycle_wait_test.go b/js/modules/k6/browser/tests/lifecycle_wait_test.go index feae7ccef82..3a373caadb8 100644 --- a/js/modules/k6/browser/tests/lifecycle_wait_test.go +++ b/js/modules/k6/browser/tests/lifecycle_wait_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/locator_test.go b/js/modules/k6/browser/tests/locator_test.go index 168976a204b..f9d5c38993d 100644 --- a/js/modules/k6/browser/tests/locator_test.go +++ b/js/modules/k6/browser/tests/locator_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/logrus_hook.go b/js/modules/k6/browser/tests/logrus_hook.go index a56fdc49ecf..6b8e4ca55d0 100644 --- a/js/modules/k6/browser/tests/logrus_hook.go +++ b/js/modules/k6/browser/tests/logrus_hook.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/mouse_test.go b/js/modules/k6/browser/tests/mouse_test.go index e2b11373e64..6c61cd5efad 100644 --- a/js/modules/k6/browser/tests/mouse_test.go +++ b/js/modules/k6/browser/tests/mouse_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/network_manager_test.go b/js/modules/k6/browser/tests/network_manager_test.go index 44463e9ecbb..f6051cee14b 100644 --- a/js/modules/k6/browser/tests/network_manager_test.go +++ b/js/modules/k6/browser/tests/network_manager_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/page_test.go b/js/modules/k6/browser/tests/page_test.go index aa6ebc342f4..44607378fec 100644 --- a/js/modules/k6/browser/tests/page_test.go +++ b/js/modules/k6/browser/tests/page_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( @@ -2135,7 +2137,7 @@ func TestPageOnMetric(t *testing.T) { const page = await browser.newPage() %s - + await page.goto('%s', {waitUntil: 'networkidle'}); await page.close() diff --git a/js/modules/k6/browser/tests/remote_obj_test.go b/js/modules/k6/browser/tests/remote_obj_test.go index 4f28e7e7790..a25cfa7ea0c 100644 --- a/js/modules/k6/browser/tests/remote_obj_test.go +++ b/js/modules/k6/browser/tests/remote_obj_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/setinputfiles_test.go b/js/modules/k6/browser/tests/setinputfiles_test.go index 2691cab92c8..b9f489d947e 100644 --- a/js/modules/k6/browser/tests/setinputfiles_test.go +++ b/js/modules/k6/browser/tests/setinputfiles_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/test_browser.go b/js/modules/k6/browser/tests/test_browser.go index ee3946d733d..4a13d504ca0 100644 --- a/js/modules/k6/browser/tests/test_browser.go +++ b/js/modules/k6/browser/tests/test_browser.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/test_browser_proxy.go b/js/modules/k6/browser/tests/test_browser_proxy.go index 1e170e84588..a5fea2e1b45 100644 --- a/js/modules/k6/browser/tests/test_browser_proxy.go +++ b/js/modules/k6/browser/tests/test_browser_proxy.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/test_browser_test.go b/js/modules/k6/browser/tests/test_browser_test.go index 53cfabd749d..616f60f51c3 100644 --- a/js/modules/k6/browser/tests/test_browser_test.go +++ b/js/modules/k6/browser/tests/test_browser_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/tracing_test.go b/js/modules/k6/browser/tests/tracing_test.go index eccbbab6fef..fbcdfa1e18a 100644 --- a/js/modules/k6/browser/tests/tracing_test.go +++ b/js/modules/k6/browser/tests/tracing_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import ( diff --git a/js/modules/k6/browser/tests/webvital_test.go b/js/modules/k6/browser/tests/webvital_test.go index 08bb63e03a1..1ebbfa97440 100644 --- a/js/modules/k6/browser/tests/webvital_test.go +++ b/js/modules/k6/browser/tests/webvital_test.go @@ -1,3 +1,5 @@ +//go:build browser_tests + package tests import (