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 ¶
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:
- browser: run the tests in Chrome instead of bun (Options.Browser).
- browser-arg=ARG: an argument for the browser (Options.BrowserArgs).
- run=REGEXP: only run the matching tests (Options.Run).
- timeout=DURATION: the timeout of the run (Options.Timeout).
- skip-typecheck: skip the type checking (Options.SkipTypecheck).
- tags=TAG,...: additional build tags (Options.Tags).
const Enabled = false
Enabled is whether the code is running as JavaScript compiled by goscript.
Variables ¶
This section is empty.
Functions ¶
func RunTests ¶
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.
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.
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). |