Skip to content

Commit

Permalink
docs(devs-infra): update documentation for react-native (#2754)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Jul 18, 2021
1 parent b4f698f commit 4a95c76
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 31 deletions.
29 changes: 20 additions & 9 deletions website/docs/guides/react-native.md
Expand Up @@ -18,6 +18,20 @@ module.exports = {
}
```

### TypeScript Configuration

Create a new `tsconfig.spec.json` at the root of your project with the following content

```json
// tsconfig.spec.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"jsx": "react"
}
}
```

### Jest config

In the same way that you moved Babel config, move Jest config from `jest` key of `package.json` to `jest.config.js`. It should look like this:
Expand All @@ -27,19 +41,16 @@ In the same way that you moved Babel config, move Jest config from `jest` key of
const { defaults: tsjPreset } = require('ts-jest/presets')

module.exports = {
...tsjPreset,
preset: 'react-native',
transform: {
...tsjPreset.transform,
'\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
},
globals: {
'ts-jest': {
babelConfig: true,
tsconfig: 'tsconfig.spec.json',
},
},
// This is the only part which you can keep
// from the above linked tutorial's config:
cacheDirectory: '.jest/cache',
transform: {
'^.+\\.jsx$': 'babel-jest',
'^.+\\.tsx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}
```
31 changes: 20 additions & 11 deletions website/versioned_docs/version-26.5/guides/react-native.md
Expand Up @@ -18,28 +18,37 @@ module.exports = {
}
```

### TypeScript Configuration

Create a new `tsconfig.spec.json` at the root of your project with the following content

```json
// tsconfig.spec.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"jsx": "react"
}
}
```

### Jest config

In the same way that you moved Babel config, move Jest config from `jest` key of `package.json` to `jest.config.js`. It should look like this:

```js
// jest.config.js
const { defaults: tsjPreset } = require('ts-jest/presets')

module.exports = {
...tsjPreset,
preset: 'react-native',
transform: {
...tsjPreset.transform,
'\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
},
globals: {
'ts-jest': {
babelConfig: true,
tsconfig: 'tsconfig.spec.json',
},
},
// This is the only part which you can keep
// from the above linked tutorial's config:
cacheDirectory: '.jest/cache',
transform: {
'^.+\\.jsx$': 'babel-jest',
'^.+\\.tsx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}
```
31 changes: 20 additions & 11 deletions website/versioned_docs/version-27.0/guides/react-native.md
Expand Up @@ -18,28 +18,37 @@ module.exports = {
}
```

### TypeScript Configuration

Create a new `tsconfig.spec.json` at the root of your project with the following content

```json
// tsconfig.spec.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"jsx": "react"
}
}
```

### Jest config

In the same way that you moved Babel config, move Jest config from `jest` key of `package.json` to `jest.config.js`. It should look like this:

```js
// jest.config.js
const { defaults: tsjPreset } = require('ts-jest/presets')

module.exports = {
...tsjPreset,
preset: 'react-native',
transform: {
...tsjPreset.transform,
'\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
},
globals: {
'ts-jest': {
babelConfig: true,
tsconfig: 'tsconfig.spec.json',
},
},
// This is the only part which you can keep
// from the above linked tutorial's config:
cacheDirectory: '.jest/cache',
transform: {
'^.+\\.jsx$': 'babel-jest',
'^.+\\.tsx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}
```

0 comments on commit 4a95c76

Please sign in to comment.