【问题标题】:Zapier timeout error on testZapier 测试超时错误
【发布时间】:2018-05-30 04:19:52
【问题描述】:

我在大多数中遇到超时错误,但不是所有时间我都运行zapier test,无论我是否添加--debug,这是我的代码:

require('should');

const zapier = require('zapier-platform-core');

// Use this to make test calls into your app:
const App = require('../index');
const appTester = zapier.createAppTester(App);

describe('Zapier - ON24 CLI Auth App', () => {

  it('should have Access Tokens pass the authentication from ON24 APIs', (done) => {

    const bundle = {
        authData:{
        accessTokenKey: 'abc', 
        accessTokenSecret: 'def',
        client_id: '123'
        }
    };

    appTester(App.authentication.test, bundle)
      .then((response) => {        

        response.status.should.eql(200);        
        done();
      })
      .catch(done);
  });
});

错误:

错误:超过 2000 毫秒的超时。对于异步测试和钩子,确保 “完成()”被调用;如果返回一个 Promise,请确保它解析

尝试在const bundle 上方添加this.timeout(5000);,但这表示timeout 不是函数。

更新 - 测试模块:

const testAuth = (z, bundle) => {

    return z.request({
              url: `https://wccqa.on24.com/wcc/api/v2/client/${bundle.authData.client_id}/languages`

            }).then((response) => {

                if(response.status === 401){
                    throw new Error('The API Keys provided are invalid');
                }
                return response;
            });
};

module.exports = {

    type: 'custom',
    fields: [
        {
            key: 'accessTokenKey', label: 'Access Token Key', required: true, type: 'string'
        },
        {
            key: 'accessTokenSecret', label: 'Access Token Secret', required: true, type: 'string'
        },
                                {
            key: 'client_id', label: 'Client Id', required: true, type: 'string'
        }
    ],
    test: testAuth,
    connectionLabel: 'testAuth connectionLabel'
};

【问题讨论】:

  • 我从来没有使用过这个,但是看看文档,appTester(...) 的参数可能有问题。你的App.authentication.test 文件/方法是什么样的?
  • 看起来应该可以了。当测试失败时,请求是否也会失败?您可以通过将控制台日志添加到 catch 函数中来进行检查(也可以从成功中记录下来,这样您就可以看到发生了什么)

标签: node.js zapier-cli


【解决方案1】:

我确实深受这个错误的困扰。该错误是由于测试框架通常不会等待超过2 seconds。无论您在测试中做什么,如果不使用类似以下的方法处理,就会发生超时。在您的应用程序的 package.json 中,请在此示例中为 mocha 运行时 (15 seconds) 添加超时。请在测试时随意设置更高的超时时间。

"scripts": { "test": "node node_modules/mocha/bin/mocha --recursive --timeout 15000" },

正如其他受访者所说,最初在您的代码中添加很多 z.console.log(msg) 以查看您的请求发生了什么。

【讨论】:

  • 在 package.json 中添加超时对我有用。谢谢。
【解决方案2】:

对我有用的是运行带有附加参数的测试

zapier 测试 -t 15000

CLI 版本为 10.0.1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 2016-11-10
    • 2017-06-10
    • 1970-01-01
    • 2013-07-11
    • 2014-01-16
    • 2017-07-31
    相关资源
    最近更新 更多