Initial import with skill sheet working
This commit is contained in:
26
node_modules/level-supports/test/cloneable.js
generated
vendored
Normal file
26
node_modules/level-supports/test/cloneable.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
const { supports } = require('..')
|
||||
|
||||
// Every object in a manifest must have a unique identity, to avoid accidental
|
||||
// mutation. In supports() we only shallowly clone the manifest object itself
|
||||
// and additionalMethods. If in the future we add more objects to manifests,
|
||||
// this test will break and we'll know to start performing a deep clone.
|
||||
module.exports = function cloneable (t, manifest) {
|
||||
const copy = supports(manifest)
|
||||
verifyUnique(t, 'manifest', manifest, copy)
|
||||
}
|
||||
|
||||
function verifyUnique (t, path, a, b) {
|
||||
if (isObject(a) && isObject(b)) {
|
||||
t.ok(a !== b, path + ' has unique identity')
|
||||
|
||||
Object.keys(a).forEach(function (key) {
|
||||
verifyUnique(t, path + '.' + key, a[key], b[key])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function isObject (o) {
|
||||
return typeof o === 'object' && o !== null
|
||||
}
|
||||
29
node_modules/level-supports/test/index.js
generated
vendored
Normal file
29
node_modules/level-supports/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict'
|
||||
|
||||
const shape = require('./shape')
|
||||
const cloneable = require('./cloneable')
|
||||
|
||||
module.exports = function suite (test, testCommon) {
|
||||
test('db has manifest', function (t) {
|
||||
const db = testCommon.factory()
|
||||
const manifest = db.supports
|
||||
|
||||
shape(t, manifest)
|
||||
cloneable(t, manifest)
|
||||
|
||||
const before = Object.assign({}, manifest, {
|
||||
additionalMethods: Object.assign({}, manifest.additionalMethods)
|
||||
})
|
||||
|
||||
db.open(function (err) {
|
||||
t.ifError(err, 'no open error')
|
||||
t.same(db.supports, before, 'manifest did not change after open')
|
||||
|
||||
db.close(function (err) {
|
||||
t.ifError(err, 'no close error')
|
||||
t.same(db.supports, before, 'manifest did not change after close')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
75
node_modules/level-supports/test/self.js
generated
vendored
Normal file
75
node_modules/level-supports/test/self.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict'
|
||||
|
||||
const test = require('tape')
|
||||
const { supports } = require('..')
|
||||
const shape = require('./shape')
|
||||
const cloneable = require('./cloneable')
|
||||
|
||||
test('no options', function (t) {
|
||||
shape(t, supports())
|
||||
cloneable(t, supports())
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('falsy options', function (t) {
|
||||
;[null, false, undefined, 0, ''].forEach(function (value) {
|
||||
const manifest = supports({
|
||||
seek: value,
|
||||
additionalMethods: {
|
||||
foo: value
|
||||
}
|
||||
})
|
||||
|
||||
shape(t, manifest)
|
||||
t.is(manifest.seek, false)
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('truthy options', function (t) {
|
||||
;[true, {}, 'yes', 1, []].forEach(function (value) {
|
||||
const manifest = supports({
|
||||
streams: value,
|
||||
additionalMethods: {
|
||||
foo: value
|
||||
}
|
||||
})
|
||||
|
||||
shape(t, manifest)
|
||||
t.same(manifest.streams, value)
|
||||
t.same(manifest.additionalMethods.foo, value)
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('merges input objects without mutating them', function (t) {
|
||||
const input1 = { seek: null, streams: false }
|
||||
const input2 = { streams: true, additionalMethods: {} }
|
||||
const manifest = supports(input1, input2)
|
||||
|
||||
manifest.foobar = true
|
||||
manifest.additionalMethods.baz = true
|
||||
|
||||
t.same(input1, { seek: null, streams: false })
|
||||
t.same(input2, { streams: true, additionalMethods: {} })
|
||||
t.is(manifest.seek, false)
|
||||
t.is(manifest.streams, true)
|
||||
shape(t, manifest)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('inherits additionalMethods', function (t) {
|
||||
const manifest = supports({ additionalMethods: { foo: true } }, {})
|
||||
t.same(manifest.additionalMethods, { foo: true })
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('does not merge additionalMethods', function (t) {
|
||||
const input1 = { additionalMethods: { foo: true } }
|
||||
const input2 = { additionalMethods: { bar: true } }
|
||||
const manifest = supports(input1, input2)
|
||||
t.same(manifest.additionalMethods, { bar: true })
|
||||
t.end()
|
||||
})
|
||||
22
node_modules/level-supports/test/shape.js
generated
vendored
Normal file
22
node_modules/level-supports/test/shape.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict'
|
||||
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty
|
||||
|
||||
module.exports = function shape (t, manifest) {
|
||||
t.ok(isObject(manifest), 'manifest is object')
|
||||
t.ok(isObject(manifest.additionalMethods), 'additionalMethods is object')
|
||||
|
||||
for (const k in manifest) {
|
||||
if (!hasOwnProperty.call(manifest, k)) continue
|
||||
|
||||
if (manifest[k]) {
|
||||
t.ok(manifest[k], 'truthy: ' + k)
|
||||
} else {
|
||||
t.is(manifest[k], false, 'false: ' + k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isObject (o) {
|
||||
return typeof o === 'object' && o !== null
|
||||
}
|
||||
Reference in New Issue
Block a user