Giter Club home page Giter Club logo

rethinkdb-mock's Introduction

rethinkdb-mock v0.6.0

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.


Why use this?

  • 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

Getting started

  1. Install from Github:
npm install --save-dev rethinkdb-mock
  1. 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
})
  1. 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...
})

Feature support

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()

Contribution

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!

Getting started

# 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

Similar repositories

rethinkdb-mock's People

Contributors

aleclarson avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.