Skip to content
This repository was archived by the owner on Mar 25, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Node.js mock for react-native-config
# react-native-config-node
[![Version][version-badge]][package]
[![semantic-release][semantic-release-badge]](https://github.com/semantic-release/semantic-release)
[![MIT License][license-badge]][license]

Node.js mock for react-native-config

A mock for [react-native-config](https://github.com/luggg/react-native-config), a module which offers an elegant way to inject environment-specific variables to [react-native](https://facebook.github.io/react-native/).

Expand Down Expand Up @@ -53,27 +58,15 @@ NODE_ENV=staging mocha --compilers js:./test/lib/babel-register test/spec/*.js

## Jest

In order to use this mock with jest, you will need to add a plugin that renames imported module.

```
npm i babel-plugin-import-rename --save-dev
```

Add the following to your .babelrc
Add the following plugin to your `babel.config.js` or `.babelrc`

```
{
"presets": ["module:metro-react-native-babel-preset"],
"env": {
"test": {
"plugins": [
[
"import-rename",
{
"^react-native-config$": "react-native-config-node"
}
]
]
"plugins": ['react-native-config-node/transform']
}
}
}
Expand All @@ -90,13 +83,13 @@ NODE_ENV=staging jest
`react-native-config-node/transform` is a babel-plugin transforming the following code

```js
import Config from `react-native-config`
import Config from 'react-native-config'
```

into

```js
import Config from `react-native-config-node`
import Config from 'react-native-config-node'
```

`react-native-config-node` offers the same API as `react-native-config` using [dotenv](https://www.npmjs.com/package/dotenv).
Expand All @@ -105,3 +98,9 @@ import Config from `react-native-config-node`
## License

MIT

[semantic-release-badge]:https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[license]: https://opensource.org/licenses/MIT
[version-badge]: https://img.shields.io/npm/v/react-native-config-node.svg
[package]: https://www.npmjs.com/package/react-native-config-node
[license-badge]: https://img.shields.io/npm/l/react-native-config-node.svg
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@
"name": "react-native-config-node",
"version": "0.0.3",
"description": "Mock for react-native-config in nodejs environment, used for testing",
"main": "index",
"keywords": [
"env",
"react-native",
"12factor",
"config"
],
"scripts": {
"test": "mocha test/transform.js && cd test && ./run-test.sh"
},
"homepage": "https://github.com/CureApp/react-native-config-node",
"repository": {
"type": "git",
"url": "https://github.com/CureApp/react-native-config-node.git"
},
"homepage": "https://github.com/CureApp/react-native-config-node",
"author": "CureApp, Inc.",
"license": "MIT",
"author": "CureApp, Inc.",
"main": "index.js",
"files": [
"index.js",
"transform.js"
],
"scripts": {
"test": "mocha test/transform.js && cd test && ./run-test.sh"
},
"dependencies": {
"dotenv": "^8.2.0"
},
Expand Down