Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(init): mock pouchdb
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Nov 30, 2019
1 parent e6c262a commit 7373e8d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"i18next-browser-languagedetector": "^4.0.1",
"i18next-xhr-backend": "^3.2.2",
"pouchdb": "~7.1.1",
"pouchdb-adapter-memory": "^7.1.1",
"react": "~16.12.0",
"react-bootstrap": "^1.0.0-beta.16",
"react-dom": "~16.12.0",
Expand Down Expand Up @@ -62,6 +63,8 @@
"cross-env": "~6.0.3",
"cz-conventional-changelog": "~3.0.2",
"dateformat": "~3.0.3",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.15.1",
"eslint": "~6.6.0",
"eslint-config-airbnb": "~18.0.1",
"eslint-config-prettier": "~6.5.0",
Expand All @@ -74,16 +77,17 @@
"husky": "~3.0.5",
"jest": "~24.9.0",
"lint-staged": "~9.5.0",
"memdown": "^5.1.0",
"prettier": "~1.19.1",
"semantic-release": "~15.13.24"
"semantic-release": "~15.13.24",
"ts-jest": "^24.2.0"
},
"scripts": {
"commit": "npx git-cz",
"start": "react-scripts start",
"build": "react-scripts build",
"prepublishOnly": "npm run build",
"pretest": "npm run lint && npm run build",
"test": "react-scripts test",
"test": "react-scripts test --detectOpenHandles",
"test:ci": "cross-env CI=true react-scripts test",
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\" --fix",
"coveralls": "jest --coverage --coverageReporters=text-lcov | coveralls",
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '../__mocks__/matchMediaMock'
import React from 'react'
import ReactDOM from 'react-dom'
import { mount } from 'enzyme'
import HospitalRun from '../containers/HospitalRun'
import App from '../App'

it('renders without crashing', () => {
const div = document.createElement('div')
ReactDOM.render(<App />, div)
ReactDOM.unmountComponentAtNode(div)
const wrapper = mount(<App />)
expect(wrapper.find(HospitalRun)).toHaveLength(1)
})
38 changes: 25 additions & 13 deletions src/config/pouchdb.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import PouchDB from 'pouchdb'

export const patients = new PouchDB('patients')
PouchDB.sync(
'patients',
'https://a27fa3db-db4d-4456-8465-da953aee0f5b-bluemix:cd6f332d39f24d2b7cfc89d82f6836d46012ef3188698319b0d5fff177cb2ddc@a27fa3db-db4d-4456-8465-da953aee0f5b-bluemix.cloudantnosqldb.appdomain.cloud/patients',
// IBM Cloudant testing and developing database
{
live: true,
retry: true,
},
).on('change', (info) => {
// handle change
console.log(info)
})
// eslint-disable-next-line
const memoryAdapter = require('pouchdb-adapter-memory')

PouchDB.plugin(memoryAdapter)

function createDb(name: string) {
if (process.env.NODE_ENV === 'test') {
return new PouchDB(name, { adapter: 'memory' })
}

const db = new PouchDB(name)
db.sync(
`https://a27fa3db-db4d-4456-8465-da953aee0f5b-bluemix:cd6f332d39f24d2b7cfc89d82f6836d46012ef3188698319b0d5fff177cb2ddc@a27fa3db-db4d-4456-8465-da953aee0f5b-bluemix.cloudantnosqldb.appdomain.cloud/${name}`,
{
live: true,
retry: true,
},
).on('change', (info) => {
console.log(info)
})

return db
}

export const patients = createDb('patients')
5 changes: 5 additions & 0 deletions src/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

Enzyme.configure({ adapter: new Adapter() })

0 comments on commit 7373e8d

Please sign in to comment.