From a3d405e5f21d67627961e525d5716fd34cde9021 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 14 Jul 2018 08:59:44 +0200 Subject: [PATCH 1/2] Test that each factory returns a unique db --- test/factory-test.js | 33 +++++++++++++++++++++++++++++++++ test/index.js | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 test/factory-test.js diff --git a/test/factory-test.js b/test/factory-test.js new file mode 100644 index 00000000..d0884fa1 --- /dev/null +++ b/test/factory-test.js @@ -0,0 +1,33 @@ +var concat = require('level-concat-iterator') + +module.exports = function (test, testCommon) { + test('testCommon.factory() returns a unique database', function (t) { + var db1 = testCommon.factory() + var db2 = testCommon.factory() + + function close () { + db1.close(function (err) { + t.error(err, 'no error while closing db1') + db2.close(function (err) { + t.error(err, 'no error while closing db2') + t.end() + }) + }) + } + + db1.open(function (err) { + t.error(err, 'no error while opening db1') + db2.open(function (err) { + t.error(err, 'no error while opening db2') + db1.put('key', 'value', function (err) { + t.error(err, 'put key in db1') + concat(db2.iterator(), function (err, entries) { + t.error(err, 'got items from db2') + t.same(entries, [], 'db2 should be empty') + close() + }) + }) + }) + }) + }) +} diff --git a/test/index.js b/test/index.js index 764633a5..3b81e6a1 100644 --- a/test/index.js +++ b/test/index.js @@ -18,6 +18,8 @@ module.exports = function (options) { var testCommon = common(options) var test = testCommon.test + require('./factory-test')(test, testCommon) + require('./leveldown-test').args(test, testCommon) require('./open-test').all(test, testCommon) require('./close-test').all(test, testCommon) From a90f48eecf629211e203883778f402ab723cfc81 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 14 Jul 2018 10:49:15 +0200 Subject: [PATCH 2/2] Call setUp and tearDown --- test/factory-test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/factory-test.js b/test/factory-test.js index d0884fa1..4e1413ff 100644 --- a/test/factory-test.js +++ b/test/factory-test.js @@ -1,6 +1,8 @@ var concat = require('level-concat-iterator') module.exports = function (test, testCommon) { + test('setUp common', testCommon.setUp) + test('testCommon.factory() returns a unique database', function (t) { var db1 = testCommon.factory() var db2 = testCommon.factory() @@ -30,4 +32,6 @@ module.exports = function (test, testCommon) { }) }) }) + + test('tearDown', testCommon.tearDown) }