Skip to content

Commit

Permalink
upgrade and fix jest
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielEliraz committed Jun 7, 2024
1 parent 1c1a411 commit fdc461f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 46 deletions.
36 changes: 36 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
preset: 'react-native',
transformIgnorePatterns: [
'node_modules/(?!(@react-native|react-native)/)',
],
transform: {
'\\.[jt]sx?$': 'babel-jest',
},
roots: [
'<rootDir>/node_modules/',
'<rootDir>/lib/dist/'
],
collectCoverageFrom: [
'lib/dist/**/*.js',
'lib/src/**/*.js',
'integration/**/*.js',
'!lib/dist/index.js',
'!lib/dist/Notifications.js',
'!lib/dist/NotificationsIOS.js',
'!lib/dist/NotificationsAndroid.js',
'!lib/dist/adapters/**/*',
'!lib/dist/interfaces/**/*',
'!lib/dist/**/*.test.*',
'!integration/**/*.test.*',
'!integration/*.test.*'
],
resetMocks: true,
resetModules: true,
coverageReporters: [
'json',
'lcov',
'text',
'html'
],
testEnvironment: 'node',
};
15 changes: 7 additions & 8 deletions lib/src/commands/Commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ describe('Commands', () => {

describe('getInitialNotification', () => {
it('sends to native', () => {
when(mockedNativeCommandsSender.getInitialNotification()).thenResolve();
uut.getInitialNotification();
verify(mockedNativeCommandsSender.getInitialNotification()).called();
});

it('Android - returns a promise with the initial notification', async () => {
Platform.OS = 'android';
const expectedNotification: Notification = new NotificationAndroid({'google.message_id': 'id'});
when(mockedNativeCommandsSender.getInitialNotification()).thenResolve(
{'google.message_id': 'id'}
);
const payload = {'google.message_id': 'id'};
const expectedNotification: Notification = new NotificationAndroid(payload);
when(mockedNativeCommandsSender.getInitialNotification()).thenResolve(payload);
const result = await uut.getInitialNotification();
expect(result).toEqual(expectedNotification);
});
Expand All @@ -54,10 +54,9 @@ describe('Commands', () => {

it('iOS - returns a promise with the initial notification', async () => {
Platform.OS = 'ios';
const expectedNotification: Notification = new NotificationIOS({identifier: 'id'});
when(mockedNativeCommandsSender.getInitialNotification()).thenResolve(
{identifier: 'id'}
);
const payload = {identifier: 'id'};
const expectedNotification: Notification = new NotificationIOS(payload);
when(mockedNativeCommandsSender.getInitialNotification()).thenResolve(payload);
const result = await uut.getInitialNotification();
expect(result).toEqual(expectedNotification);
});
Expand Down
43 changes: 6 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@
"@react-native/eslint-config": "0.73.2",
"@react-native/metro-config": "0.73.5",
"@react-native/typescript-config": "0.73.1",
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"@types/jest": "^27.0.0",
"@types/lodash": "4.14.182",
"@types/react": "^18.2.6",
"@types/react-native": "0.73.0",
"@types/react-test-renderer": "^18.0.0",
"babel-eslint": "10.0.3",
"detox": "^19.4.2",
"babel-jest": "^29.7.0",
"detox": "20.19.5",
"github-release-notes": "https://github.com/yogevbd/github-release-notes/tarball/e601b3dba72dcd6cba323c1286ea6dd0c0110b58",
"jest": "^27.0.0",
"jest": "^27.5.1",
"lodash": "4.17.21",
"react": "^18.2.0",
"react-native": "^0.73.3",
Expand All @@ -83,37 +84,5 @@
"homepage": "https://github.com/wix/react-native-notifications",
"bugs": {
"url": "https://github.com/wix/react-native-notifications/issues"
},
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
},
"roots": [
"<rootDir>/node_modules/",
"<rootDir>/lib/dist/"
],
"collectCoverageFrom": [
"lib/dist/**/*.js",
"lib/src/**/*.js",
"integration/**/*.js",
"!lib/dist/index.js",
"!lib/dist/Notifications.js",
"!lib/dist/NotificationsIOS.js",
"!lib/dist/NotificationsAndroid.js",
"!lib/dist/adapters/**/*",
"!lib/dist/interfaces/**/*",
"!lib/dist/**/*.test.*",
"!integration/**/*.test.*",
"!integration/*.test.*"
],
"resetMocks": true,
"resetModules": true,
"coverageReporters": [
"json",
"lcov",
"text",
"html"
]
}
}
}
2 changes: 1 addition & 1 deletion scripts/test-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function run() {
const paths = _.chain(dirs).map((d) => d === 'e2e' ? `${d}/**/*.[tj]s` : `${d}/**/*.[tj]sx?`).join(' ').value();
exec.execSync(`tslint ${paths} ${fix} --format verbose`);
assertAllTsFilesInSrc();
exec.execSync(`jest --coverage`);
exec.execSync(`jest --coverage --config ./jest.config.js`);
}

function assertAllTsFilesInSrc() {
Expand Down

0 comments on commit fdc461f

Please sign in to comment.