MockReduce
所属分类:大数据
开发工具:JavaScript
文件大小:0KB
下载次数:0
上传日期:2021-05-09 04:35:00
上 传 者:
sh-1993
说明: mongodbs mongoose的mapReduce的模拟,以实现可测试性,
(A mock for mongodbs mongoose s mapReduce in order to achieve testability,)
文件列表:
.nvmrc (3, 2019-11-12)
.travis.yml (47, 2019-11-12)
index.js (512, 2019-11-12)
karma.conf.js (1353, 2019-11-12)
package-lock.json (9805, 2019-11-12)
package.json (730, 2019-11-12)
spec/ (0, 2019-11-12)
spec/helpers/ (0, 2019-11-12)
spec/helpers/require-uncached.js (112, 2019-11-12)
spec/integration/ (0, 2019-11-12)
spec/integration/index-spec.js (779, 2019-11-12)
spec/integration/mongoose-spec.js (2179, 2019-11-12)
spec/src/ (0, 2019-11-12)
spec/src/installer-spec.js (7377, 2019-11-12)
spec/src/map-spec.js (3199, 2019-11-12)
spec/src/mock-reduce-spec.js (9306, 2019-11-12)
spec/src/reduce-spec.js (1950, 2019-11-12)
spec/src/scope-spec.js (2093, 2019-11-12)
spec/support/ (0, 2019-11-12)
spec/support/jasmine.json (111, 2019-11-12)
src/ (0, 2019-11-12)
src/installer.js (3584, 2019-11-12)
src/map.js (2953, 2019-11-12)
src/mock-reduce.js (3115, 2019-11-12)
src/reduce.js (1067, 2019-11-12)
src/scope.js (1479, 2019-11-12)
[![Build Status](https://travis-ci.org/djungowski/MockReduce.svg?branch=master)](https://travis-ci.org/djungowski/MockReduce)
# MockReduce
A mock for mongodbs/mongoose's mapReduce in order to achieve testability
## Installation
```bash
npm install mock-reduce
```
## Usage
```javascript
var mockReduce = require('mock-reduce');
```
So far I have only tested implementations with [node for jasmine](http://jasmine.github.io/2.2/node.html). Generally it should work with any other testing framework.
## Using MockReduce with mongoose
```javascript
var mongoose = require('mongoose');
var mockReduce = require('mock-reduce');
describe('Mongoose Test', function() {
it('runs a mock reduce and returns the expected data', function() {
var testData = [
{"someId": 42, "someString": "Chickens don't clap!", "value": 4},
{"someId": 5, "someString": "I'm on the job.", "value": 5},
{"someId": 42, "someString": "Annyong", "value": 8},
{"someId": 5, "someString": "Come on, this is a Bluth family celebration.", "value": 5}
];
var reducedData = [
{"_id": 5, value: 10},
{"_id": 42, value: 12}
];
mockReduce.install(mongoose);
mockReduce.setNextTestData(testData);
var model = require('./models/myModel');
var result = model.someMethodThatCallsMapReduce();
expect(result).toEqual(reducedData);
mockReduce.uninstall();
});
});
```
See file [spec/integration/mongoose-spec.js](https://github.com/djungowski/MockReduce/blob/master/spec/integration/mongoose-spec.js) for an extended test example
## Using mockReduce with with node-mongodb-native
__Caution: This feature is still work in progress. Generally it should work, I haven't fully tested it yet__
```javascript
var mongodb = require('mongodb');
var mockReduce = require('mock-reduce');
describe('node-mongodb-native Test', function() {
it('runs a mock reduce and returns the expected data', function() {
var testData = [
{"someId": 42, "someString": "Chickens don't clap!", "value": 4},
{"someId": 5, "someString": "I'm on the job.", "value": 5},
{"someId": 42, "someString": "Annyong", "value": 8},
{"someId": 5, "someString": "Come on, this is a Bluth family celebration.", "value": 5}
];
var reducedData = [
{"_id": 5, value: 10},
{"_id": 42, value: 12}
];
mockReduce.install(mongodb);
mockReduce.setNextTestData(testData);
mongodb.connect('mongodb://localhost:27017/test', function(err, db) {
var collection = db.collection('collection_name');
var map = function() {...}
var reduce = function() {...}
var options = {
scope: {
additional: 'variable'
}
};
var result = collection.mapReduce(map, reduce, options);
});
expect(result).toEqual(reducedData);
mockReduce.uninstall();
});
});
```
## Available methods
MockReduce stores almost every step of a map reduce operation. Try one of the following methods:
```javascript
mockReduce.map.getEmits();
mockReduce.map.getMappedData();
mockReduce.reduce.getReducedData();
```
## Supported methods
So far the following methods are supported:
- map
- reduce
- finalize
- scope
- done callback
## Running MockReduce's own tests
MockReduce was completely developed test-driven. If you wish to run its own tests, clone the git repo and run
```bash
npm install
npm test
```
## Changelog
### 0.1.0
- Security: Fix security vulnerabilities in mongoose and karma dependencies
- Change: Do not put MockReduce and all subclasses into global scope but instead use require
- Bugfix: Make sure index.js is required uncached in tests
- Update: Bump mongoose to version 5.7.10
- Update: Bump jasmine to version 3.5.0
### 0.0.5
- Bugfix: Don't break when connect is called without a callback
### 0.0.4
- Install does not break the original connector when running twice
### 0.0.3
- Fixed "window is not defined" issue
### 0.0.2
- MockReduce can now be used directly within node itself (PhantomJS not needed anymore)
近期下载者:
相关文件:
收藏者: