繁体   English   中英

赛普拉斯插件文件在之后没有等待/异步:运行

[英]Cypress plugins file not awaiting/asyncing on after:run

我对赛普拉斯有点陌生,想知道为什么这段代码在赛普拉斯的运行后步骤中不起作用。 我在终端上使用节点运行此代码,效果很好。 但是,当我将它放在带有 after:run 事件的 cypress 插件文件中时,它不会到达 console.log 结果并且没有错误。 有什么线索吗?

const{ WebClient} = required('@slack/web-api')
module.exports = {on, config} => {
   on('after:run', (results) => {


      if(results){
         (async () => {
             try{
                let web = new WebClient({slacktoken})
                let result = await web.chat.postMessage({
                    channel: {channel}
                    text: "hello world" 
                })
              console.log(result)
              }
              catch(error){
                  console.log(error)
              }
         })();
      }
   }
}

答案是在 after:run function 上添加 async 关键字而不是它自己的

const{ WebClient} = required('@slack/web-api')
module.exports = {on, config} => {
   on('after:run', async(results) => {


      if(results){
             try{
                let web = new WebClient({slacktoken})
                let result = await web.chat.postMessage({
                    channel: {channel}
                    text: "hello world" 
                })
              console.log(result)
              }
              catch(error){
                  console.log(error)
              }
      }
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM