-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create location directory recursively (#6)
- Loading branch information
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
|
||
const test = require('tape') | ||
const tempy = require('tempy') | ||
const path = require('path') | ||
const fs = require('fs') | ||
const { ClassicLevel } = require('..') | ||
|
||
test('creates location directory recursively', async function (t) { | ||
const location = path.join(tempy.directory(), 'beep', 'boop') | ||
const db = new ClassicLevel(location) | ||
|
||
t.is(fs.existsSync(location), false) | ||
await db.open() | ||
t.is(fs.existsSync(location), true) | ||
}) | ||
|
||
test('does not create location directory recursively if createIfMissing is false', async function (t) { | ||
t.plan(3) | ||
|
||
const location = path.join(tempy.directory(), 'beep', 'boop') | ||
const db = new ClassicLevel(location, { createIfMissing: false }) | ||
|
||
try { | ||
await db.open() | ||
} catch (err) { | ||
t.is(err.code, 'LEVEL_DATABASE_NOT_OPEN') | ||
|
||
// Error message is inconsistent between platforms so not checked | ||
t.ok(err.cause) | ||
|
||
// On Windows, LevelDB itself creates the directory (technically a bug) | ||
t.is(fs.existsSync(location), process.platform === 'win32') | ||
} | ||
}) |