goscript

package
v0.5.55 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: BSD-3-Clause Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package goscript provides support for running Cogent Core code compiled to JavaScript by goscript (https://github.com/s4wave/goscript), which is used for the js platform. Code compiled by goscript is built with GOOS=js, GOARCH=wasm, and the goscript build tag.

The main use of this package is RunTests, which runs the existing Go tests of a package compiled to JavaScript, so that the same tests verify both the native and the goscript versions of the code. It is run by core test js (see the cmd package), for the packages given to it, and, for a pattern with ... in it, for the packages that opt in with a Directive line in one of their test files:

//core:js-test

Tests that do not work in goscript call Skip.

This package must only import the standard library, so that it can be used in the tests of any package without an import cycle.

Index

Constants

View Source
const Directive = "//core:js-test"

Directive is the comment directive with which a package opts in to having its tests run compiled to JavaScript by core test js for a package pattern with ... in it (see PackageOptions). It is a line comment in any test file of the package, optionally followed by options:

//core:js-test browser timeout=20m

Each such line is one run of the tests, with these options:

View Source
const Enabled = false

Enabled is whether the code is running as JavaScript compiled by goscript.

Variables

This section is empty.

Functions

func RunTests

func RunTests(dir string, o Options, out io.Writer) error

RunTests runs the Go tests of the package in the given directory compiled to JavaScript by goscript test, writing its output to the given writer. It returns an error if the tests could not be run or did not pass, which names the failing tests. goscript and bun (https://bun.sh) must be installed (as by core setup -js), and tsrs, unless Options.SkipTypecheck.

func Skip

func Skip(t testing.TB, reason string)

Skip skips the given test with the given reason if the code is running as JavaScript compiled by goscript (see Enabled). It is for the (ideally rare and temporary) tests that do not work in goscript.

Types

type Options

type Options struct {

	// Run, if non-empty, only runs the tests matching this regular expression.
	Run string

	// Bench, if non-empty, also runs the benchmarks matching this regular
	// expression, as with go test -bench. The tests are not run in this
	// case, unless [Options.Run] is set.
	Bench string

	// BenchTime is the minimum time to run each benchmark, as a duration
	// such as 2s, if [Options.Bench] is set.
	BenchTime string

	// Timeout is the maximum time for compiling and running the tests.
	// It defaults to 5 minutes (30 minutes with [Options.Bench]).
	Timeout time.Duration

	// Browser runs the tests in a Chromium browser instead of bun.
	Browser bool

	// BrowserChannel, if non-empty, runs the [Options.Browser] tests in
	// this installed browser, such as "chrome", instead of the Chromium
	// that Playwright downloads.
	BrowserChannel string

	// BrowserArgs are additional command-line arguments for the browser,
	// such as "--enable-unsafe-webgpu" to enable WebGPU in headless Chrome.
	BrowserArgs []string

	// Tags are additional build tags (the goscript tag is always added).
	Tags []string

	// SkipTypecheck skips the TypeScript type checking of the compiled
	// code, which goscript test otherwise does before running it, as core
	// build js does (bun only strips the types). It is for packages whose
	// compiled code has type errors that do not affect what they do, so
	// that their tests still run (as mvmcore, whose mvm interpreter the
	// docs use on the web).
	SkipTypecheck bool

	// Verbose makes goscript test print the output of all of the tests,
	// as with go test -v.
	Verbose bool
}

Options are the options for RunTests.

func PackageOptions

func PackageOptions(dir string) ([]Options, error)

PackageOptions returns the options of the runs of the tests of the package in the given directory that its test files give with Directive lines, in the order of the files and lines (none if it has no such line).

Directories

Path Synopsis
Package gsbench has benchmarks of basic Go language operations, used to compare the performance of code compiled to JavaScript by goscript with native Go code (see the goscript package).
Package gsbench has benchmarks of basic Go language operations, used to compare the performance of code compiled to JavaScript by goscript with native Go code (see the goscript package).

Jump to

Keyboard shortcuts

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