thinkable

Helpers for testing RethinkDB apps with AVA

Usage no npm install needed!

<script type="module">
  import thinkable from 'https://cdn.skypack.dev/thinkable';
</script>

README

thinkable Build status for Thinkable

Helpers for testing RethinkDB apps with AVA

Why?

  • Initializes and cleans up the database.
  • Each test worker gets its own isolated database.
  • Easily seed the database and configure it.

Install

npm install thinkable --save-dev

Usage

import test from 'ava';
import r from 'rethinkdb';
import { init, cleanup } from 'thinkable';

const seed = {
    dbOne : {
        tableA : [
            { name : 'Jane Doe' }
        ]
    },
    dbTwo : {
        tableA : [
            { color : 'blue' }
        ]
    }
};

test.before(init(seed));
test.after.always(cleanup);

test('does some stuff', async (t) => {
    const conn = await r.connect({
        port : t.context.dbPort
    });
    console.log(await r.dbList().run(conn));
});

API

init(seed, option)

Returns an async function that is meant to be passed as fn to AVA's test.before(fn). The returned function, when called, starts and seeds the database.

cleanup()

Stops the database and cleans up its data.

option

Type: object

cwd

Type: string

A path where the RethinkDB data directory should be created.

password

Type: string

An initial password for the admin user.

Contributing

See our contributing guidelines for more details.

  1. Fork it.
  2. Make a feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.

License

MPL-2.0 © Seth Holladay

Go make something, dang it.