test-level
Create temporary levelup databases, with unique names generated by tmpgen. Can remove directory on test end, db.close or before process exit (on node >= 0.12.11). Does not include levelup, leveldown or memdown - so you get to choose the versions. API unstable, expect breaking changes.
example
npm i levelup leveldown level-sublevel test-level
const disk = 'my-module/*' wrap: 'sublevel' const db1 = const db2 = // /tmp/my-module/1454283677055// /tmp/my-module/1454283677055.001console const sub = db1
see also
- level-test
- ltest test function on top of
level-test
Differences from level-test
:
- In
level-test
,opts.clean
removes the directory before opening the db, intest-level
it removes the directory after you're done - No browser support as of yet
- Does not fallback to memdown if leveldown failed to load
- Does not include memdown, leveldown or levelup
usage
npm i levelup leveldown memdown level-sublevel test-level existent
const level = existent = // Create a levelup+memdown factory, with node-hat as// name generator (see `npm docs tmpgen` for details)const mem = // Same asconst mem2 = const mem3 = // Create a db and override the valueEncoding (or// any other levelup option) of the factoryconst db1 = // Create a levelup+leveldown factory. Each db gets a unique temporary// directory with the default monotonic-timestamp name generator and is// wrapped with level-sublevel.const diskA = const db2 = const sub = db2 // Same, at custom tmp location, with wrapper optionsconst diskB = const db3 = // Remove created dbs before process exit (ignored if mem is true)const diskC = // Create db in a subdirectoryconst db4 = ;db1 db2 db3 db4 process
Output:
db 1 false 8a2fe3f361ff5365dd956da54fcca014
db 2 true /tmp/test-level/1454283677010
db 3 true /tmp/my-module/1454283677055
db 4 true /tmp/beep-1454283677058/special-name
Exiting
db 1 false 8a2fe3f361ff5365dd956da54fcca014
db 2 true /tmp/test-level/1454283677010
db 3 true /tmp/my-module/1454283677055
db 4 false /tmp/beep-1454283677058/special-name
tape test helper
[todo: write docs or move that stuff to another module]
api
main(arg[,opts])
...
install
With npm do:
npm install test-level
license
MIT © Vincent Weevers