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
- Variables
- func Run(node, dir string, env []string, args ...string) ([]byte, error)
- func RunFor(d time.Duration, node, dir string, env []string, args ...string) ([]byte, error)
- func RunTo(d time.Duration, w io.Writer, node, dir string, env []string, args ...string) ([]byte, error)
- func TimedOut(err error) bool
- type DeadlineError
Constants ¶
const ProfileEnv = "BIDE_CHROME_PROFILE"
ProfileEnv is the environment variable that carries the Chrome profile directory to the script.
Variables ¶
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 ¶
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 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.
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.