Skip to content

Commit f58700e

Browse files
authored
tests: start integration of Jest tests (invertase#3529)
[skip ci]
1 parent 81479dc commit f58700e

File tree

9 files changed

+122
-10
lines changed

9 files changed

+122
-10
lines changed

.github/workflows/tests_jest.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Testing
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '**'
7+
8+
jobs:
9+
jest:
10+
name: Jest
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1
14+
with:
15+
fetch-depth: 1
16+
- uses: actions/setup-node@v1
17+
with:
18+
node-version: 12
19+
- name: Get yarn cache directory path
20+
id: yarn-cache-dir-path
21+
run: echo "::set-output name=dir::$(yarn cache dir)"
22+
- uses: actions/cache@v1
23+
name: Yarn Cache
24+
id: yarn-cache
25+
with:
26+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
27+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
28+
restore-keys: |
29+
${{ runner.os }}-yarn-
30+
- name: Yarn Install
31+
run: yarn --no-audit --prefer-offline
32+
- name: Jest
33+
run: yarn run tests:jest-coverage

babel.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ module.exports = {
1010
],
1111
],
1212
},
13+
test: {
14+
presets: [
15+
[
16+
'@babel/preset-env',
17+
{
18+
targets: {
19+
node: 'current',
20+
},
21+
},
22+
],
23+
'module:./tests/node_modules/metro-react-native-babel-preset',
24+
'@babel/preset-flow',
25+
],
26+
},
1327
publish: {
1428
presets: [
1529
[

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
maxConcurrency: 10,
3+
preset: './tests/node_modules/react-native/jest-preset.js',
4+
setupFiles: ['./jest.setup.js'],
5+
testMatch: ['**/packages/**/__tests__/**/*.test.js'],
6+
modulePaths: ['node_modules', './tests/node_modules'],
7+
testPathIgnorePatterns: ['./packages/template'],
8+
};

jest.setup.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as ReactNative from 'react-native';
2+
3+
jest.doMock('react-native', () => {
4+
return Object.setPrototypeOf(
5+
{
6+
Platform: {
7+
OS: 'android',
8+
},
9+
NativeModules: {
10+
...ReactNative.NativeModules,
11+
RNFBAppModule: {
12+
NATIVE_FIREBASE_APPS: [
13+
{
14+
appConfig: {
15+
name: '[DEFAULT]',
16+
},
17+
options: {},
18+
},
19+
],
20+
},
21+
RNFBPerfModule: {},
22+
},
23+
},
24+
ReactNative,
25+
);
26+
});

package.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"lerna:bootstrap": "lerna bootstrap",
1212
"lerna:link": "lerna link",
1313
"lerna:clean": "lerna clean",
14+
"tests:jest": "jest",
15+
"tests:jest-watch": "jest --watch",
16+
"tests:jest-coverage": "jest --coverage",
1417
"gen:reference": "node scripts/generate-typedoc.js",
1518
"tests:packager:chrome": "cd tests && node_modules/.bin/react-native start --reset-cache",
1619
"tests:packager:jet": "cd tests && cross-env REACT_DEBUGGER=\"echo nope\" node_modules/.bin/react-native start --no-interactive",
@@ -31,23 +34,26 @@
3134
"format:markdown": "prettier --write \"docs/**/*.md\""
3235
},
3336
"devDependencies": {
34-
"inquirer": "^7.1.0",
35-
"shelljs": "^0.8.3",
36-
"codecov": "^3.6.5",
37-
"cross-env": "^7.0.2",
38-
"genversion": "^2.2.0",
39-
"lerna": "3.20.2",
40-
"rimraf": "^3.0.2",
41-
"typedoc": "^0.15.0",
42-
"typescript": "^3.8.3",
4337
"@types/react-native": "^0.62.0",
4438
"@typescript-eslint/eslint-plugin": "^2.18.0",
4539
"@typescript-eslint/parser": "^2.18.0",
40+
"codecov": "^3.6.5",
41+
"cross-env": "^7.0.2",
4642
"eslint": "^6.8.0",
4743
"eslint-config-prettier": "^6.5.0",
4844
"eslint-plugin-prettier": "^3.1.1",
4945
"eslint-plugin-react": "^7.19.0",
50-
"prettier": "^1.19.1"
46+
"genversion": "^2.2.0",
47+
"inquirer": "^7.1.0",
48+
"lerna": "3.20.2",
49+
"prettier": "^1.19.1",
50+
"rimraf": "^3.0.2",
51+
"shelljs": "^0.8.3",
52+
"typedoc": "^0.15.0",
53+
"typescript": "^3.8.3",
54+
"jest": "^24.9.0",
55+
"@babel/preset-env": "7.9.5",
56+
"@babel/preset-flow": "7.9.0"
5157
},
5258
"workspaces": {
5359
"packages": [

packages/functions/.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ android/.settings
6464
.circleci
6565
.eslintignore
6666
type-test.ts
67+
68+
__tests__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import functions from '../lib';
2+
3+
describe('Cloud Functions', () => {
4+
describe('useFunctionsEmulator()', () => {
5+
it('useFunctionsEmulator -> uses 10.0.2.2', () => {
6+
functions().useFunctionsEmulator('http://localhost');
7+
expect(functions()._useFunctionsEmulatorOrigin).toBe('http://10.0.2.2');
8+
functions().useFunctionsEmulator('http://127.0.0.1');
9+
expect(functions()._useFunctionsEmulatorOrigin).toBe('http://10.0.2.2');
10+
});
11+
});
12+
});

packages/perf/.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ android/.settings
6464
.circleci
6565
.eslintignore
6666
type-test.ts
67+
68+
__tests__
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import perf from '../lib';
2+
3+
describe('Performance Monitoring', () => {
4+
describe('setPerformanceCollectionEnabled', () => {
5+
it('errors if not boolean', async () => {
6+
expect(() => perf().setPerformanceCollectionEnabled()).toThrow('must be a boolean');
7+
});
8+
});
9+
});

0 commit comments

Comments
 (0)