Registry / testing / yamltest

yamltest

JSON →
library1.2.0jsnpmunverified

YAMLTest is a declarative testing framework for Node.js (requiring Node.js >=18.0.0) that enables defining HTTP, shell command, and Kubernetes resource tests entirely in YAML. It allows users to write test definitions without boilerplate, running them via CLI or a programmatic API. The package is currently at version 1.2.0 and, based on its active development and recent release, appears to follow a regular, though unspecified, release cadence for new features and fixes. Its core differentiator is the strict, schema-based validation of test definitions *before* execution, providing clear error messages and preventing malformed tests from running. It supports retries, environment variable interpolation, and can run tests locally or within Kubernetes pods, offering a robust solution for integration and end-to-end testing.

npm install yamltest
INSTALL
IMPORT
SIG · YAMLTEST
Y
yamltest
testingjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

runTests
import { runTests } from 'yamltest';
const { runTests } = require('yamltest');
While the provided README examples show CommonJS `require()`, for Node.js 18+ and modern development, ESM `import` is the preferred and fully supported module syntax.
executeTest
import { executeTest } from 'yamltest';
const { executeTest } = require('yamltest');
This function allows low-level execution of a single YAML test definition directly, returning a boolean indicating success or throwing an error on failure.
validateTestDefinitions
import { validateTestDefinitions } from 'yamltest';
const { validateTestDefinitions } = require('yamltest');
Use this function to validate an array of parsed YAML test definitions against the internal schema without initiating any test execution, useful for pre-flight checks.

Demonstrates how to programmatically execute a simple HTTP GET test defined in a YAML string using the `runTests` function and log the overall outcome.

import { runTests } from 'yamltest'; const yamlString = ` - name: httpbin returns 200 http: url: "https://httpbin.org" method: GET path: "/get" source: type: local expect: statusCode: 200 bodyContains: "httpbin.org" `; async function runMyTest() { try { console.log('Running YAMLTest programmatically...'); const result = await runTests(yamlString); console.log(`Test Results: Passed: ${result.passed}, Failed: ${result.failed}, Total: ${result.total}`); if (result.failed > 0) { console.error('One or more tests failed.'); process.exit(1); } else { console.log('All tests passed successfully!'); } } catch (error) { console.error('An unexpected error occurred during test execution:', error.message); process.exit(1); } } runMyTest();
yamltest --version
Debug
Known issues
gotchaAll test definitions are rigorously validated against an internal schema before execution. Any invalid YAML, missing required fields, or incorrect value types will immediately halt the test runner with a specific validation error.
fix
Always consult the official documentation for the exact YAML schema and property requirements for each test type (e.g., `http`, `command`, `wait`, `httpBodyComparison`). Pay close attention to error messages, which pinpoint the exact location of issues.
affects: >=1.0.0
gotchaEach individual test object in the YAML array must define *exactly one* test type (e.g., `http:`, `command:`, `wait:`, or `httpBodyComparison:`). Defining multiple types or omitting a type will cause a schema validation failure.
fix
Ensure that every test definition YAML block contains only one primary key that corresponds to a test type. For instance, `http: { ... }` and `command: { ... }` cannot coexist within the same test object.
affects: >=1.0.0
gotchaWhen defining an HTTP test (`http:` block), the `method` field accepts only a specific set of HTTP verbs: `GET`, `POST`, `PUT`, `DELETE`, `PATCH`. Using any other method will trigger a validation error.
fix
Verify that your `http.method` field adheres strictly to one of the allowed values: GET, POST, PUT, DELETE, or PATCH.
affects: >=1.0.0
gotchaFor tests targeting Kubernetes pods (`source.type: pod`), the `source.selector` property is mandatory to identify the target pod(s). Omitting this field will result in a validation error.
fix
Include a valid `source.selector` (e.g., `app: my-app`) when `source.type` is set to `pod` to specify which Kubernetes pods to interact with.
affects: >=1.0.0
Errors
Common errors & fixes
Validation failed: Test #1 ("login") /http/method: must be one of: GET, POST, PUT, DELETE, PATCH
The HTTP method specified in an `http` test definition is not one of the allowed values.
fix
Change the `http.method` field to `GET`, `POST`, `PUT`, `DELETE`, or `PATCH`.
Validation failed: Test #3: must define exactly one of: http, command, wait, httpBodyComparison
A test definition attempted to specify multiple test types (e.g., both `http` and `command`) or failed to specify any test type.
fix
Review the YAML for Test #3 and ensure it contains exactly one top-level key corresponding to a single test type (e.g., `http:`, `command:`).
Validation failed: Test #5 ("check pods") /source: missing required property "selector"
A test configured to run within a Kubernetes pod (`source.type: pod`) did not include the necessary `selector` property to identify the pod.
fix
Add the `source.selector` field to Test #5, specifying the Kubernetes label selector to target the desired pod(s).
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
41 hits · last 30 days
node
34
OpenAI (training)
1
Resources
yamltest — npm install yamltest · libregistry