An in-memory RethinkDB used for testing.
The end goal is to replicate the API of rethinkdbdash
.
For all intents and purposes, you should get the same results.
Please review the Feature support table before opening an issue.
Reusing and nesting queries are fully supported. ๐
Check out the Releases tab for details about the newest versions.
- Load JSON data into the database with
db.load()
- Or call
db.init()
to easily populate the database - Easily run specific tests (
fit
in Jasmine) - Avoid teardown between test suites
- Avoid having to start a
rethinkdb
process before you can run tests - Avoid mutilating your development
rethinkdb_data
- Continuous integration compatibility
- Install from Github:
npm install --save-dev rethinkdb-mock
- Put some boilerplate in your test environment:
const rethinkdb = require('rethinkdb-mock')
// Replace `rethinkdbdash` with `rethinkdb-mock`
const mock = require('mock-require')
mock('rethinkdbdash', rethinkdb)
// You must use the same database name as the code you're testing.
const db = rethinkdb({
name: 'test' // The default value
})
- Use it in your test suites:
describe('Some test suite', () => {
// Reset the database between suites.
beforeAll(() => {
db.init({
users: [],
friends: [],
})
// Optionally, load JSON into the database.
db.load(__dirname, './data.json')
})
// Now create your tests...
})
The entire Rethink API is not yet implemented.
Get an idea of what's supported by referencing the table below.
Open an issue to request a feature be implemented.
But try implementing it yourself if you have time! ๐
If a method is not behaving as expected, please open an issue!
But first check out TODO.md
for a list of missing behaviors.
โ means "not implemented yet"
โ ๏ธ means "partially implemented"๐ฏ means "fully implemented"
% | Feature |
---|---|
โ | Changefeeds |
โ | Binary support |
โ | Date-time support |
โ | Geospatial support |
๐ฏ | r.table() |
๐ฏ | r.tableCreate() |
โ | r.tableList() |
๐ฏ | r.tableDrop() |
โ | r.indexCreate() |
โ | r.indexList() |
โ | r.indexDrop() |
โ | r.indexRename() |
โ | r.indexStatus() |
โ | r.indexWait() |
r.row |
|
๐ฏ | r() or r.expr() |
๐ฏ | r.do() |
โ | r.args() |
๐ฏ | r.object() |
๐ฏ | r.branch() |
r.typeOf() |
|
๐ฏ | r.uuid() |
r.desc() |
|
r.asc() |
|
โ | r.js() |
โ | r.json() |
โ | r.http() |
โ | r.error() |
โ | r.range() |
๐ฏ | table.get() |
๐ฏ | table.getAll() |
table.insert() |
|
๐ฏ | table.delete() |
๐ฏ | query() or query.bracket() |
๐ฏ | query.nth() |
๐ฏ | query.getField() |
query.hasFields() |
|
โ | query.withFields() |
query.offsetsOf() |
|
query.contains() |
|
query.orderBy() |
|
๐ฏ | query.isEmpty() |
๐ฏ | query.count() |
๐ฏ | query.skip() |
๐ฏ | query.limit() |
๐ฏ | query.slice() |
โ | query.between() |
๐ฏ | query.merge() |
๐ฏ | query.pluck() |
query.without() |
|
query.replace() |
|
query.update() |
|
query.delete() |
|
๐ฏ | query.default() |
๐ฏ | query.and() |
๐ฏ | query.or() |
query.eq() |
|
query.ne() |
|
query.gt() |
|
query.lt() |
|
query.ge() |
|
query.le() |
|
query.add() |
|
query.sub() |
|
query.mul() |
|
๐ฏ | query.div() |
โ | query.mod() |
โ | query.sum() |
โ | query.avg() |
โ | query.min() |
โ | query.max() |
โ | query.not() |
โ | query.ceil() |
โ | query.floor() |
โ | query.round() |
โ | query.random() |
โ | query.coerceTo() |
๐ฏ | query.map() |
query.filter() |
|
โ | query.fold() |
โ | query.reduce() |
โ | query.forEach() |
โ | query.distinct() |
โ | query.concatMap() |
โ | query.innerJoin() |
โ | query.outerJoin() |
โ | query.eqJoin() |
โ | query.zip() |
โ | query.group() |
โ | query.ungroup() |
โ | query.sample() |
โ | query.setInsert() |
โ | query.setUnion() |
โ | query.setIntersection() |
โ | query.setDifference() |
โ | query.append() |
โ | query.prepend() |
โ | query.union() |
โ | query.difference() |
โ | query.insertAt() |
โ | query.spliceAt() |
โ | query.deleteAt() |
โ | query.changeAt() |
โ | query.keys() |
โ | query.values() |
โ | query.literal() |
โ | query.match() |
โ | query.split() |
โ | query.upcase() |
โ | query.downcase() |
โ | query.toJSON() or query.toJsonString() |
โ | query.info() |
โ | query.sync() |
Any contribution goes a long way for making this library more reliable.
Issues and pull requests are always appreciated! ๐
The implementation is relatively simple, but if you have any questions, feel free to open an issue.
You can help expose edge cases by writing tests!
# This tool compiles the `src` directory during `npm install`.
npm install -g coffee-build
# You can include `-b unstable` for the latest changes.
git clone https://github.com/aleclarson/rethinkdb-mock
# Install dependencies.
npm install
# Manually compile the `src` directory after you make any changes.
coffee -cb -o js src
- JohanObrink/rethink-mock: Stubs for
sinon
(last updated August 2016) - vasc/rethinkdb-mock: Small subset of Rethink API, not spec-compliant (last updated April 2014)