A simple framework for testing cxy web applications
A practical, example-first guide to writing tests with js-test. If you're new
to the framework, read 15 and you'll be productive; the rest is reference by
feature.
package.json, no node_modules. Tests run on Node's built-in node:test and web-standard APIs.
directory.
Add js-test as a dev dependency in your Cxyfile.yaml:
dev-dependencies:
- name: js-test
repository: https://github.com/cxy-lang/js-test.git
version: '^0.1.0'
Then cxy package install. Because js-test exports its runner, you can run it
directly with zero local config:
cxy package run @js-test test
Or add a local shorthand to your Cxyfile.yaml:
scripts:
test: cxy package run @js-test test -- "$@"
cxy package run test
node path/to/js-test/bin/runner.mjs
The runner discovers tests/**/*.test.mjs (and *.test.js) under the current
directory.
A test file is a normal node:test file that imports from "js-test":
// tests/hello.test.mjs
import test from "node:test";
import assert from "node:assert/strict";
import { findFreePort } from "js-test";
test("allocates a free port", async () => {
const port = await findFreePort();
assert.ok(port > 0);
});
Run it:
cxy package run test -- -s hello
The bare "js-test" import works without node_modules the runner registers a
module-resolution hook that maps it to the installed package.
node "${CXY_PACKAGE_DIR}/bin/runner.mjs" [options] [files...]
| Flag | Meaning | |
|---|---|---|
-s, --suite <regex> |
Only run test files whose path matches | |
-f, --filter <regex> |
Only run tests whose name matches | |
| `--browser <chromium\ | safari>` | Browser engine for browser suites (default chromium) |
--browser-path <path> |
Explicit browser binary/driver | |
--artifacts-dir <path> |
Where run artifacts go (default .cxy/build/tests) |
|
--stdout <reporter> |
Stdout reporter: spec |