diff --git a/browser/module.go b/browser/module.go index 8ab1cfe8f..821fa06ac 100644 --- a/browser/module.go +++ b/browser/module.go @@ -38,6 +38,7 @@ type ( initOnce *sync.Once tracesMetadata map[string]string filePersister filePersister + testRunID string } // JSModule exposes the properties available to the JS script. @@ -91,6 +92,7 @@ func (m *RootModule) NewModuleInstance(vu k6modules.VU) k6modules.Instance { ), taskQueueRegistry: newTaskQueueRegistry(vu), filePersister: m.filePersister, + testRunID: m.testRunID, }), Devices: common.GetDevices(), NetworkProfiles: common.GetNetworkProfiles(), @@ -126,6 +128,9 @@ func (m *RootModule) initialize(vu k6modules.VU) { if err != nil { k6ext.Abort(vu.Context(), "failed to create file persister: %v", err) } + if e, ok := initEnv.LookupEnv(env.K6TestRunID); ok && e != "" { + m.testRunID = e + } } func startDebugServer() { diff --git a/browser/modulevu.go b/browser/modulevu.go index 64ae87324..ea6597985 100644 --- a/browser/modulevu.go +++ b/browser/modulevu.go @@ -22,6 +22,8 @@ type moduleVU struct { *taskQueueRegistry filePersister + + testRunID string } // browser returns the VU browser instance for the current iteration. diff --git a/env/env.go b/env/env.go index 5f523fa41..401673dfb 100644 --- a/env/env.go +++ b/env/env.go @@ -81,6 +81,13 @@ const ( ScreenshotsOutput = "K6_BROWSER_SCREENSHOTS_OUTPUT" ) +// Infrastructural. +const ( + // K6TestRunID represents the test run id. Note: this was taken from + // k6. + K6TestRunID = "K6_CLOUD_PUSH_REF_ID" +) + // LookupFunc defines a function to look up a key from the environment. type LookupFunc func(key string) (string, bool)