Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -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,

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"lint-staged": {
"**/*.js": [
"eslint --fix"
"eslint --fix",
"prettier --write"
]
},
"dependencies": {
Expand Down
13 changes: 5 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
Comment on lines +93 to +97
30 changes: 27 additions & 3 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines 54 to +57
});

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'
);
Comment on lines +63 to +81
Comment on lines +63 to +81
Comment on lines +79 to +81
});
});