Last active
April 4, 2016 15:03
-
-
Save jlyman/09d42c856903abd48948daa9ed64c617 to your computer and use it in GitHub Desktop.
Example of getting Mocha going with React Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": ["react-native"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "MochaTestableApp", | |
... | |
"scripts": { | |
... | |
"test": "mocha --require test/testhook --compilers js:babel-register --recursive", | |
}, | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The purpose of this file is to ensure | |
// the babel transpiler is activated prior to any | |
// test code, and using the same babel options | |
/* eslint semi: [2, "always"] */ | |
const fs = require('fs'); | |
const path = require('path'); | |
const config = getBabelRC(); | |
function getBabelRC() { | |
const rcpath = path.join(__dirname, '..', '.babelrc'); | |
const source = fs.readFileSync(rcpath).toString(); | |
return JSON.parse(source); | |
} | |
config.ignore = (filename) => { | |
if (!(/\/node_modules\//).test(filename)) { | |
return false; // if not in node_modules, we want to compile it | |
} else if ((/\/node_modules\/react-native\//).test(filename)) { | |
// its RN source code, so we want to compile it | |
return false; | |
} | |
// else it's in node modules and NOT RN source code | |
return true; | |
}; | |
require('babel-register')(config); | |
global.__DEV__ = true; | |
// Now get some global things available | |
const chai = require('chai'); | |
const sinon = require('sinon'); | |
const dirtyChai = require('dirty-chai'); | |
const chaiImmutable = require('chai-immutable'); | |
const expect = chai.expect; | |
const should = chai.should(); | |
chai.use(dirtyChai); | |
// chai.use(chaiImmutable); | |
global.chai = chai; | |
global.expect = expect; | |
global.should = should; | |
global.sinon = sinon; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment