Help us shape the future of Go! Take the 2026 Go Developer Survey

browsertest

package
v0.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package browsertest runs the Node scripts that drive a page in Chrome for the packages' tests. It is for tests only. A script that stalls (a Chrome that does not start, a page that never settles) would otherwise hold the test until the whole test binary times out, with nothing said about where it stopped: Run gives it a deadline, stops the script and the Chrome it started, and returns what the script had printed, stdout and stderr.

Chrome is not in the script's process group: puppeteer starts it detached. So the run owns the Chrome profile: it makes a fresh directory, hands it to the script in BIDE_CHROME_PROFILE (every script launches with userDataDir: env.BIDE_CHROME_PROFILE), and after the script ends, however it ended, kills every process whose command line names that directory and removes it.

Index

Constants

View Source
const ProfileEnv = "BIDE_CHROME_PROFILE"

ProfileEnv is the environment variable that carries the Chrome profile directory to the script.

Variables

View Source
var Deadline = 5 * time.Minute

Deadline is how long a script may run. A script under a loaded machine takes up to four times its usual few seconds; five minutes is far past that and well short of the test binary's timeout.

Functions

func Run

func Run(node, dir string, env []string, args ...string) ([]byte, error)

Run runs node with args in dir, with env added to the environment of the test, and returns its standard output. When the script outlives Deadline it is stopped (see RunTo) and the error is a *DeadlineError quoting the tail of what the script wrote.

func RunFor

func RunFor(d time.Duration, node, dir string, env []string, args ...string) ([]byte, error)

RunFor is Run with a deadline given.

func RunTo

func RunTo(d time.Duration, w io.Writer, node, dir string, env []string, args ...string) ([]byte, error)

RunTo is RunFor that also copies the script's standard error to w as it is written (nil: not copied), for a script whose progress a person watches; the error of a failed run still quotes its tail.

At the deadline the script's process group gets SIGTERM, which puppeteer answers by closing Chrome; two seconds later the group is killed. A script whose event loop is stuck cannot answer, which is the usual way to stall, so the second layer does not depend on it: whatever the script did, every process whose command line holds the run's profile directory is killed, and the directory removed.

func TimedOut

func TimedOut(err error) bool

TimedOut reports whether err is a script stopped at its deadline. A caller that fails on it should report it first: a script cut off has printed no result, and "no result" is the consequence.

Types

type DeadlineError

type DeadlineError struct {
	Script   string
	Deadline time.Duration
	Stderr   string // the tail of what it wrote to standard error
	Stdout   string // the tail of what it wrote to standard output
	Profile  string // the Chrome profile directory the run owned
}

DeadlineError is a script that was still running at its deadline and was stopped.

func (*DeadlineError) Error

func (e *DeadlineError) Error() string

Error says which script was stopped, after how long, in which Chrome profile, and what it had written.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL