@xhubio/nanook-table
Nanook is a toolkit for defining test cases in Excel spreadsheets and generating test data. You describe your test scenarios using equivalence class tables, matrix tables, or specification tables in standard XLSX files, and Nanook reads those definitions, processes them through pluggable data generators, and writes the resulting test data to your chosen output format.
Key Features
- Equivalence class tables -- Define fields, their equivalence classes (valid and invalid), and mark which class applies to each test case.
- Matrix tables -- Describe pairwise or combinatorial relationships between two dimensions of test parameters.
- Specification tables -- Define field rules and severities at a higher level; Nanook automatically converts them into equivalence class tables.
- Pluggable data generators -- Use the built-in Faker generator or write your own. Generators support instance IDs, uniqueness constraints, persistent stores, and post-processing.
- Custom writers -- Control how generated data is written: JSON files, databases, or any format you need.
- Filtering -- Include or exclude test cases at processing time using tag-based filter expressions.
- Single package -- Everything ships as one ESM package with TypeScript types.
Installation
npm install @xhubio/nanook-table
Requires Node.js >= 22.
Quick Start
import path from 'node:path'
import fs from 'node:fs/promises'
import {
LoggerMemory,
TestcaseProcessor,
createDefaultFileProcessor,
DataGeneratorRegistry,
GeneratorFaker,
type InterfaceWriter
} from '@xhubio/nanook-table'
async function main() {
const logger = new LoggerMemory()
logger.writeConsole = true
const fileProcessor = createDefaultFileProcessor(logger)
// a new registry starts empty: register every generator your tables call (gen::faker:...);
// createDefaultGeneratorRegistry(logger) comes with 'faker' (3.3.0 or later)
const generatorRegistry = new DataGeneratorRegistry()
generatorRegistry.registerGenerator(
'faker',
new GeneratorFaker({ generatorRegistry, name: 'faker', logger })
)
await fileProcessor.load([path.join('resources', 'tests.xlsx')])
const tables: Record<string, any> = {}
for (const table of fileProcessor.tables) {
tables[table.tableName] = table
}
// one JSON file per test case; see "Writing a Custom Writer" below
const writer: InterfaceWriter = {
logger,
async before() {
await fs.mkdir('tdg', { recursive: true })
},
async write(tc) {
await fs.writeFile(path.join('tdg', `${tc.tableName}.${tc.name}.json`), JSON.stringify(tc, null, 2))
},
async after() {}
}
const processor = new TestcaseProcessor({
logger,
generatorRegistry,
writer: [writer],
tables
})
await processor.process()
}
main()
Data Flow
Excel / XLSX File
|
v
ImporterXlsx -- reads raw cell values
|
v
FileProcessor -- delegates to the right parser per sheet
|
+-- ParserDecision -- sheets starting with <DECISION_TABLE>
+-- ParserMatrix -- sheets starting with <MATRIX_TABLE>
+-- ParserSpecification + ParserSpecificationConverter
| -- sheets starting with <SPECIFICATION> (or <SPECIFICATION_TABLE>)
v
Table Models -- TableDecision, TableMatrix
|
v
TestcaseProcessor -- orchestrates the generation loop
|
+-- DataGeneratorRegistry
| +-- GeneratorFaker (built-in)
| +-- your custom generators
|
+-- InterfaceWriter[]
| +-- default JSON writer
| +-- your custom writers
v
Output Files / Data
Table Types
| Marker | Table Type | Description |
|---|
<DECISION_TABLE> | Decision / Equivalence Class | Fields with equivalence classes, one column per test case |
<MATRIX_TABLE> | Matrix | Two-dimensional parameter combinations |
<SPECIFICATION> (also <SPECIFICATION_TABLE>) | Specification | High-level rules that convert to a decision table |
Writing a Custom Generator
Extend DataGeneratorBase and override doGenerate():
import {
DataGeneratorBase,
DataGeneratorGenerateRequest
} from '@xhubio/nanook-table'
class MyGenerator extends DataGeneratorBase {
protected async doGenerate(request: DataGeneratorGenerateRequest) {
const { instanceId, testcaseData, generatorDirective } = request
// Generate and return your data
return `generated-value-for-${generatorDirective?.fieldName}`
}
}
Register it in a DataGeneratorRegistry:
import { DataGeneratorRegistry } from '@xhubio/nanook-table'
const registry = new DataGeneratorRegistry()
const gen = new MyGenerator({ generatorRegistry: registry, name: 'myGen' })
registry.registerGenerator('myGen', gen)
Writing a Custom Writer
Implement the InterfaceWriter interface: