jstest

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package jstest is a test framework using js as test script

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Throw

func Throw(err error)

Throw throw go error in js vm as an Exception

func Throws

func Throws(msg string)

Throws throw go string in js vm as an Exception

Types

type Adapter

type Adapter interface {
	// Before all test begin
	OnSetup(r *Runner)
	// When all test in a testfile is done
	OnTeardown(r *Runner)
	// When test case is register
	OnTestCase(r *Runner, test TestCase) TestCase
}

Adapter is the interface of underlying logic manager

type RunOption

type RunOption struct {
	Quiet    bool
	Patten   string
	InGoTest bool
}

RunOption is the option to run a test script

func DefaultRunOption

func DefaultRunOption() *RunOption

DefaultRunOption returns the default RunOption

type Runner

type Runner struct {
	Option RunOption
	// contains filtered or unexported fields
}

Runner is the runner of test file

func NewRunner

func NewRunner(opt *RunOption, adapter Adapter) (*Runner, error)

NewRunner instance a Runner

func (*Runner) AddModulePath

func (r *Runner) AddModulePath(path []string)

AddModulePath add path as nodejs module search path

func (*Runner) AddTestFile

func (r *Runner) AddTestFile(file string) error

AddTestFile add a js test file to Runner

func (*Runner) Close

func (r *Runner) Close()

Close release resources by Runner

func (*Runner) GlobalObject

func (r *Runner) GlobalObject() *otto.Object

GlobalObject returns the global Object in js vm

func (*Runner) Run

func (r *Runner) Run(rundir string) error

Run run all tests with rundir as working directory

func (*Runner) RunFile

func (r *Runner) RunFile(file string) error

Run run a js test file using file's dir as working directory

func (*Runner) VM

func (r *Runner) VM() *otto.Otto

VM returns the js vm

type TestCase

type TestCase struct {
	Name string
	F    func(*testing.T)
}

TestCase is the one test case

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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