Skip to content

Commit c9c0e15

Browse files
authored
Merge pull request #594 from Iterable/2.0.0-alpha/MOB-9673-new-unit-tests
[MOB-9673] Fix unit tests
2 parents 005167f + 72af06a commit c9c0e15

File tree

13 files changed

+870
-855
lines changed

13 files changed

+870
-855
lines changed

.codeclimate.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ exclude_patterns:
2020
- "**/*.yml"
2121
- "**/build.gradle"
2222
- "**/AndroidManifest.xml"
23+
plugins:
24+
eslint:
25+
enabled: true
26+
editorconfig:
27+
enabled: true
28+
fixme:
29+
enabled: true
30+
git-legal:
31+
enabled: true
32+
shellcheck:
33+
enabled: true
34+
swiftlint:
35+
enabled: true
36+
tailor:
37+
enabled: true
38+
tslint:
39+
enabled: true

.github/workflows/test-and-publish.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/unit-test.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
branches:
9+
- "**"
10+
11+
jobs:
12+
test-comment:
13+
name: Unit tests
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Setup
20+
uses: ./.github/actions/setup
21+
22+
- name: Run tests
23+
run: |
24+
yarn test --coverage --coverageReporters json-summary
25+
26+
- name: Test coverage comment
27+
id: coverageComment
28+
uses: MishaKav/jest-coverage-comment@main
29+
with:
30+
hide-comment: false
31+
coverage-summary-path: ./coverage/coverage-summary.json
32+
test-code-climate:
33+
name: Upload unit test results to Code Climate
34+
runs-on: ubuntu-latest
35+
36+
steps:
37+
- uses: actions/checkout@v3
38+
39+
- name: Setup
40+
uses: ./.github/actions/setup
41+
42+
- name: Run tests
43+
run: |
44+
yarn test --coverage --coverageReporters lcov
45+
46+
- name: Upload coverage to Code Climate
47+
uses: paambaati/[email protected]
48+
env:
49+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
50+
with:
51+
coverageCommand: yarn test --coverage --coverageReporters lcov
52+
coverageLocations: |
53+
${{github.workspace}}/coverage/lcov.info:lcov

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ android/generated
8383

8484
# Iterable
8585
.env
86-
.xcode.env.local
86+
.xcode.env.local
87+
coverage/

jest.config.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
module.exports = {
22
preset: 'react-native',
3-
setupFiles: ['<rootDir>/ts/__mocks__/jest.setup.ts'],
4-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
5-
testMatch: ['<rootDir>/ts/__tests__/**/*.(test|spec).[jt]s?(x)'],
3+
setupFiles: ['<rootDir>/src/__mocks__/jest.setup.ts'],
4+
setupFilesAfterEnv: [
5+
'<rootDir>/node_modules/@testing-library/jest-native/extend-expect',
6+
],
7+
testMatch: ['<rootDir>/src/__tests__/**/*.(test|spec).[jt]s?(x)'],
8+
transformIgnorePatterns: [
9+
'node_modules/(?!((jest-)?react-native(-.*)?|@react-native(-community)?)/)',
10+
],
11+
collectCoverageFrom: [
12+
'src/**/*.{cjs,js,jsx,mjs,ts,tsx}',
13+
'!src/**/*.test.{cjs,js,jsx,mjs,mdx,ts,tsx}',
14+
'!src/(__tests__|__mocks__)/*',
15+
],
16+
modulePathIgnorePatterns: [
17+
'<rootDir>/example/node_modules',
18+
'<rootDir>/lib/',
19+
],
20+
coverageThreshold: {
21+
global: {
22+
branches: 10,
23+
functions: 30,
24+
lines: 30,
25+
statements: 30,
26+
},
27+
},
628
};

package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"scripts": {
3939
"example": "yarn workspace @iterable/react-native-sdk-example",
4040
"test": "jest",
41+
"test:coverage": "jest --coverage",
4142
"typecheck": "tsc",
4243
"lint": "eslint \"**/*.{js,ts,tsx}\"",
4344
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
@@ -69,6 +70,8 @@
6970
"@react-native/eslint-config": "^0.73.1",
7071
"@react-navigation/native": "^6.1.18",
7172
"@release-it/conventional-changelog": "^5.0.0",
73+
"@testing-library/jest-native": "^5.4.3",
74+
"@testing-library/react-native": "^12.7.2",
7275
"@types/jest": "^29.5.5",
7376
"@types/react": "^18.2.44",
7477
"@types/react-native-vector-icons": "^6.4.18",
@@ -104,13 +107,6 @@
104107
"example"
105108
],
106109
"packageManager": "[email protected]",
107-
"jest": {
108-
"preset": "react-native",
109-
"modulePathIgnorePatterns": [
110-
"<rootDir>/example/node_modules",
111-
"<rootDir>/lib/"
112-
]
113-
},
114110
"commitlint": {
115111
"extends": [
116112
"@commitlint/config-conventional"

src/__mocks__/jest.setup.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
import * as ReactNative from 'react-native';
2+
13
import { MockRNIterableAPI } from './MockRNIterableAPI';
24
import { MockLinking } from './MockLinking';
35

4-
import * as ReactNative from 'react-native';
56
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter.js');
67

8+
jest.mock('react-native-webview', () => {
9+
const { View } = require('react-native');
10+
return {
11+
WebView: View,
12+
};
13+
});
14+
715
jest.doMock('react-native', () => {
816
// Extend ReactNative
917
return Object.setPrototypeOf(

0 commit comments

Comments
 (0)