react-native-config-node
react-native-config-node
npm i react-native-config-node
react-native-config-node

react-native-config-node

Mock for react-native-config in nodejs environment, used for testing.

by CureApp

0.0.3 (see all)License:MITTypeScript:Not Found
npm i react-native-config-node
Readme

react-native-config-node

Version semantic-release MIT License

Node.js mock for react-native-config

A mock for react-native-config, a module which offers an elegant way to inject environment-specific variables to react-native.

As react-native-config contains native codes, it cannot be run in Nodejs environment. We provide a way to mock the module.

Installation

via NPM:

npm install --save-dev react-native-config-node

via Yarn:

yarn add -D react-native-config-node

Usage

Mocha

Create a compiler file using babel-register.

test/lib/babel-register.js

module.exports = require('babel-register')({
    plugins: ['react-native-config-node/transform']
})

Use it via command.

mocha --compilers js:./test/lib/babel-register test/spec/*.js

Alternatively, you can set mocha.opts.

--compilers js:./test/lib/babel-register

You can pass specific environment via NODE_ENV variable.

NODE_ENV=staging mocha --compilers js:./test/lib/babel-register test/spec/*.js

.env.staging will be loaded.

Jest

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

{
  "presets": ["module:metro-react-native-babel-preset"],
  "env": {
    "test": {
      "plugins": ['react-native-config-node/transform']
    }
  }
}

You can pass specific environment via NODE_ENV variable.

NODE_ENV=staging jest

.env.staging will be loaded.

How it works

react-native-config-node/transform is a babel-plugin transforming the following code

import Config from 'react-native-config'

into

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

react-native-config-node offers the same API as react-native-config using dotenv.

License

MIT

Downloads/wk

2.4K

GitHub Stars

16

LAST COMMIT

2yrs ago

MAINTAINERS

1

CONTRIBUTORS

8

OPEN ISSUES

3

OPEN PRs

4
VersionTagPublished
0.0.3
latest
3yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate