You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pouchdb.apache.org by "emilygilberts (via GitHub)" <gi...@apache.org> on 2026/02/19 16:20:44 UTC
[PR] rewrite mapreduce upsert tests with async/await [pouchdb]
emilygilberts opened a new pull request, #9176:
URL: https://github.com/apache/pouchdb/pull/9176
- rewrote the unit tests for `mapreduce.js-upsert` using `async/await`
(left the `mapreduce.js-utils` tests as they are, because they are more readable & straightforward with the current syntax)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pouchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor mapreduce tests with async/await [pouchdb]
Posted by "emilygilberts (via GitHub)" <gi...@apache.org>.
emilygilberts commented on code in PR #9176:
URL: https://github.com/apache/pouchdb/pull/9176#discussion_r3027810159
##########
tests/mapreduce/test.mapreduce.js:
##########
@@ -1335,71 +1225,69 @@ function tests(suiteName, dbName, dbType, viewType) {
}
});
}
- return db.bulkDocs(docs).then(function () {
- return createView(db, {
- map: function (doc) {
- emit(doc._id);
+ await db.bulkDocs(docs);
+
+ const queryFun = await createView(db, {
+ map: doc => emit(doc._id)
Review 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.toString()
map: `${viewObj.map}`
};
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pouchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] rewrite mapreduce upsert tests with async/await [pouchdb]
Posted by "janl (via GitHub)" <gi...@apache.org>.
janl commented on code in PR #9176:
URL: https://github.com/apache/pouchdb/pull/9176#discussion_r2832225162
##########
tests/unit/test.mapreduce.js:
##########
@@ -6,63 +6,81 @@ var upsert = PouchDB.utils.upsert;
var utils = PouchDB.utils.mapReduceUtils;
describe('test.mapreduce.js-upsert', function () {
- it('should throw an error if the doc errors', function () {
- return upsert({
- get: function () {
- return Promise.reject(new Error('a fake error!'));
- }
- }, 'foo')
- .then(function () {
+ it('should throw an error if the doc errors', async function () {
+ try {
+ await upsert(
+ {
Review 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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pouchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor mapreduce tests with async/await [pouchdb]
Posted by "emilygilberts (via GitHub)" <gi...@apache.org>.
emilygilberts commented on PR #9176:
URL: https://github.com/apache/pouchdb/pull/9176#issuecomment-4397750011
The test `should handle many doc changes` is here twice, with the difference that the second one uses `expectedResponseKeys.sort((a, b)=> a - b) `whilst the first one only uses `expectedResponseKeys.sort();`the second one is correct, cause it sorts numerically, can i remove the first test that sorty alphabetically? it looks like someone added the second one to correct the first and forgot to delete it, or am I missing something?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pouchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor mapreduce tests with async/await [pouchdb]
Posted by "emilygilberts (via GitHub)" <gi...@apache.org>.
emilygilberts commented on PR #9176:
URL: https://github.com/apache/pouchdb/pull/9176#issuecomment-4126786962
I'm running the tests locally with `TYPE=mapreduce npm run test-node`. Any idea why they all pass for `test.mapreduce.js-persisted`, but for `test.mapreduce.js-temp` the first test executed jumps out with a timeout error?
<img width="975" height="155" alt="Bildschirmfoto 2026-03-25 um 14 51 41" src="https://github.com/user-attachments/assets/a031ec12-7818-4b05-b92d-7a1bfa8370ba" />
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pouchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor mapreduce tests with async/await [pouchdb]
Posted by "janl (via GitHub)" <gi...@apache.org>.
janl commented on code in PR #9176:
URL: https://github.com/apache/pouchdb/pull/9176#discussion_r3334726847
##########
tests/mapreduce/test.mapreduce.js:
##########
@@ -12,134 +12,122 @@ viewTypes.forEach(function (viewType) {
function tests(suiteName, dbName, dbType, viewType) {
- describe(suiteName, function () {
+ describe(suiteName, () => {
let createView;
if (dbType === 'http' || viewType === 'persisted') {
- createView = function (db, viewObj) {
+ createView = async (db, viewObj) => {
const storableViewObj = {
- map: viewObj.map.toString()
+ map: `${viewObj.map}`
};
if (viewObj.reduce) {
- storableViewObj.reduce = viewObj.reduce.toString();
+ storableViewObj.reduce = `${viewObj.reduce}`;
}
- return new Promise(function (resolve, reject) {
- db.put({
- _id: '_design/theViewDoc',
- views: {
- 'theView' : storableViewObj
- }
- }, function (err) {
- if (err) {
- reject(err);
- } else {
- resolve('theViewDoc/theView');
- }
- });
+
+ await db.put({
+ _id: '_design/theViewDoc',
+ views: {
+ 'theView' : storableViewObj
+ }
});
+ return 'theViewDoc/theView';
};
} else {
- createView = function (db, viewObj) {
- return new Promise(function (resolve) {
- setTimeout(function () {
- resolve(viewObj);
- });
- });
+ createView = async (db, viewObj) => {
+ await Promise.resolve();
Review Comment:
would making the function here async not already defer execution, or do we want to do an extra round of that in this context?
##########
tests/mapreduce/test.mapreduce.js:
##########
@@ -12,134 +12,122 @@ viewTypes.forEach(function (viewType) {
function tests(suiteName, dbName, dbType, viewType) {
- describe(suiteName, function () {
+ describe(suiteName, () => {
let createView;
if (dbType === 'http' || viewType === 'persisted') {
- createView = function (db, viewObj) {
+ createView = async (db, viewObj) => {
const storableViewObj = {
- map: viewObj.map.toString()
+ map: `${viewObj.map}`
};
if (viewObj.reduce) {
- storableViewObj.reduce = viewObj.reduce.toString();
Review Comment:
in general I think we’d prefer a function call over manual string interpolation, but maybe I am missing a particular reason for this change here?
##########
tests/mapreduce/test.mapreduce.js:
##########
@@ -12,134 +12,122 @@ viewTypes.forEach(function (viewType) {
function tests(suiteName, dbName, dbType, viewType) {
- describe(suiteName, function () {
+ describe(suiteName, () => {
let createView;
if (dbType === 'http' || viewType === 'persisted') {
- createView = function (db, viewObj) {
+ createView = async (db, viewObj) => {
const storableViewObj = {
- map: viewObj.map.toString()
+ map: `${viewObj.map}`
};
if (viewObj.reduce) {
- storableViewObj.reduce = viewObj.reduce.toString();
+ storableViewObj.reduce = `${viewObj.reduce}`;
}
- return new Promise(function (resolve, reject) {
- db.put({
- _id: '_design/theViewDoc',
- views: {
- 'theView' : storableViewObj
- }
- }, function (err) {
- if (err) {
- reject(err);
- } else {
- resolve('theViewDoc/theView');
- }
- });
+
+ await db.put({
+ _id: '_design/theViewDoc',
+ views: {
+ 'theView' : storableViewObj
+ }
});
+ return 'theViewDoc/theView';
};
} else {
- createView = function (db, viewObj) {
- return new Promise(function (resolve) {
- setTimeout(function () {
- resolve(viewObj);
- });
- });
+ createView = async (db, viewObj) => {
+ await Promise.resolve();
+ return viewObj;
};
}
- beforeEach(function () {
+ beforeEach(async () => {
if (dbType === 'http') {
const url = new URL(dbName);
const dbUrl = `${url.origin}${url.pathname}`;
- return PouchDB.fetch(dbUrl + '?q=1', {
+ await PouchDB.fetch(dbUrl + '?q=1', {
Review Comment:
no need to await, we can just return the `fetch` promise as before.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pouchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor mapreduce tests with async/await [pouchdb]
Posted by "emilygilberts (via GitHub)" <gi...@apache.org>.
emilygilberts commented on code in PR #9176:
URL: https://github.com/apache/pouchdb/pull/9176#discussion_r3027810159
##########
tests/mapreduce/test.mapreduce.js:
##########
@@ -1335,71 +1225,69 @@ function tests(suiteName, dbName, dbType, viewType) {
}
});
}
- return db.bulkDocs(docs).then(function () {
- return createView(db, {
- map: function (doc) {
- emit(doc._id);
+ await db.bulkDocs(docs);
+
+ const queryFun = await createView(db, {
+ map: doc => emit(doc._id)
Review 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}`
};
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pouchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor mapreduce tests with async/await [pouchdb]
Posted by "emilygilberts (via GitHub)" <gi...@apache.org>.
emilygilberts commented on PR #9176:
URL: https://github.com/apache/pouchdb/pull/9176#issuecomment-4169669726
hmm wondering - in some tests we had promise chains that did multiple queries that returned `res` to then be evaluated with `should` expressions. I always reassigned `res` to keep the same names as before, but I'm guessing it would be better style to use `const` and `res, res2,... `?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pouchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor mapreduce tests with async/await [pouchdb]
Posted by "janl (via GitHub)" <gi...@apache.org>.
janl commented on code in PR #9176:
URL: https://github.com/apache/pouchdb/pull/9176#discussion_r3027897015
##########
tests/mapreduce/test.mapreduce.js:
##########
@@ -1335,71 +1225,69 @@ function tests(suiteName, dbName, dbType, viewType) {
}
});
}
- return db.bulkDocs(docs).then(function () {
- return createView(db, {
- map: function (doc) {
- emit(doc._id);
+ await db.bulkDocs(docs);
+
+ const queryFun = await createView(db, {
+ map: doc => emit(doc._id)
Review Comment:
should be fine in tests, but lets leave them in their CouchDB-canonical traditional `function` form
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pouchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org