testrun

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Suites = map[string]Suite{
	"main": {
		Name:      "main",
		Globs:     []string{"test/tests/**/*.js"},
		TimeoutMS: 2000,
		// contains filtered or unexported fields
	},
}

Suites are the browser suites of the repository. The "e2e" suite is not here: it drives the example app, see internal/e2e.

Functions

func Command

func Command() cli.Command

Command is the "test" subcommand.

func Discover

func Discover(root string, globs []string) ([]string, error)

Discover lists the files below root (as slash separated paths relative to root) that match any of the globs, sorted. node_modules and .git are skipped.

func Run

func Run(ctx context.Context, o Options) int

Run executes the suite in every requested browser and returns the exit code: 0 when every test passed in every browser that ran, 1 when a test failed or nothing could run.

func Serve

func Serve(ctx context.Context, root string, suite Suite, port int, dist bool, out, errw io.Writer) int

Serve serves the repository root until ctx ends. Pages are at http://localhost:PORT/<path>, for example /test/manual/sse.html.

func SuiteNames

func SuiteNames() []string

SuiteNames lists the names of the browser suites plus the e2e suite.

Types

type BrowserReport

type BrowserReport struct {
	Browser     string
	Label       string
	Unavailable *browsers.Unavailable
	Files       []FileReport
	Duration    time.Duration
}

BrowserReport is the outcome of a suite in one browser.

func (BrowserReport) Totals

func (b BrowserReport) Totals() (files, passed, failed, skipped int)

Totals of a browser report.

type ErrInfo

type ErrInfo struct {
	Name    string `json:"name"`
	Message string `json:"message"`
	Stack   string `json:"stack"`
}

ErrInfo is a failure as the page reports it.

type FileError

type FileError struct {
	Title string
	Err   ErrInfo
}

FileError is a failure that belongs to the file and not to one test: a hook, a module that did not load, a timeout, a crashed page.

type FileReport

type FileReport struct {
	File     string
	Tests    []TestResult
	Errors   []FileError
	Duration time.Duration
	Logs     []string
}

FileReport is the outcome of one test file in one browser.

func (FileReport) Counts

func (f FileReport) Counts() (passed, failed, skipped int)

Counts of a report.

type Options

type Options struct {
	Root        string
	Suite       Suite
	Files       []string // overrides the globs of the suite when not empty
	Browsers    []string
	Concurrency int
	Grep        string
	Dist        bool // serve the built dist/ files in place of src/
	Port        int
	Timeout     time.Duration // per test file
	Verbose     bool
	Headed      bool
	Logs        bool
	ChromePath  string
	// Open starts a browser; nil means browsers.Open. Tests replace it.
	Open func(ctx context.Context, name string, opts browsers.Options) (browsers.Browser, error)

	Out   io.Writer
	Err   io.Writer
	IsTTY bool
	Env   func(string) string
}

Options configure a browser run of a suite.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves the files of the repository the tests need, the vendored mocha and chai, the test pages and the endpoint where pages report their results. It answers only to the host names of the loopback address it listens on, and never follows a symlink out of the repository root.

func NewServer

func NewServer(root string, suite Suite, port int, dist bool) (*Server, error)

NewServer listens on 127.0.0.1:port (0 picks a free port). With dist true the files of src/ are answered by their built, minified counterparts in dist/ (see distFile), so the suites exercise what a user loads.

func (*Server) Close

func (s *Server) Close() error

Close stops the server.

func (*Server) Port

func (s *Server) Port() int

Port is the port the server listens on.

type Suite

type Suite struct {
	Name string
	// Globs select the test files, relative to the repository root.
	Globs []string
	// Timeout is the mocha timeout of one test in milliseconds.
	TimeoutMS int
	// contains filtered or unexported fields
}

Suite describes one test suite: which files it runs and the page every file runs in.

func (Suite) Page

func (s Suite) Page(file, grep string) string

Page renders the HTML for one test file.

type TestResult

type TestResult struct {
	Path     []string `json:"path"`
	Status   string   `json:"status"` // passed, failed, skipped
	Duration float64  `json:"duration"`
	Error    *ErrInfo `json:"error"`
}

TestResult is one test as mocha ran it.

func (TestResult) Title

func (t TestResult) Title() string

Title is the full title of the test.

Jump to

Keyboard shortcuts

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