UNPKG

qerrors

Version:

Intelligent error handling middleware with AI-powered analysis, environment validation, caching, and production-ready logging. Provides OpenAI-based error suggestions, queue management, retry mechanisms, and comprehensive configuration options for Node.js

44 lines (39 loc) 1.94 kB
const test = require('node:test'); //node test runner const assert = require('node:assert/strict'); //strict assertion helpers function reloadQerrors() { //helper to reload module with current env delete require.cache[require.resolve('../lib/qerrors')]; //remove cached module return require('../lib/qerrors'); //reload qerrors fresh } test('axiosInstance honors QERRORS_TIMEOUT', () => { const orig = process.env.QERRORS_TIMEOUT; //save existing value process.env.QERRORS_TIMEOUT = '1234'; //set custom timeout for test const { axiosInstance } = reloadQerrors(); //reload module with env try { assert.equal(axiosInstance.defaults.timeout, 1234); //timeout matches env } finally { if (orig === undefined) { delete process.env.QERRORS_TIMEOUT; } else { process.env.QERRORS_TIMEOUT = orig; } reloadQerrors(); //restore module state } }); test('axiosInstance uses default timeout when env missing', () => { const orig = process.env.QERRORS_TIMEOUT; //capture original env delete process.env.QERRORS_TIMEOUT; //remove to test default const { axiosInstance } = reloadQerrors(); //reload module with defaults try { assert.equal(axiosInstance.defaults.timeout, 10000); //default set } finally { if (orig === undefined) { delete process.env.QERRORS_TIMEOUT; } else { process.env.QERRORS_TIMEOUT = orig; } reloadQerrors(); //reset module state } }); test('axiosInstance uses default timeout with invalid env', () => { //invalid value fallback const orig = process.env.QERRORS_TIMEOUT; //save current env process.env.QERRORS_TIMEOUT = 'abc'; //set invalid const { axiosInstance } = reloadQerrors(); //reload with invalid value try { assert.equal(axiosInstance.defaults.timeout, 10000); //should use default } finally { if (orig === undefined) { delete process.env.QERRORS_TIMEOUT; } else { process.env.QERRORS_TIMEOUT = orig; } reloadQerrors(); //reset module } });