Merge pull request #727 from TomMcHugh/master
[CLI] Adds Testing to CLI
This commit is contained in:
commit
7c49d293f1
|
@ -0,0 +1,44 @@
|
|||
'use strict';
|
||||
|
||||
jest.dontMock('../install');
|
||||
jest.dontMock('fs');
|
||||
jest.dontMock('path');
|
||||
|
||||
var install = require('../install.js');
|
||||
|
||||
var openingReactTag = '#<React-Native>';
|
||||
var closingReactTag = '#</React-Native>';
|
||||
|
||||
var fs = require.requireActual('fs');
|
||||
var path = require.requireActual('path');
|
||||
|
||||
process.chdir(__dirname);
|
||||
|
||||
describe('setup Podfile', function() {
|
||||
|
||||
it('creates a Podfile if none exists', function() {
|
||||
try {
|
||||
fs.unlinkSync(path.resolve(__dirname, 'Podfile'));
|
||||
} catch(e) {}
|
||||
|
||||
var setupPodfile = install.setupPodfile();
|
||||
|
||||
expect(setupPodfile.created).toBe(true);
|
||||
});
|
||||
|
||||
it('does not create Podfile if one exists', function() {
|
||||
var setupPodfile = install.setupPodfile();
|
||||
expect(setupPodfile.created).toBe(false);
|
||||
});
|
||||
|
||||
it('includes React Native Tags', function() {
|
||||
var setupPodfile = install.setupPodfile();
|
||||
|
||||
expect(setupPodfile.podfileText).toContain(openingReactTag);
|
||||
expect(setupPodfile.podfileText).toContain(closingReactTag);
|
||||
|
||||
try {
|
||||
fs.unlinkSync(path.resolve(__dirname, 'Podfile'));
|
||||
} catch(e) {}
|
||||
});
|
||||
});
|
|
@ -5,11 +5,12 @@
|
|||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
var NODE_MODULE_PATH = './node_modules';
|
||||
var NODE_MODULE_PATH = path.resolve(__dirname, 'node_modules');
|
||||
|
||||
var PODFILE_PATH = './Podfile';
|
||||
var PODFILE_PATH = path.resolve(__dirname, 'Podfile');
|
||||
|
||||
function addDependency(name, path) {
|
||||
console.log('Found dependency: ' + name);
|
||||
|
@ -48,6 +49,10 @@ function installDependecies() {
|
|||
|
||||
module.exports = {
|
||||
setupPodfile: function() {
|
||||
var returnArgs = {
|
||||
created: false
|
||||
};
|
||||
|
||||
var podfileText;
|
||||
try {
|
||||
podfileText = fs.readFileSync(PODFILE_PATH, 'utf8');
|
||||
|
@ -58,6 +63,7 @@ module.exports = {
|
|||
var reactPodfileBoilerplate = openingReactTag + closingReactTag;
|
||||
|
||||
if (!podfileText) {
|
||||
returnArgs.created = true;
|
||||
fs.appendFileSync(PODFILE_PATH, reactPodfileBoilerplate);
|
||||
} else {
|
||||
if (podfileText.indexOf(openingReactTag) === -1 || podfileText.indexOf(closingReactTag) === -1) {
|
||||
|
@ -67,6 +73,7 @@ module.exports = {
|
|||
|
||||
try {
|
||||
podfileText = fs.readFileSync(PODFILE_PATH, 'utf8');
|
||||
returnArgs.podfileText = podfileText;
|
||||
} catch(e) {}
|
||||
|
||||
if (podfileText.indexOf('pod \'React\'') === -1) {
|
||||
|
@ -79,10 +86,13 @@ module.exports = {
|
|||
podfileText.slice(indexOfReactComponents)].join('');
|
||||
|
||||
fs.writeFileSync(PODFILE_PATH, newPodfileText);
|
||||
returnArgs.podfileText = newPodfileText;
|
||||
} catch(e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return returnArgs;
|
||||
},
|
||||
init: function(arguement) {
|
||||
// arguement is available for future arguement commands
|
||||
|
|
Loading…
Reference in New Issue