
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
Simple but powerful JSON-like data-driven unit testing utility
npm install -g --save ddt-js
var ddt = require('ddt-js);
let sayHello = function(person){
if (!person && person !== false)
throw "invalid person";
else
return "Hello " + person;
}
ddt.test({
title: "test sayHello() with actual person",
unit: sayHello,
getArgs: function() { return ["World"]; },
getExpected: function() { return "Hello World"; }
})
output:
{
title: "test sayHello with actual person",
unit: "sayHello()",
args: ["World"],
expected: "Hello World",
actual: "Hello World",
passed: true
}
ddt --src foo/bar/src --dest foo/bar/test --ext .test.result --test-info-key testInfo
The command line options are:
The ddt command-line assumes each file in the source glob defines a single module together with its test information. To be testable, the module definition must export a test information object (by default named "testInfo") that specifies the folowing members:
{
title: "test title",
description: "test description",
unit: function(){}, // the function being tested
getArgs: function(){ return []}, // return array of arguments to be passed to unit
getConvertedActual: function(actual){ return actual }, // optional function to convert actual value before comparison
getExpected: function(){}, // return expected value of test
getComparison: function(expected, actual) { return expected === actual; } // optional function to compare expected and actual
}
module.exports.sayHello = function(person){
if (!person && person !== false)
throw "invalid person";
else
return "Hello " + person;
}
module.exports.testInfo = {
defaultUnit: sayHello,
getContext: function() { return null; },
cases: [
{
title: "sayHello() return correct output with actual person",
getArgs: function() { return ["World"]; },
getExpected: function() { return "Hello World"; }
},
{
title: "sayHello() return correct error with null person",
getArgs: function() { return [null]; },
getExpected: function() { return "invalid person"; }
}
]
})
FAQs
Simple but powerful JSON-like data-driven unit testing utility
We found that ddt-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.