Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit abcfa44

Browse files
committed
Add an env var to disable test runs
This flag can stop tests runs that shouldn't occur, along with another messaging env var that override the default messaging. We're not using os.Exit to exit the process as that will prevent k6 from shutting down cleanly. Instead we throw an error that k6 can work with and cleanly shut itself down, also allowing it to write an appropriate exit code the other systems can understand and work with. Note that this this throw needs to be done in NewModuleInstance. Closes: #664
1 parent aa0b43d commit abcfa44

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

browser/module.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
package browser
33

44
import (
5+
"errors"
6+
"os"
7+
58
"github.com/grafana/xk6-browser/api"
69
"github.com/grafana/xk6-browser/chromium"
710
"github.com/grafana/xk6-browser/common"
811

12+
k6common "go.k6.io/k6/js/common"
913
k6modules "go.k6.io/k6/js/modules"
1014
)
1115

@@ -42,6 +46,15 @@ func New() *RootModule {
4246
// NewModuleInstance implements the k6modules.Module interface to return
4347
// a new instance for each VU.
4448
func (*RootModule) NewModuleInstance(vu k6modules.VU) k6modules.Instance {
49+
if _, ok := os.LookupEnv("K6_BROWSER_DISABLE_RUN"); ok {
50+
msg := "Disable run flag enabled, browser test run aborted. Please contact support."
51+
if m, ok := os.LookupEnv("K6_BROWSER_DISABLE_RUN_MSG"); ok {
52+
msg = m
53+
}
54+
55+
k6common.Throw(vu.Runtime(), errors.New(msg))
56+
}
57+
4558
return &ModuleInstance{
4659
mod: &JSModule{
4760
Chromium: chromium.NewBrowserType(vu),

0 commit comments

Comments
 (0)