Skip to content

Commit

Permalink
Remove values mock from test
Browse files Browse the repository at this point in the history
It's easy for this mock to fall out of sync with the actual module, and
solutions which would prevent this would be verbose and cluttered.
The only thing it achieves is keeping the tests fast with a lower retry
timeout, and that can also be achieved with a switch on NODE_ENV.
  • Loading branch information
nicknovitski committed Sep 10, 2024
1 parent 41773e1 commit d0747b4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('jest').Config} */
const config = {
coverageDirectory: '<rootDir>/../coverage',
preset: 'ts-jest',
rootDir: 'src',
testEnvironment: 'node',
};

module.exports = config;
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
"eslintConfig": {
"extends": "universe/node"
},
"jest": {
"coverageDirectory": "<rootDir>/../coverage",
"preset": "ts-jest",
"rootDir": "src",
"testEnvironment": "node"
},
"repository": {
"type": "git",
"url": "git+https://github.com/expo/expo-server-sdk-node.git"
Expand Down
2 changes: 1 addition & 1 deletion src/ExpoClientValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ export const defaultConcurrentRequestLimit = 6;
/**
* Minimum timeout in ms for request retries.
*/
export const requestRetryMinTimeout = 1000;
export const requestRetryMinTimeout = process.env['NODE_ENV'] === 'test' ? 1 : 1000;
11 changes: 1 addition & 10 deletions src/__tests__/ExpoClient-test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { jest, afterEach, beforeEach, describe, test, expect } from '@jest/globals';
import { afterEach, beforeEach, describe, test, expect } from '@jest/globals';
import fetch from 'node-fetch';
import assert from 'node:assert';

import ExpoClient, { ExpoPushMessage } from '../ExpoClient';
import { getReceiptsApiUrl, sendApiUrl } from '../ExpoClientValues';

jest.mock('../ExpoClientValues', () => ({
requestRetryMinTimeout: 1,
pushNotificationChunkLimit: 100,
sendApiUrl: 'http://localhost:3000/--/api/v2/push/send',
getReceiptsApiUrl: 'http://localhost:3000/--/api/v2/push/getReceipts',
pushNotificationReceiptChunkLimit: 300,
defaultConcurrentRequestLimit: 6,
}));

afterEach(() => {
(fetch as any).reset();
});
Expand Down

0 comments on commit d0747b4

Please sign in to comment.