New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ltest

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ltest

test function for leveldb testing

latest
Source
npmnpm
Version
2.1.2
Version published
Weekly downloads
29
866.67%
Maintainers
1
Weekly downloads
 
Created
Source

ltest Build Status

A test function that:

  • Sets up a fresh temporary levelup instance.
  • Calls back with t, db and createReadStream.
  • Closes db and removes files when a test ends via t.end().
  • Adds tests to make sure db is opened, closed and removed properly.
  • Supports multiple levelup backends via level-test, which also has built in support for MemDOWN. Default is leveldown.
  • Supports any test framework that has a test function and t.end and t.ok methods.

Extracted from the test code in level-ttl and made more generic.

Install

$ npm install ltest --save

Usage

var tape = require('tape')
var test = require('ltest')(tape)
test('put and stream', function (t, db, createReadStream) {
  db.put('foo', 'bar', function (err) {
    t.ok(!err, 'no put error')
    var count = 0
    createReadStream()
      .on('data', function (data) {
        t.equal(data.key, 'foo')
        t.equal(data.value, 'bar')
        ++count
      })
      .on('end', function () {
        t.equal(count, 1)
        t.end() // <-- will close the db and delete files
      })
  })
})
TAP version 13
# put and stream
ok 1 no error on open()
ok 2 valid db object
ok 3 no put error
ok 4 should be equal
ok 5 should be equal
ok 6 should be equal
ok 7 no error on close()
ok 8 db removed

1..8
# tests 8
# pass  8

# ok

Api

ltest([options, ]testFn)

Returns a test function of the form function (desc[, opts], cb) where desc is the test description, opts is an optional options object passed to underlying db and cb is a callback of the form function (t, db, createReadStream).

options object is optional and is passed on to levelup and to level-test. Use this to define things like 'keyEncoding' or other settings for levelup.

Set options.mem to true if you want an in memory db.

testFn is the test function that should be used. Use any framework you like as long as it's a function and supports t.end and t.ok methods.

var ltest = require('ltest')(require('tape'))

or

var ltest = require('ltest')(require('tap').test)

License

MIT

Keywords

test

FAQs

Package last updated on 25 Dec 2015

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