
Product
Introducing Immutable Scans
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.
This module provides methods to aid in testing your Node.js apps. You probably wouldn't run this in production.
npm install testutil
Make sure that you run the test script to verify that it works on your system.
Navigate to the directory for the module and run: npm test
testutil = require('testutil')
Synchronously creates a temporary directory and returns the path.
var dirPath = testutil.createTempDir();
e.g. /tmp/tmpdir-359353928528529/
Synchronously creates and returns a buffer of size N filled with random data.
var buffer = testutil.createBuffer(1024); //buffer of 1024 bytes
Synchronously creates a file of size N filled with random data. The file path is returned.
var filepath = testutil.createFileWithData(filepath, 1024);
Asynchronously fetches all of the files in a specified directory that end in .test.coffee or .test.js.
testutil.fetchTestFiles('test/', function(files) {
// do something with test files
});
You might use this in conjunction with Mocha.
Generates a string that you can use for a test path.
var testPath = testutil.generateTestPath('test-mypackage');
console.log(testPath); // /tmp/test-mypackage/2012-08-04_13-05-11
This modules also creates three global methods that I use in my tests. Again, as stated up top, you shouldn't use this in production code.
I like short and concise tests. I also write everything CoffeeScript. Here are the function definitions:
T = (v) -> assert(v)
F = (v) -> assert(!v)
for you JavaScript folks:
T = function(v) { return assert(v); };
F = function(v) { return assert(!v); };
My CoffeeScript tests might look like this:
describe 'SomeClass', ->
describe '- ssaySomethingNice()', ->
it 'should say something nice', ->
T saySomethingNice() == 'hello'
F saySomethingNice() == 'i hate you'
easier to visually parse than what a lot of other tests look like:
describe 'SomeClass', ->
describe '- saySomethingNice()', ->
it 'should say something nice', ->
saySomethingNice().should.equal('hello')
assert.false(saySomethingNice(), 'i hate you')
(The MIT License) See LICENSE for details.
Copyright (c) 2011-2012 JP Richardson
FAQs
testutil contains methods to aid in automatic testing of your application.
We found that testutil 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.

Product
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.