Machinepack Test Runner
raw JSON →test-machinepack provides a raw command-line test runner specifically designed for `node-machine` 'machinepacks'. Its current stable version is 3.0.1, though the last known development activity dates back to 2017, suggesting it is in maintenance mode rather than active development. While it includes a basic, generic test driver, the documentation explicitly recommends against using it for production testing, instead pointing to more robust, community-maintained drivers like `test-machinepack-mocha`. The primary function of this package is to expose a consistent interface for running tests defined in JSON or JSON5 format within a machinepack's `tests` directory, thereby enabling custom test drivers to integrate seamlessly with the `node-machine` ecosystem.
Common errors
error command not found: testmachinepack ↓
npm install -g test-machinepack. error Error: Failed to parse test file: [filepath].json5 (SyntaxError: Unexpected token ...) ↓
jsonlint or online JSON validators can help identify issues. error Error: Could not find 'machine' with identity 'some-machine' in the current machinepack. ↓
machine property in your JSON/JSON5 test file exactly matches the identity of an existing machine within your machinepack. Verify the machine's file name and export. Warnings
gotcha The built-in test driver included with `test-machinepack` is explicitly labeled as 'pretty basic' and not recommended for serious use. Users are encouraged to utilize external drivers, such as `test-machinepack-mocha`, for more robust and feature-rich testing. ↓
deprecated The package appears to be unmaintained since 2017 based on its GitHub activity and copyright dates. While functional, it may not receive updates for new Node.js versions or security fixes, potentially leading to compatibility issues. ↓
gotcha Test definitions are written in JSON or JSON5 format, which differs significantly from traditional JavaScript/TypeScript test files. This can be a steep learning curve for developers unfamiliar with the `node-machine` convention. ↓
Install
npm install test-machinepack yarn add test-machinepack pnpm add test-machinepack Imports
- testmachinepack CLI wrong
node testmachinepackcorrecttestmachinepack - runTests wrong
import { runTests } from 'test-machinepack';correctconst runTests = require('test-machinepack'); - runTests (ESM) wrong
import * as testMachinepack from 'test-machinepack';correctimport runTests from 'test-machinepack';
Quickstart
npm install -g test-machinepack
mkdir my-awesome-machinepack
cd my-awesome-machinepack
# Assuming you have `machinepack` installed globally to use `pm scrub`
# npm install -g machinepack
pm scrub
mkdir tests
cat > tests/example-machine.json5 <<EOF
{
"machine": "example-machine",
"expectations": [
{
"using": {
"input1": "hello"
},
"outcome": "success"
},
{
"using": {
"input1": ""
},
"outcome": "error",
"todo": true
}
]
}
EOF
# Run tests using the built-in (basic) driver
testmachinepack