From fdc461fdba2c352701eff91cbee533ff414e8d37 Mon Sep 17 00:00:00 2001 From: danielel Date: Fri, 7 Jun 2024 16:20:37 +0300 Subject: [PATCH] upgrade and fix jest --- jest.config.js | 36 ++++++++++++++++++++++++++ lib/src/commands/Commands.test.ts | 15 +++++------ package.json | 43 +++++-------------------------- scripts/test-js.js | 2 +- 4 files changed, 50 insertions(+), 46 deletions(-) create mode 100644 jest.config.js diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 000000000..105eefb11 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,36 @@ +module.exports = { + preset: 'react-native', + transformIgnorePatterns: [ + 'node_modules/(?!(@react-native|react-native)/)', + ], + transform: { + '\\.[jt]sx?$': 'babel-jest', + }, + roots: [ + '/node_modules/', + '/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', +}; diff --git a/lib/src/commands/Commands.test.ts b/lib/src/commands/Commands.test.ts index 9aeddfa5e..f62372cae 100644 --- a/lib/src/commands/Commands.test.ts +++ b/lib/src/commands/Commands.test.ts @@ -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); }); @@ -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); }); diff --git a/package.json b/package.json index 2061ba966..e53a8ffab 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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$": "/node_modules/react-native/jest/preprocessor.js" - }, - "roots": [ - "/node_modules/", - "/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" - ] } -} \ No newline at end of file +} diff --git a/scripts/test-js.js b/scripts/test-js.js index 0613aa3e8..d5ae2dd09 100644 --- a/scripts/test-js.js +++ b/scripts/test-js.js @@ -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() {