refactor mapreduce tests with async/await#9176
refactor mapreduce tests with async/await#9176emilygilberts wants to merge 12 commits intoapache:masterfrom
Conversation
There was a problem hiding this comment.
this looks good overall, I’m just wondering if it would make sense to DRY out the get and put functions a little bit, it’s three lines each when the only difference is the what the promise resolves with.
Spitballing here:
instead of
const res = await upsert(
{
get: function () {
return Promise.reject({ status: 404 });
},
put: function () {
return Promise.resolve({ rev: 'abc' });
},
},
'foo',
function () {
return { difference: "something" };
},
);function makeFun (action, value) {
return function() { return Promise[action](value) };
}
// [...]
const res = await upsert(
{
get: makeFun('resolve', {status: 404}),
put: makeFun('reject', { rev: 'abc' }),
},
'foo',
function () { return { difference: "something" };
},
);Might be too fancy, feel free to shoot me down :)
tests/unit/test.mapreduce.js
Outdated
| it('should throw an error if the doc errors', async function () { | ||
| try { | ||
| await upsert( | ||
| { |
There was a problem hiding this comment.
just a style nit, but I’d be okay with having the opening curlies start with the method: upsert({ to save a mostly empty line
|
@janl hmm how about using arrow functions for the functions in get and put? I think it could look neat/be readable cause they are all one liners. |
3dd1915 to
f1a1b9c
Compare
|
hmm wondering - in some tests we had promise chains that did multiple queries that returned |
| await db.bulkDocs(docs); | ||
|
|
||
| const queryFun = await createView(db, { | ||
| map: doc => emit(doc._id) |
There was a problem hiding this comment.
Actually, could it be a problem in some setups that I changes the map function to an arrow function? It will be converted to a string in the createView function:
const storableViewObj = {
map: `${viewObj.map}`
};
There was a problem hiding this comment.
should be fine in tests, but lets leave them in their CouchDB-canonical traditional function form

tests/unit
mapreduce.js-upsertusingasync/await(left the
mapreduce.js-utilstests as they are, because they are more readable & straightforward with the current syntax)tests/mapreduce (in process)
should.becometoshould.deep.equalfor objects orshould.be.truefor boolean).toString()with template literals (except on view map function declarations)tests/mapreduce/test.mapreduce.js
in test Query result should include _conflicts and Views should include conflicts :
testUtils.fin()withtry/finally blockpromisifywith simply awaiting the replication - so thattestUtils.promisify(remote, db.replicate);becomesawait db.replicate.from(remote);in test Test view querying with custom reduce function:
values.flat()keyId[0]//const id = keyId[1];be deleted?