chris-l / mock-couch Goto Github PK
View Code? Open in Web Editor NEWA node.js module designed to mock a CouchDB server, mostly for unit testing purposes.
Home Page: http://chris-l.github.io/mock-couch/
A node.js module designed to mock a CouchDB server, mostly for unit testing purposes.
Home Page: http://chris-l.github.io/mock-couch/
Thanks! this is something I really needed today, but unfortunately couldn't make it work with yarn
(not that I tried npm
actually)
This is the error I am getting when I require the modue:
{ Error: Cannot find module './build/Release/DTraceProviderBindings'
at Function.Module._resolveFilename (module.js:489:15)
at Function.Module._load (module.js:439:25)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/z/dev/x/node_modules/bunyan/node_modules/dtrace-provider/dtrace-provider.js:18:23)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3) code: 'MODULE_NOT_FOUND' }
TAP version 13
# deploy
util.js:988
throw new TypeError('The super constructor to "inherits" must not ' +
^
TypeError: The super constructor to "inherits" must not be null or undefined
at Object.inherits (util.js:988:11)
at Object.<anonymous> (/Users/z/dev/x/node_modules/spdy/lib/spdy/connection.js:86:6)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/z/dev/x/node_modules/spdy/lib/spdy.js:20:19)
This would be ignored because it causes the repo to install whatever version of restify in it.
restify is currently 6.4.3 but npm-shrinkwrap.json still refers to 2.8.5.
Great work!
Support in _show and _list functions would be lovely.
Thanks :)
Thanks for the great library. I've been looking for something like this for a while!
The docs clearly show that views are supported using addDoc, but it doesn't appear that updates
functions are supported when I add design docs that have update handlers in them. We use update handlers to add simple timestamps to our docs. Am I doing something wrong, or is this feature just not supported yet.
Are update handlers a feature that you'd consider supporting, if they don't work already?
I seem to be getting the following errors when trying to create a new mockCouch server.
var mockCouch = require('mock-couch');
var couchdb = mockCouch.createServer();
{ [Error: Cannot find module './build/Release/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/default/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/Debug/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
Any ideas what would be causing this?
{"statusCode":400,"error":"Bad Request","message":"Name: 'm/6f23be18595c4164a575d768b2121043'. Only lowercase characters (a-z), digits (0-9), and any of the characters _, $, (, ), +, -, and / are allowed. Must begin with a letter."}
https://github.com/shotclip-team/mockcouch
POST event not happening?
I'm having a problem with node crashing when I require mock-couch.
package.json
{
"dependencies": {
"mock-couch": "0.1.10"
}
}
test.js
require('mock-couch');
bash> node test.js
#
# Fatal error in ../deps/v8/src/api.cc, line 1248
# Check failed: !value_obj->IsJSReceiver() || value_obj->IsTemplateInfo().
#
Illegal instruction: 4
bash> npm list
/Users/chris/projects/rmc/test
└─┬ [email protected]
├── [email protected] extraneous
├── [email protected]
├── [email protected] extraneous
├── [email protected] extraneous
├── [email protected] extraneous
├── [email protected]
├─┬ [email protected] invalid
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ ├── [email protected] extraneous
│ └── [email protected] extraneous
└── [email protected]
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/color-convert
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/grunt
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/grunt-jasmine-nodejs
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/grunt-jslint
npm ERR! invalid: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/restify
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/assert-plus
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/backoff
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/bunyan
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/csv
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/deep-equal
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/dtrace-provider
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/escape-regexp-component
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/formidable
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/http-signature
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/keep-alive-agent
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/lru-cache
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/mime
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/negotiator
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/node-uuid
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/once
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/qs
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/semver
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/spdy
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/tunnel-agent
npm ERR! extraneous: [email protected] /Users/chris/projects/rmc/test/node_modules/mock-couch/node_modules/verror
I wonder if the problem is related to [email protected] invalid
? I'm not sure what that means.
I need to fill CouchDB mock database with documents with attachments
Is there possible to upload attachment in batch mode?
Have methods addDB
and addDoc
support?
If not: have you plan/time to implement this feature?
Alternative: Is there possible to use couch-push with together with mock-couch
?
One of my tests broke today and it was because I was using sum function.
Reference of built-in reduce functions: https://wiki.apache.org/couchdb/Built-In_Reduce_Functions .
After e67a594, you get {"statusCode":404,"error":"Not Found","message":"no_db_file"}
when trying to PUT a new database.
There'd need to be some kind of request injection for the project to be able to catch this with a test.
After creating a new database via HTTP save_doc throws an exception when trying to save a new document into it.
TypeError: Cannot read property 'push' of undefined
at Server.<anonymous> (.../node_modules/mock-couch/lib/save_doc.js:43:29)
Weird error when I execute test with gulp or npm:
Here the sample of code from my test:
const mockCouch = require('mock-couch');
let couchdbMock;
describe('TEST', function() {
before(function() {
couchdbMock = mockCouch.createServer();
couchdbMock.listen(5985);
});
// unit tests
I got this error comming from the line of code: couchdbMock = mockCouch.createServer();
:
TypeError: The super constructor to "inherits" must not be null or undefined
at Object.exports.inherits (util.js:989:11)
at Object.<anonymous> (node_modules/spdy/lib/spdy/connection.js:86:6)
at require (internal/module.js:20:19)
at Object.<anonymous> (node_modules/spdy/lib/spdy.js:20:19)
at require (internal/module.js:20:19)
at Object.<anonymous> (node_modules/restify/lib/server.js:13:12)
at require (internal/module.js:20:19)
at Object.createServer (node_modules/restify/lib/index.js:95:18)
at node_modules/mock-couch/index.js:122:25
at Object.createServer (node_modules/mock-couch/index.js:158:6)
at Context.<anonymous> (server/dao/dao.couchdb.spec.js:18:33)
The weird thing is I get this error when I execute the test with Gulp or npm, but I do not get any errors when I use mocha commands directly.
Are you planing to support CouchDB 2.* as well?
This issue might not be related to mock-couch but I would appreciate some help. I am getting this error when running a simple test (let me know if you need the complete log):
TypeError: The super constructor to "inherits" must not be null or undefined
at Object.inherits (util.js:971:11)
at Object.<anonymous> (node_modules\mock-couch\node_modules\spdy\lib\spdy\connection.js:86:6)
This is my simple test (I have deleted some lines; mockedUsers is a simple JSON object):
(function mockConnection(module, require) {
'use strict';
const path = require('path');
const root = path.resolve('./');
const mockedUsers = require(`${root}/mocks/users`);
const should = require('should');
const mock = require('mock-couch');
describe('Mock couch connection', function mockCouchConnection() {
let Users;
let mockCouch;
const port = 5984;
const uid = '[email protected]';
beforeEach(function beforeEach() {
mockCouch = mock.createServer({ keepAlive: false, });
mockCouch.listen(port, function mockCouchListen() {
// does nothing... yet!
});
// This creates a db for Mock Couch. The db is nothing but an array of objects.
// If we provide an object with an _id property, it will use it. Otherwise, it will create a random one.
Users = mockCouch.addDB('users', mockedUsers);
});
it(`user ${uid} must exist`, function userMustExists(done) {
// TODO: validate that user actually exists.
done();
});
});
}(module, require));
The error happens at this line mockCouch = mock.createServer({ keepAlive: false, });
. I have run the code in different Nodejs versions, including 8.4.0, 8.8.0, 7.10.0.
Thanks!
Hi there,
Can somebody publish the fix in 'Add put/post for design docs #42' to npm package?
The latest 0.1.6 version of npm package was published 6 month ago and doesn't have this fix.
Really look forward to seeing the npm package include this fix, rather than install from git for the specific version.
Thanks very much.
I'm talking about this block https://github.com/chris-l/mock-couch/blob/8793eeff62cd5e8e2d698a760f55469d99fcfac5/lib/query_options.js#L86-90 .
It maps elements of keys array to exactly one match from rows array.
Edit: The first two comments are more me trying to figure out what's happening. It's good reading, but I think I've come closer to nailing down part of the problem in the third post (as well as the referenced commit to my fork just above it)
Having a bit of a problem with the order some documents are spit out versus what they do on a real couch-db instance. It's going to not look super clear, but I hope to illustrate the issue I'm having. I can try to provide sample data tomorrow if necessary. Here is the map function:
function (doc) {
if (doc.docType === 'foo') {
key = [];
key.push(doc._id);
emit(key);
}
if (doc.docType === 'rel:bar') {
key = [];
key.push(doc.fooId);
key.push(doc.barId);
emit(key, { _id: doc.barId });
}
if ((doc.docType === 'rel:baz') && (doc.path.length === 2)) {
key = [];
key.push(doc.fooId);
key.push(doc.barId);
key.push(doc.path);
emit(key, { _id: doc.bazId });
}
}
What this effectively does is spit out a three level hierarchy of some documents we have.
What I want, and what seems to work very consistently on our real instance, is:
foo
bar
baz
foo
bar
baz
bar
baz
etc.
However, in test, foo does not come first. Therefore when we try to construct this hierarchy in flat, descending order, it fails because there was no foo before bar, or baz. It appears the foos come last. I've tried messing with the descending order flags on a view with no luck.
Like I said, it works on our real instance, but now that it doesn't work in our unit tests I'm second guessing the whole thing :/
let mockCouch = mock.createServer();
TypeError [ERR_INVALID_ARG_TYPE]: The "superCtor" argument must be of type Function. Received type undefined
at Object.inherits (util.js:1203:11)
at Object. (C:\Users\TEJINDERSINGH\Projects\isc-common-configstore\configstorev1\node_modules\mock-couch\node_modules\spdy\lib\spdy\connection.js:86:6)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
Regression introduced in 8486e7b
TypeError: Cannot read property '_id' of null
at global.emit (/.../node_modules/mock-couch/lib/get_view.js:43:30)
When I run mock-couch I get an error:
Stacktrace:
TypeError: Object #<Object> has no method 'createsrv'
at node_modules/mock-couch/index.js:21:23
I think it was introduced in this commit:
590c1e4#diff-168726dbe96b3ce427e7fedce31bb0bcR21
Should be a quick fix!
Just came across this project, I am so glad this exists. Anything that requires having more than one couch becomes real annoying to test. Specifically I've been wanting something like this in order to write some tests for overwatch
. I'd love to help out with a basic _changes
implementation when I have some bandwidth. Let me know if this interests you :).
I seem to be getting a 405 PUT not allowed error when trying to insert a design document;
{ [Error: PUT is not allowed]
name: 'Error',
statusCode: 405,
body: { code: 'MethodNotAllowedError', message: 'PUT is not allowed' },
scope: 'couch',
request:
{ method: 'PUT',
headers:
{ 'content-type': 'application/json',
accept: 'application/json' },
[...]
I'm simply doing the following with nano after creating a database:
var design = {
"views": {
"all": {
map: function(doc) {
if (doc._id) emit(doc._id, doc);
}
}
}
};
db.insert(design, '_design/tweets', function(err, res) {
if (err) return console.log(err);
console.log('Inserted!');
});
This gives the correct response when using a real couchdb database, but seems to fail when using mock-couch
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.