0.5.43 • Published 4 years ago
tdmf v0.5.43
test-driven-modular-framework
A Test Driven Modular Application Framework
npm install tdmf
Represent any complex application workflow (flowchart) as JavaScript code.
building blocks:
Current Version: 0.5.43
tdmf = require('tdmf')
flags = tdmf.flags // in-memory key-value datastore
testEngine = tdmf.testEngine // register tests for your functions and classes
Pipeline = tdmf.Pipeline // create pipelines
build_pipeline = tdmf.build_pipeline // build pipelines
testEngine.add_test("package", "get_sum", "pt_number_only") // a package test to inspect function input
testEngine.add_test("unit", "get_sum", ["test1", [1,2,3], [6]])
testEngine.add_test("package", "times_two", "pt_number_only")
testEngine.add_test("unit", "times_two", ["test1", [1,2,3], [2,4,6]]) // a unit test
// write components (functions and classes) with global scope
get_sum = async (package) => {
output = []
try {
output = [ package.reduce((a,b) => a+b, 0) ]
} catch(err){
console.log(err)
}
return output
}
times_two = async (package) => {
output = []
try {
output = package.map(x => x*2)
times_two_output = flags.fetch("times_two_output") // read data from in-memory data store
if (times_two_output){
times_two_output = output.reduce((a,b) => { a.push(b); return a }, times_two_output)
} else {
times_two_output = output
}
flags.update("times_two_output", times_two_output) // write data to in-memory data store
} catch(err){
console.log(err)
}
return output
}
// Compose a pipeline to pass output of one function into another
let sample_pipeline = Pipeline([
["get_sum", [1,2.44,3]],
"times_two"
])
// build and run your pipeline asynchronously
build_pipeline(sample_pipeline).then((pipeline) => {
console.log(pipeline.output, flags.fetch("times_two_output"))
})