jsonscript-test
raw JSON → 0.6.0 verified Fri May 01 auth: no javascript
jsonscript-test (v0.6.0) is a testing library for JSONScript scripts, allowing developers to define and run test suites that validate script behavior. It is part of the JSONScript ecosystem and is currently a work in progress, with an unstable API expected to evolve. Unlike general testing frameworks, it is tailored specifically for JSONScript's declarative execution model. Release cadence is sporadic, as the project is in early development.
Common errors
error SyntaxError: Cannot use import statement outside a module ↓
cause Running ESM code in a non-module Node.js environment.
fix
Add "type": "module" to package.json or use .mjs extension.
error TypeError: require is not a function ↓
cause Using require() in an ESM context after v0.6.0.
fix
Switch to import statements or downgrade to v0.5.0.
error AssertionError: expected undefined to deeply equal 3 ↓
cause Test script returned undefined instead of expected value.
fix
Ensure JSONScript script produces correct output; check script definition.
Warnings
gotcha Package is a work in progress; API is unstable and may change without notice. ↓
fix Pin to exact version and expect breaking changes.
breaking v0.6.0 switched to ESM-only; CommonJS require() will throw an error. ↓
fix Use ES module imports or downgrade to v0.5.x if CJS needed.
gotcha Test suites must follow JSONScript schema; invalid scripts cause silent failures. ↓
fix Validate JSONScript scripts before including in test suites.
Install
npm install jsonscript-test yarn add jsonscript-test pnpm add jsonscript-test Imports
- default wrong
const test = require('jsonscript-test')correctimport test from 'jsonscript-test' - runSuite wrong
const { runSuite } = require('jsonscript-test')correctimport { runSuite } from 'jsonscript-test' - defineSuite wrong
import { defineSuite } from 'jsonscript-test/test'correctimport { defineSuite } from 'jsonscript-test'
Quickstart
import test, { runSuite, defineSuite } from 'jsonscript-test';
// Define a test suite
const suite = defineSuite({
name: 'My Suite',
tests: [
{
name: 'addition',
script: { $op: 'add', left: 1, right: 2 },
expected: 3
}
]
});
// Run the suite
const results = runSuite(suite);
console.log(results); // outputs test results