I'm having trouble with my Zapier tests. They keep timing out most of the time. It doesn't matter if I use the debug flag or not.
Here's what my test code looks like:
const myApp = require('../app');
const testRunner = zapier.createTestRunner(myApp);
describe('My Zapier App', () => {
it('should authenticate with API', async () => {
const testData = {
auth: {
apiKey: 'test123',
apiSecret: 'secret456',
userId: '789'
}
};
const result = await testRunner(myApp.auth.test, testData);
expect(result.status).toBe(200);
});
});
The error I'm getting is:
> Error: 2000ms timeout exceeded. Make sure to call done() for async tests or resolve Promises.
I tried setting a longer timeout with this.timeout(5000) but it says timeout isn't a function. Any ideas on how to fix this?
Update: Here's my auth module if it helps:
const verifyAuth = (z, data) => {
return z.request({
url: `https://api.example.com/user/${data.auth.userId}/info`
}).then(response => {
if (response.status === 401) {
throw new Error('Invalid API credentials');
}
return response;
});
};
module.exports = {
type: 'custom',
fields: [
{key: 'apiKey', label: 'API Key', required: true},
{key: 'apiSecret', label: 'API Secret', required: true},
{key: 'userId', label: 'User ID', required: true}
],
test: verifyAuth,
connectionLabel: 'API Connection'
};
I’ve dealt with similar timeout issues in Zapier tests. Have you considered using a polyfill for global.Promise? Sometimes, the Node.js environment in Zapier can be finicky with promises. Try adding this at the top of your test file:
global.Promise = require(‘bluebird’);
This replaces the native Promise with Bluebird, which can be more reliable in certain scenarios. Also, ensure your API endpoint isn’t rate-limiting requests. If it is, you might need to implement a delay between tests or use a mock server for testing.
Lastly, check if your auth module is properly catching and handling all potential errors. Unhandled exceptions can sometimes lead to silent timeouts. Adding more detailed error logging could help isolate the issue.
hey, tried using async/await all the way? sometimes mixing promises causes timeouts. check your req config too. hope that helps, good luck!
I’ve encountered similar timeout issues with Zapier tests before. One thing that worked for me was increasing the timeout in the test runner configuration itself, not just in individual tests. Try adding this at the top of your test file:
jest.setTimeout(30000);
This sets a global timeout of 30 seconds for all tests. If that doesn’t work, you might want to check your API endpoint. Sometimes slow responses from external services can cause timeouts. I’ve found it helpful to mock API calls during testing to isolate the issue.
Also, double-check your auth module. Make sure you’re properly handling errors and not getting stuck in a promise chain. Adding some logging might help pinpoint where the timeout is occurring. Good luck troubleshooting!