All Projects → rrdelaney → ava-rethinkdb

rrdelaney / ava-rethinkdb

Licence: MIT license
🔗 RethinkDB helpers for AVA

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ava-rethinkdb

Opendominion
A text-based, persistent browser-based strategy game (PBBG) in a fantasy war setting
Stars: ✭ 155 (+545.83%)
Mutual labels:  magic
Magic
Create your .Net Core/Angular/Database CRUD Web apps by simply clicking a button
Stars: ✭ 214 (+791.67%)
Mutual labels:  magic
leto
Leto: Realtime Application Stack [Angualr2, Rethinkdb/Horizon, ExpressJS] Web | Mobile | Desktop
Stars: ✭ 21 (-12.5%)
Mutual labels:  rethinkdb
Z.js
🦄 Hide text via Unicode's ZW(N)Js
Stars: ✭ 161 (+570.83%)
Mutual labels:  magic
Aegis.cpp
Discord C++ library for interfacing with the API. Join our server:
Stars: ✭ 198 (+725%)
Mutual labels:  magic
revue
Revue provides a helpful interface for testing Vue components
Stars: ✭ 16 (-33.33%)
Mutual labels:  ava
Mlv App
All in one MLV processing app that is pretty great. Download:
Stars: ✭ 150 (+525%)
Mutual labels:  magic
Unicopia
The pony powers mod to power in your pony pony pony
Stars: ✭ 42 (+75%)
Mutual labels:  magic
Abracadabra
Automated refactorings for VS Code (JS & TS) ✨ It's magic ✨
Stars: ✭ 204 (+750%)
Mutual labels:  magic
vue-boilerplate
An opinionated Vue.js 2 boilerplate with Vue Router, AVA and Istanbul
Stars: ✭ 27 (+12.5%)
Mutual labels:  ava
File Type
Detect the file type of a Buffer/Uint8Array/ArrayBuffer
Stars: ✭ 2,386 (+9841.67%)
Mutual labels:  magic
Mtgjson
MTGJSON build scripts for Magic: the Gathering
Stars: ✭ 191 (+695.83%)
Mutual labels:  magic
discover-videos
This app is a clone of Netflix app, check out the course http://bit.ly/nextjs-udemy-ankita on how to build this
Stars: ✭ 81 (+237.5%)
Mutual labels:  magic
Hitrava
Convert your Huawei Health sport activities and import them in Strava.
Stars: ✭ 156 (+550%)
Mutual labels:  magic
docker-credential-magic
A magic shim for Docker credential helpers 🪄
Stars: ✭ 56 (+133.33%)
Mutual labels:  magic
Tangram
WebGL map rendering engine for creative cartography
Stars: ✭ 1,964 (+8083.33%)
Mutual labels:  magic
Openram
An open-source static random access memory (SRAM) compiler.
Stars: ✭ 239 (+895.83%)
Mutual labels:  magic
mtgjson-website
MTGJSON Documentation Front-End Application built with Vuepress 1
Stars: ✭ 29 (+20.83%)
Mutual labels:  magic
react-facebook-friends
👍Web app to rank, quantify your FaceBook friendship with React
Stars: ✭ 26 (+8.33%)
Mutual labels:  ava
perseus
Perseus is a set of scripts (docker+javascript) to investigate a distributed database's responsiveness when one of its three nodes is isolated from the peers
Stars: ✭ 49 (+104.17%)
Mutual labels:  rethinkdb

Testing utilities for RethinkDB and AVA

ava-rethinkdb on NPM Build Status See package.json for Node.js Support

npm install --save-dev ava-rethinkdb

This is a hacky way of using the NodeJS RethinkDB and AVA together. It uses undocumented features of the RethinkDB driver, and should be considered experimental.

Basic Testing

By running init and cleanup you get a fully managed database instance for your tests! Everything is cleaned up at the end, so there's no leftover fixtures

import test from 'ava'
import { init, cleanup } from 'ava-rethinkdb'

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

test('I should have a RethinkDB instance', async t => {
  let connection = await r.connect({})

  await r.dbCreate('MyDatabase')
})

Seeding

The problem is that if you want to do multiple tests they all happen at the same time due to the magic of AVA. Luckily you can seed the database with a simple JSON structure

import test from 'ava'
import { init, cleanup } from 'ava-rethinkdb'

const TEST_DATA = {
  my_database: { // The top level is the database to create
    my_table: [ // Next is a table in the database. This holds an array of documents to insert
      { name: 'A', value: 1},
      { name: 'B', value: 2}
    ],
    users: [
      { username: 'daniel', email: '[email protected]' },
      { username: 'heya', email: '[email protected]' }
    ]
  }
}

test.before(init(TEST_DATA))
test.after.always(cleanup)

test('These documents should exist', async t => {
  let conn = await r.connect({ db: 'my_database' })
  let results = await r.table('my_table').run(conn)
  let data = await results.toArray()

  console.log(data)
  t.truthy(data)
})

Different Database Instances

This is where the magic really is. Every single test file is given its own RethinkDB instance. This makes it perfect for integration tests against endpoints, because now they can all be used in parallel! The magic comes from modifying the default port the driver looks at, making it different in each process, then spinning up a RethinkDB instance at that port. Check out the test directory for a good example.

// app.js

const express = require('express')
const r = require('rethinkdb')

let app = express()

app.get('/users', (req, res) => {
  r.connect({ db: 'app' })
    .then(conn => r.table('users').run(conn))
    .then(results => results.toArray())
    .then(users => res.status(200).send({ users }))
    .catch(e => res.status(500).send(e))
})

module.exports = { app }
// test/integration/users-test-1.js
import test from 'ava'
import request from 'supertest-as-promised'
import { init, cleanup } from 'ava-rethinkdb'

import { app } from '../../app.js'

const TEST_DATA = {
  app: {
    users: [
      { name: 'UserA' },
      { name: 'UserB' }
    ]
  }
}

test('Users should be returned from /users', t => {
  return request(app)
    .get('/users')
    .expect(200)
})
// test/integration/users-test-2.js
import test from 'ava'
import request from 'supertest-as-promised'
import { init, cleanup } from 'ava-rethinkdb'

import { app } from '../../app.js'

const TEST_DATA = {
  app: {
    users: [
      { name: 'UserC' },
      { name: 'UserD' }
    ]
  }
}

test('Different users should be returned from /users', t => {
  return request(app)
    .get('/users')
    .expect(200)
})

The TEST_DATA contained in each file creates a new database to be used for each file!

Debugging

To view the output from all the server logs, set the environment variable AVA_RETHINKDB_DEBUG=on

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].