🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

testutil

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

testutil

testutil contains methods to aid in automatic testing of your application.

Source
npmnpm
Version
0.2.2
Version published
Maintainers
1
Created
Source

Node.js - testutil

This module provides methods to aid in testing your Node.js apps. You probably wouldn't run this in production.

Installation

npm install testutil

Make sure that you run the test script to verify that it works on your system.

Test Installation

Navigate to the directory for the module and run: npm test

Usage

testutil = require('testutil')

Module Methods

createTempDir()

Synchronously creates a temporary directory and returns the path.

var dirPath = testutil.createTempDir();

e.g. /tmp/tmpdir-359353928528529/

createBuffer(size)

Synchronously creates and returns a buffer of size N filled with random data.

var buffer = testutil.createBuffer(1024); //buffer of 1024 bytes
createFileWithData(size)

Synchronously creates a file of size N filled with random data. The file path is returned.

var filepath = testutil.createFileWithData(filepath, 1024); 
fetchTestFiles(dirPath, callback)

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.

generateTestPath(name)

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

Global Methods

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.

T() / F() / TTRUE() / TFALSE() / TTrue() / TFalse()

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')

TODO

  • Remove CoffeeScript development dependency.

License

(The MIT License) See LICENSE for details.

Copyright (c) 2011-2012 JP Richardson

Keywords

test

FAQs

Package last updated on 11 Aug 2012

Did you know?

Socket

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.

Install

Related posts