Skip to content

Commit

Permalink
fix: Fix yarn test:unit v1.22.4 (#753)
Browse files Browse the repository at this point in the history
* Fix yarn run v1.22.4
$ jest App
Done in 5.66s. #724

* ci: run unit tests in github pr workflow

* Update babel.config.js

* Update jest.config.js

* Update jest.config.js

* Update jest.config.js

* Update jest.config.js

Co-authored-by: Amaury Martiny <[email protected]>
  • Loading branch information
bertoort and amaury1093 committed Oct 4, 2020
1 parent 3286566 commit 1b7e89e
Show file tree
Hide file tree
Showing 7 changed files with 873 additions and 685 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ jobs:
- uses: actions/checkout@v1
- run: yarn install
- run: yarn lint

test-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: yarn install
- run: yarn test:unit
test-e2e:
runs-on: macOS-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion App/stores/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('withTimeout', () => {
it('should correct time out', async (done) => {
jest.setTimeout(5000);

const p = new Promise((resolve) => setTimeout(resolve, 2000));
const p = new Promise((resolve) => setTimeout(resolve, 2001));

try {
await withTimeout(p, 2000);
Expand Down
5 changes: 5 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
// Properly configure ts-jest.
// https://kulshekhar.github.io/ts-jest/user/react-native/#babel-config
presets: ['module:metro-react-native-babel-preset'],
};
22 changes: 21 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
/* eslint-disable */
const { defaults: tsjPreset } = require('ts-jest/presets');

module.exports = {
...tsjPreset,
preset: 'jest-expo',
moduleFileExtensions: ['js', 'ts', 'tsx'],
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
// Mock static asset imports.
// https://jestjs.io/docs/en/webpack#handling-static-assets
moduleNameMapper: {
'\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/mocks/fileMock.js',
},
transform: {
'^.+\\.tsx?$': 'ts-jest',
...tsjPreset.transform,
},
// blacklist any unwanted modules that get transpiled, like sentry
// https://docs.expo.io/guides/testing-with-jest/#jest-configuration
transformIgnorePatterns: [
'node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|@sentry/.*)',
],
globals: {
'ts-jest': {
babelConfig: true, // Globals with ts-jest config to look for babel config.
},
},
};
1 change: 1 addition & 0 deletions mocks/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = '';
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
"@types/jest": "^26.0.14",
"detox": "^17.8.0",
"detox-expo-helpers": "^0.6.0",
"jest": "^24.9.0",
"jest": "^26.4.2",
"jest-expo": "^39.0.0",
"ts-jest": "^24.3.0",
"ts-jest": "^26.4.1",
"typescript": "~3.9.2"
}
}
Loading

0 comments on commit 1b7e89e

Please sign in to comment.