All files / scripts/lib axiosLoader.js

100% Statements 9/9
100% Branches 6/6
100% Functions 1/1
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22    33x                 46x 5x   5x 4x 4x 1x     33x  
// require('axios') is deferred to call-time so test runners that parse CJS builds
// don't trip over the axios ESM entry point before it's needed.
let _axios = null;
 
/**
 * Returns a shared axios instance, requiring it lazily on first call.
 * Returns null when axios is not installed so callers can skip network calls gracefully.
 *
 * @returns {import('axios').AxiosInstance|null}
 */
function getAxios() {
  if (_axios) return _axios;
  try {
    // eslint-disable-next-line global-require
    const mod = require('axios');
    _axios = mod && mod.default ? mod.default : mod;
    return _axios;
  } catch (e) { return null; }
}
 
module.exports = { getAxios };