From c4c5d894953b2ca9f262494b098708a64f7cd20d Mon Sep 17 00:00:00 2001 From: Jason Sooter <7215306+JasonSooter@users.noreply.github.com> Date: Mon, 11 May 2026 17:56:40 -0600 Subject: [PATCH] feat(config): enforce 100% test coverage threshold and add prettier to pre-commit Configures coverageThreshold to require 100% across all metrics (statements, branches, functions, lines). Adds prettier --write to lint-staged so formatting is enforced on every commit. Adds tests for error handling paths and simplifies the module export guard. Co-Authored-By: Claude Opus 4.6 --- jest.config.js | 15 +++++++++++---- package.json | 3 ++- src/index.js | 13 +++++-------- src/index.test.js | 30 +++++++++++++++++++++++++++--- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/jest.config.js b/jest.config.js index 48577cf..6ed0b95 100644 --- a/jest.config.js +++ b/jest.config.js @@ -24,7 +24,17 @@ module.exports = { // The directory where Jest should output its coverage files coverageDirectory: 'coverage', - // coverageThreshold: { global: { lines: 75 } }, + + // An object that configures minimum threshold enforcement for coverage results + coverageThreshold: { + global: { + branches: 100, + functions: 100, + lines: 100, + statements: 100 + } + }, + // An array of regexp pattern strings used to skip coverage collection // coveragePathIgnorePatterns: [ // "/node_modules/" @@ -41,9 +51,6 @@ module.exports = { // "clover" // ], - // An object that configures minimum threshold enforcement for coverage results - // coverageThreshold: undefined, - // A path to a custom dependency extractor // dependencyExtractor: undefined, diff --git a/package.json b/package.json index 7981407..5b13c84 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ }, "lint-staged": { "**/*.js": [ - "eslint --fix" + "eslint --fix", + "prettier --write" ] }, "dependencies": { diff --git a/src/index.js b/src/index.js index df913a5..f6cf485 100644 --- a/src/index.js +++ b/src/index.js @@ -90,11 +90,8 @@ async function onRequest(request, settings) { /** * Exports for Testing Only */ -try { - if (process?.env['NODE_DEV'] === 'TEST') { - module.exports = { - onRequest - }; - } - // eslint-disable-next-line no-empty -} catch (e) {} +if (typeof process !== 'undefined' && process.env['NODE_DEV'] === 'TEST') { + module.exports = { + onRequest + }; +} diff --git a/src/index.test.js b/src/index.test.js index 7d401b9..d64fc21 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -52,8 +52,32 @@ describe('onRequest', () => { * Expect `Segment` methods to have been called */ expect(Segment.identify).toHaveBeenCalledTimes(1); - expect(Segment.track).toHaveBeenCalledTimes(1); - expect(Segment.track).toHaveBeenCalledTimes(1); - expect(Segment.track).toHaveBeenCalledTimes(1); + expect(Segment.group).toHaveBeenCalledTimes(1); + expect(Segment.page).toHaveBeenCalledTimes(1); + expect(Segment.screen).toHaveBeenCalledTimes(1); + }); + + it('should throw RetryError on fetch connection error', async () => { + fetch.mockRejectOnce(new Error('Network failure')); + + await expect(onRequest(baseRequest, baseSettings)).rejects.toThrow( + 'Network failure' + ); + }); + + it('should throw RetryError on 500 server error', async () => { + fetch.mockResponseOnce('', { status: 500 }); + + await expect(onRequest(baseRequest, baseSettings)).rejects.toThrow( + 'Failed with 500' + ); + }); + + it('should throw RetryError on 429 rate limit', async () => { + fetch.mockResponseOnce('', { status: 429 }); + + await expect(onRequest(baseRequest, baseSettings)).rejects.toThrow( + 'Failed with 429' + ); }); });