@nan0web/test
v1.1.3
Published
A test package with simple utilities for testing in node.js runtime
Downloads
46
Readme
@nan0web/test
|Package name|Status|Documentation|Test coverage|Features|Npm version|
|---|---|---|---|---|---|
|@nan0web/test |🟢 97.2% |🧪 English 🏴Українською 🇺🇦 |🟡 83.5% |✅ d.ts 📜 system.md 🕹️ playground |1.1.2 |
A test package with simple utilities for testing in node.js runtime. Designed for nan0web philosophy, where zero dependencies mean maximum freedom and minimal assumptions.
This package helps build ProvenDocs and structured datasets from test examples, especially useful for LLM fine-tuning.
Installation
How to install with npm?
npm install @nan0web/testHow to install with pnpm?
pnpm add @nan0web/testHow to install with yarn?
yarn add @nan0web/testCore Concepts
This package is designed with zero external dependencies and maximum clarity:
- ✅ Fully typed with JSDoc and
.d.tsfiles - 🔁 Includes mocked utilities for real testing scenarios
- 🧠 Built for cognitive clarity: each function has a clear purpose
- 🌱 Enables lightweight testing without side effects
MemoryDB(options)
Utility to simulate a file system for tests.
@deprecated Use the
@nan0web/db.DBas it has the same functionality.
- Parameters
options– Object of params including:predefined– Map of pre-defined file contents (e.g.,{ 'users.json': '[{ id: 1 }]' })
How to mock file system using MemoryDB?
import { MemoryDB } from "@nan0web/test"
const db = new MemoryDB({
predefined: new Map([
['file1.txt', 'content1'],
['file2.txt', 'content2'],
]),
})
await db.connect()
const content = await db.loadDocument('file1.txt')
console.info(content) // 'content1'runSpawn(cmd, args, options)
Utility to mock and execute child processes (for CLI tools).
Parameters
cmd– command to run (e.g.,"git")args– array of argumentsopts– optional spawn options withonDatahandler
Returns
{ code: number, text: string }
How to use runSpawn as a CLI test tool?
import { runSpawn } from "@nan0web/test"
const { code, text } = await runSpawn('echo', ['hello world'])
console.info(code) // 0
console.info(text.includes('hello world')) // trueTestPackage(options)
Class to automate package verification based on nan0web standards.
- Parameters
options– package metadata and file system db instance
How to validate a package using TestPackage.run(rrs)?
import { TestPackage, RRS } from "@nan0web/test"
const db = new MemoryDB()
db.set("system.md", "# system.md")
db.set("tsconfig.json", "{}")
db.set("README.md", "# README.md")
db.set("LICENSE", "ISC")
const pkg = new TestPackage({
db,
cwd: ".",
name: "@nan0web/test",
baseURL: "https://github.com/nan0web/test"
})
const rrs = new RRS()
const statuses = []
for await (const s of pkg.run(rrs)) {
statuses.push(s.name + ':' + s.value)
}
console.info(statuses.join('\n'))DocsParser
Parser to extract documentation from tests and generate markdown (ProvenDoc).
It reads js tests with comments like:
it("How to do something?", () => {
...
})and converts them into structured .md documents.
DatasetParser
Parser that converts markdown docs (such as README.md) into structured .jsonl datasets.
Each How-to block becomes one test case:
{"instruction": "How to do X?", "output": "```js\n doX()\n```", ...}How to generate dataset from markdown documentation?
import { DatasetParser } from "@nan0web/test"
const md = '# Title\n\nHow to do X?\n```js\ndoX()\n```'
const dataset = DatasetParser.parse(md, '@nan0web/test')
console.info(dataset[0].instruction) // ← "How to do X?"Playground
This package doesn't use heavy mocking or virtual environments — it simulates them with lightweight wrappers. You can play in its sandbox as follows:
How to run CLI sandbox?
git clone https://github.com/nan0web/test.git
cd test
npm install
npm run playAPI Components
has multiple test components that can be imported separately
import { MemoryDB, DocsParser, DatasetParser, runSpawn } from "@nan0web/test"Java•Script types & Autocomplete
Package is fully typed with jsdoc and d.ts.
How many d.ts files should cover the source?
Contributing
How to contribute? - check here
License
How to license? - LICENSE
