node.jszapier-cli

Zapier timeout error on test


I get a timeout error in most but not all the times i run zapier test whether i add --debug or not, here's my code:

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);
  });
});

Error:

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves

Tried adding this.timeout(5000); above const bundle but this says that timeout is not a function.

Update - test module:

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'
};

Solution

  • I did suffer from this error a lot. The error is due the test framework which normally doesn't wait beyond 2 seconds. Whatever you do in the tests, timeout occurs if not handled using something like the following. In your app's package.json, please add a timeout to mocha runtime (15 seconds) in this example. Please feel free to set a higher timeout while you are testing.

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

    As other respondents said, add z.console.log(msg) to your code a lot initially to see what is happening with your requests.