Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Port tests to Brittle #39

Merged
merged 10 commits into from Oct 12, 2021
2 changes: 1 addition & 1 deletion .github/workflows/test-node.yml
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
node_modules
package-lock.json
coverage
sandbox.js
sandbox/
9 changes: 7 additions & 2 deletions package.json
Expand Up @@ -4,7 +4,7 @@
"description": "Hypercore 10",
"main": "index.js",
"scripts": {
"test": "standard && tape test/*.js"
"test": "standard && brittle test/*.{,m}js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -32,13 +32,18 @@
},
"devDependencies": {
"@hyperswarm/replicator": "^1.8.0",
"brittle": "^1.3.9",
"random-access-memory": "^3.1.2",
"range-parser": "^1.2.1",
"standard": "^16.0.3",
"tape": "^5.0.1",
"tmp-promise": "^3.0.2"
},
"optionalDependencies": {
"fsctl": "^1.0.0"
},
"standard": {
"ignore": [
"**/*.mjs"
]
kasperisager marked this conversation as resolved.
Show resolved Hide resolved
}
}
36 changes: 18 additions & 18 deletions test/basic.js
@@ -1,17 +1,17 @@
const tape = require('tape')
const test = require('brittle')
const ram = require('random-access-memory')

const Hypercore = require('../')
const { create } = require('./helpers')

tape('basic', async function (t) {
test('basic', async function (t) {
const core = await create()
let appends = 0

t.same(core.length, 0)
t.same(core.byteLength, 0)
t.same(core.writable, true)
t.same(core.readable, true)
t.is(core.length, 0)
t.is(core.byteLength, 0)
t.is(core.writable, true)
t.is(core.readable, true)

core.on('append', function () {
appends++
Expand All @@ -20,25 +20,25 @@ tape('basic', async function (t) {
await core.append('hello')
await core.append('world')

t.same(core.length, 2)
t.same(core.byteLength, 10)
t.same(appends, 2)
t.is(core.length, 2)
t.is(core.byteLength, 10)
t.is(appends, 2)

t.end()
})

tape('session', async function (t) {
test('session', async function (t) {
const core = await create()

const session = core.session()

await session.append('test')
t.same(await core.get(0), Buffer.from('test'))
t.same(await session.get(0), Buffer.from('test'))
t.alike(await core.get(0), Buffer.from('test'))
t.alike(await session.get(0), Buffer.from('test'))
t.end()
})

tape('close', async function (t) {
test('close', async function (t) {
const core = await create()
await core.append('hello world')

Expand All @@ -52,7 +52,7 @@ tape('close', async function (t) {
}
})

tape('close multiple', async function (t) {
test('close multiple', async function (t) {
const core = await create()
await core.append('hello world')

Expand All @@ -64,16 +64,16 @@ tape('close multiple', async function (t) {
core.close().then(() => done('close 3'))

await core.close()
t.same(expected.length, 0, 'all event passed')
t.is(expected.length, 0, 'all event passed')

function done (event) {
t.same(event, expected.shift())
t.is(event, expected.shift())
}
})

tape('storage options', async function (t) {
test('storage options', async function (t) {
const core = new Hypercore({ storage: ram })
await core.append('hello')
t.same(await core.get(0), Buffer.from('hello'))
t.alike(await core.get(0), Buffer.from('hello'))
t.end()
})
24 changes: 12 additions & 12 deletions test/bitfield.js
@@ -1,26 +1,26 @@
const tape = require('tape')
const test = require('brittle')
const ram = require('random-access-memory')
const Bitfield = require('../lib/bitfield')

tape('bitfield - set and get', async function (t) {
test('bitfield - set and get', async function (t) {
const b = await Bitfield.open(ram())

t.false(b.get(42))
t.absent(b.get(42))
b.set(42, true)
t.true(b.get(42))
t.ok(b.get(42))

// bigger offsets
t.false(b.get(42000000))
t.absent(b.get(42000000))
b.set(42000000, true)
t.true(b.get(42000000))
t.ok(b.get(42000000))

b.set(42000000, false)
t.false(b.get(42000000))
t.absent(b.get(42000000))

await b.flush()
})

tape('bitfield - random set and gets', async function (t) {
test('bitfield - random set and gets', async function (t) {
const b = await Bitfield.open(ram())
const set = new Set()

Expand Down Expand Up @@ -51,7 +51,7 @@ tape('bitfield - random set and gets', async function (t) {
t.pass('all random set and gets pass')
})

tape('bitfield - reload', async function (t) {
test('bitfield - reload', async function (t) {
const s = ram()

{
Expand All @@ -64,8 +64,8 @@ tape('bitfield - reload', async function (t) {

{
const b = await Bitfield.open(s)
t.true(b.get(142))
t.true(b.get(40000))
t.true(b.get(1424242424))
t.ok(b.get(142))
t.ok(b.get(40000))
t.ok(b.get(1424242424))
}
})