草庐IT

javascript - Bluebird Promise 串行迭代,并解析到修改后的数组?

我有这个promise,如果在db中找不到新的Item文档,然后将其存储在以前创建的Collection文档中。..Collection文档是数组中的第一个字符串,数组中的任何后续索引都转换为一个或多个Item文档。Promise.each"Resolvestotheoriginalarrayunmodified"因此Promise.each中的最后一个return正在渲染对象,但随后的.then会生成原始数组..这是promise(为便于阅读而缩写):globalVar=true;collectionId="";varitemSeries=Promise.each(items,fun

node.js - 使用 testdoublejs 测试多个 then 的 Promise

我正在使用testdouble在我的node.js项目中stub调用。这个特定的函数包装了一个promise,并且在函数本身中有多个then调用。functiongetUser(rethink,username){returnnewPromise((resolve,reject)=>{letr=database.connect();r.then(conn=>database.table(tablename).filter({username})).then(data=>resolve(data)).error(err=>reject(err));});}所以我想确定resolve和re

node.js - 使用 testdoublejs 测试多个 then 的 Promise

我正在使用testdouble在我的node.js项目中stub调用。这个特定的函数包装了一个promise,并且在函数本身中有多个then调用。functiongetUser(rethink,username){returnnewPromise((resolve,reject)=>{letr=database.connect();r.then(conn=>database.table(tablename).filter({username})).then(data=>resolve(data)).error(err=>reject(err));});}所以我想确定resolve和re

node.js - child_process.exec/spawn 使用 npm install 命令触发回调/关闭(通过 Gulp/Shipit)

我正在使用Shipit用于部署。在部署时,Shipit将当前的GitShacheckout到tmp目录,然后我运行npminstall和gulpbuild,然后继续部署。与Gulp一样,Shipit将Orchestrator用于其任务流。Shipit有自己的CLI,所以我可以使用shipitdevelopmentdeploy进行部署。上面的一切都有效。我要做的是创建一个gulpdeploy任务,它将直接初始化Shipit,而不是使用CLI。看起来像这样:gulp.task('shipit:deploy',function(){vardeployToEnv=argv['deploy-to

node.js - child_process.exec/spawn 使用 npm install 命令触发回调/关闭(通过 Gulp/Shipit)

我正在使用Shipit用于部署。在部署时,Shipit将当前的GitShacheckout到tmp目录,然后我运行npminstall和gulpbuild,然后继续部署。与Gulp一样,Shipit将Orchestrator用于其任务流。Shipit有自己的CLI,所以我可以使用shipitdevelopmentdeploy进行部署。上面的一切都有效。我要做的是创建一个gulpdeploy任务,它将直接初始化Shipit,而不是使用CLI。看起来像这样:gulp.task('shipit:deploy',function(){vardeployToEnv=argv['deploy-to

node.js - 保存时 promise 的 Mongoose 错误?

当我尝试通过模型实例上的保存操作来获得promise时。我得到错误:undefinedisnotafunctioninstance.save().exec().then(..)但是,如果我尝试用这样的模型获得promise,那么它会起作用。model.find(..).exec().then(..)有没有办法获得保存操作的promise。目前我只是通过回调来保存功能。但是,为了保持一致性,我想以相同的方式进行所有数据库操作。 最佳答案 Model#save返回一个promise,所以你应该跳过.exec():instance.sav

node.js - 保存时 promise 的 Mongoose 错误?

当我尝试通过模型实例上的保存操作来获得promise时。我得到错误:undefinedisnotafunctioninstance.save().exec().then(..)但是,如果我尝试用这样的模型获得promise,那么它会起作用。model.find(..).exec().then(..)有没有办法获得保存操作的promise。目前我只是通过回调来保存功能。但是,为了保持一致性,我想以相同的方式进行所有数据库操作。 最佳答案 Model#save返回一个promise,所以你应该跳过.exec():instance.sav

javascript - 使用 sinon 和 bluebird 对 Promisified 函数进行 Stub

在我要测试的文件中,我有以下代码:varhttpGet=Promise.promisify(require("request").get);httpGet(endpoint,{auth:{bearer:req.body.access_token},json:true}).then(...)现在,在我的测试中,我想确保httpGet被调用一次,并确保参数有效。在被promise之前,我的测试是这样的:beforeEach(function(){request.get=sinon.stub().yields(null,null,{error:"testerror",error_descri

javascript - 使用 sinon 和 bluebird 对 Promisified 函数进行 Stub

在我要测试的文件中,我有以下代码:varhttpGet=Promise.promisify(require("request").get);httpGet(endpoint,{auth:{bearer:req.body.access_token},json:true}).then(...)现在,在我的测试中,我想确保httpGet被调用一次,并确保参数有效。在被promise之前,我的测试是这样的:beforeEach(function(){request.get=sinon.stub().yields(null,null,{error:"testerror",error_descri

node.js - 在解决 promise 时如何保持 node.js 脚本处于事件状态?

我的脚本使用Promise(使用q库)执行一些异步任务。运行mocha测试工作正常。但是从命令行运行脚本不会。Node进程立即死亡。varbot=require('./bot');bot.getCategories().then(function(categories){console.log('Found'+categories.length+'categories');}); 最佳答案 Myscriptperformssomeasynchronoustasksusingpromises(withtheqlibrary).Runn