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

Commit

Permalink
Port tests to Brittle (#39)
Browse files Browse the repository at this point in the history
* Initial pass on porting tests to Brittle

* Convert `test/oplog.js` to ESM and serialize tests

* Don't lint `test/oplog.mjs`

* Update `actions/setup-node` to v2

* Don't lint any ESM files

* Update Brittle

* Revert "Convert `test/oplog.js` to ESM and serialize tests"

This reverts commit 6ff787c.

* Serialize oplog tests

* Update Brittle and make oplog tests serial

* Remove Standard config in `package.json`
  • Loading branch information
kasperisager authored and mafintosh committed Oct 19, 2021
1 parent d38b06a commit a9143dd
Show file tree
Hide file tree
Showing 15 changed files with 385 additions and 382 deletions.
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
Expand Up @@ -2,6 +2,7 @@ node_modules
package-lock.json
.DS_Store
sandbox
coverage
sandbox.js
tmp
*.log
4 changes: 2 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/*.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -32,10 +32,10 @@
},
"devDependencies": {
"@hyperswarm/replicator": "^1.8.0",
"brittle": "^1.4.1",
"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": {
Expand Down
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))
}
})

0 comments on commit a9143dd

Please sign in to comment.