Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to k6 lookupEnv and abstract env. var. lookup #918

Merged
merged 28 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0d39d40
Rename RootModule.once to initOnce for clarity
inancgumus Jun 1, 2023
42fc913
Move RootModule init to a function
inancgumus Jun 2, 2023
cd861d7
Move debug server to NewModuleInstance
inancgumus Jun 2, 2023
cd85bb2
Fix abort if remote registry fails to register
inancgumus Jun 2, 2023
27c97e2
Add empty LookupEnv field to module test
inancgumus Jun 2, 2023
97d5c3a
Add LookupEnv to k6test.NewVU
inancgumus Jun 1, 2023
63bc0ec
Refactor NewBrowserType slightly
inancgumus Jun 2, 2023
bdb8727
Use k6 lookup in BrowserType and RootModule.init
inancgumus Jun 2, 2023
6d8dd09
Add withLookupFunc to testBrowser
inancgumus Jun 2, 2023
2049cad
Use env.LookupEnv in RootModule.initialize
inancgumus Jun 2, 2023
8871fbd
Remove SetEnvLookupper from BrowserType
inancgumus Jun 2, 2023
bb78b8a
Remove testBrowser.withBrowserOptions
inancgumus Jun 2, 2023
c784100
Remove testBrowser.setupEnvLookupper
inancgumus Jun 2, 2023
11f39a9
Remove browserOptions from tests
inancgumus Jun 2, 2023
34d2c16
Add testingT helper to test for failing tests
inancgumus Jun 2, 2023
6259634
Add TestTestBrowserWithLookupFunc
inancgumus Jun 2, 2023
30161e6
Use TMPDIR from k6 LookupEnv in BrowserType
inancgumus Jun 1, 2023
cb6572f
Use LookupEnv for USERPROFILE in ExecutablePath
inancgumus Jun 1, 2023
ad4ec6f
Use LookupEnv in makeLogger
inancgumus Jun 1, 2023
73b0199
Refactor TestIsRemoteBrowser
inancgumus Jun 1, 2023
a46ed22
Remove the old relic SKIP_FLAKKY
inancgumus Jun 1, 2023
ad81e72
Remove setenv from TestIsRemoteBrowser
inancgumus Jun 1, 2023
6825710
Refactor env.var. names to constants
inancgumus Jun 1, 2023
d2cc3c9
Add environment lookup func helpers
inancgumus Jun 1, 2023
e5fbe42
Remove unnecessary withLookup types
inancgumus Jun 1, 2023
1207e02
Update Dockerfile to use K6_BROWSER_HEADLESS
inancgumus Jun 2, 2023
6ffa156
Update workflows to use K6_BROWSER_HEADLESS
inancgumus Jun 2, 2023
3edd61b
Remove default env lookup from test browser
inancgumus Jun 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion chromium/browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ func (b *BrowserType) launch(
if err != nil {
return nil, 0, fmt.Errorf("%w", err)
}

dataDir := &storage.Dir{}
if err := dataDir.Make("", flags["user-data-dir"]); err != nil {
if err := dataDir.Make(b.tmpdir(), flags["user-data-dir"]); err != nil {
inancgumus marked this conversation as resolved.
Show resolved Hide resolved
return nil, 0, fmt.Errorf("%w", err)
}
flags["user-data-dir"] = dataDir.Dir
Expand Down Expand Up @@ -217,6 +218,14 @@ func (b *BrowserType) launch(
return browser, browserProc.Pid(), nil
}

// tmpdir returns the temporary directory to use for the browser.
// It returns the value of the TMPDIR environment variable if set,
// otherwise it returns an empty string.
func (b *BrowserType) tmpdir() string {
dir, _ := b.envLookupper("TMPDIR")
return dir
}

// LaunchPersistentContext launches the browser with persistent storage.
func (b *BrowserType) LaunchPersistentContext(userDataDir string, opts goja.Value) api.Browser {
rt := b.vu.Runtime()
Expand Down
17 changes: 9 additions & 8 deletions tests/browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ func TestBrowserNewPage(t *testing.T) {
}

func TestTmpDirCleanup(t *testing.T) {
t.Parallel()

tmpDirPath := "./"

err := os.Setenv("TMPDIR", tmpDirPath)
assert.NoError(t, err)
defer func() {
err = os.Unsetenv("TMPDIR")
assert.NoError(t, err)
}()
b := newTestBrowser(t, withSkipClose(), withLookupFunc(func(k string) (string, bool) {
if k == "TMPDIR" {
return tmpDirPath, true
}
return "", false
}))

b := newTestBrowser(t, withSkipClose())
p := b.NewPage(nil)
err = p.Close(nil)
err := p.Close(nil)
require.NoError(t, err)

matches, err := filepath.Glob(tmpDirPath + "xk6-browser-data-*")
Expand Down