Skip to content

Commit 5d4b492

Browse files
Sets up initial jest infra and mocks along with a basic export snapshot (stripe#331)
* js unit infra * fix lint * store coverage
1 parent cb342a6 commit 5d4b492

File tree

7 files changed

+91
-3
lines changed

7 files changed

+91
-3
lines changed

Diff for: .circleci/config.yml

+13
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ jobs:
241241
command: |
242242
yarn typescript
243243
yarn --cwd example-app typescript
244+
unit-js:
245+
executor: linux_js
246+
steps:
247+
- attach_project
248+
- run:
249+
name: Jest
250+
command: |
251+
yarn unit-test:js --coverage
252+
- store_artifacts:
253+
path: coverage
244254
example-build-android:
245255
executor:
246256
name: android/android-machine
@@ -365,6 +375,9 @@ workflows:
365375
- typescript:
366376
requires:
367377
- install-dependencies
378+
- unit-js:
379+
requires:
380+
- install-dependencies
368381
- example-build-ios:
369382
requires:
370383
- install-dependencies

Diff for: .eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ tsconfig.json
99
config.json
1010
app.json
1111
tsconfig.build.json
12+
*.snap

Diff for: jest.eslint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ module.exports = {
55
displayName: 'eslint',
66
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
77
testMatch: ['**/*'],
8+
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/lib'],
89
};

Diff for: jestSetup.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { NativeModules } from 'react-native';
2+
3+
NativeModules.StripeTerminalReactNative = {
4+
getConstants: () => ({
5+
FETCH_TOKEN_PROVIDER: 'FETCH_TOKEN_PROVIDER',
6+
CHANGE_CONNECTION_STATUS: 'CHANGE_CONNECTION_STATUS',
7+
CHANGE_PAYMENT_STATUS: 'CHANGE_PAYMENT_STATUS',
8+
FINISH_DISCOVERING_READERS: 'FINISH_DISCOVERING_READERS',
9+
FINISH_INSTALLING_UPDATE: 'FINISH_INSTALLING_UPDATE',
10+
REQUEST_READER_DISPLAY_MESSAGE: 'REQUEST_READER_DISPLAY_MESSAGE',
11+
REQUEST_READER_INPUT: 'REQUEST_READER_INPUT',
12+
REPORT_AVAILABLE_UPDATE: 'REPORT_AVAILABLE_UPDATE',
13+
REPORT_UNEXPECTED_READER_DISCONNECT: 'REPORT_UNEXPECTED_READER_DISCONNECT',
14+
REPORT_UPDATE_PROGRESS: 'REPORT_UPDATE_PROGRESS',
15+
START_INSTALLING_UPDATE: 'START_INSTALLING_UPDATE',
16+
UPDATE_DISCOVERED_READERS: 'UPDATE_DISCOVERED_READERS',
17+
}),
18+
};

Diff for: package.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"stripe-terminal-react-native.podspec"
1818
],
1919
"scripts": {
20-
"test": "jest",
20+
"test": "yarn unit-test:android && yarn unit-test:js",
2121
"typescript": "tsc --noEmit",
2222
"lint": "jest --config \"jest.eslint.config.js\"",
2323
"prettier": "prettier --write \"**/*.{ts,js,jsx,tsx}\"",
@@ -40,7 +40,8 @@
4040
"e2e:test:ios:release": " detox test --configuration ios.sim.release --take-screenshots failing --loglevel verbose",
4141
"get:testbutler": "curl -f -o ./test-butler-app.apk https://repo1.maven.org/maven2/com/linkedin/testbutler/test-butler-app/2.2.1/test-butler-app-2.2.1.apk",
4242
"docs": "npx typedoc ./src/index.tsx --out ./docs/api-reference --tsconfig ./tsconfig.json",
43-
"unit-test:android": "cd android && ./gradlew testDebugUnitTest"
43+
"unit-test:android": "cd android && ./gradlew testDebugUnitTest",
44+
"unit-test:js": "jest"
4445
},
4546
"keywords": [
4647
"react-native",
@@ -86,10 +87,16 @@
8687
},
8788
"jest": {
8889
"preset": "react-native",
90+
"setupFiles": [
91+
"<rootDir>/jestSetup.js"
92+
],
8993
"modulePathIgnorePatterns": [
9094
"<rootDir>/dev-app/node_modules",
9195
"<rootDir>/lib/"
92-
]
96+
],
97+
"moduleNameMapper": {
98+
"package.json$": "<rootDir>/package.json"
99+
}
93100
},
94101
"peerDependencies": {
95102
"react": "*",

Diff for: src/__snapshots__/index.test.tsx.snap

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`index.ts Public API snapshot ensure there are no unexpected changes to our public exports 1`] = `
4+
Object {
5+
"CommonError": Object {
6+
"Canceled": "Canceled",
7+
"Failed": "Failed",
8+
"Unknown": "Unknown",
9+
},
10+
"PaymentIntent": Object {},
11+
"PaymentMethod": Object {
12+
"Android": Object {},
13+
"IOS": Object {},
14+
},
15+
"Reader": Object {
16+
"Android": Object {},
17+
"IOS": Object {},
18+
},
19+
"Refund": Object {
20+
"Android": Object {},
21+
"IOS": Object {},
22+
},
23+
"SetupIntent": Object {
24+
"Android": Object {},
25+
"IOS": Object {},
26+
},
27+
"StripeTerminalProvider": [Function],
28+
"StripeTerminalProviderProps": undefined,
29+
"UseStripeTerminalProps": undefined,
30+
"WithStripeTerminalProps": undefined,
31+
"requestNeededAndroidPermissions": [Function],
32+
"useStripeTerminal": [Function],
33+
"withStripeTerminal": [Function],
34+
}
35+
`;

Diff for: src/index.test.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as StripeTerminal from './index';
2+
3+
jest.mock(
4+
'../node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter'
5+
);
6+
7+
describe('index.ts', () => {
8+
describe('Public API snapshot', () => {
9+
it('ensure there are no unexpected changes to our public exports', () => {
10+
expect(StripeTerminal).toMatchSnapshot();
11+
});
12+
});
13+
});

0 commit comments

Comments
 (0)