mirror of
https://github.com/status-im/react-native.git
synced 2025-01-13 02:54:42 +00:00
Updates tests to work with new install output
This commit is contained in:
parent
2efce394f5
commit
800502f2a0
44
local-cli/__tests__/install-test.js
Normal file
44
local-cli/__tests__/install-test.js
Normal file
@ -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) {}
|
||||
});
|
||||
});
|
@ -1,38 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
jest.dontMock('../install');
|
||||
|
||||
var install = require('../install.js');
|
||||
var fs = require('fs');
|
||||
|
||||
describe('setup Podfile', function() {
|
||||
it('creates a Podfile', function() {
|
||||
fs.mkdirSync('./podfile-test');
|
||||
process.chdir('./podfile-test');
|
||||
var setupPodfile = install.setupPodfile();
|
||||
|
||||
expect(setupPodfile.podfileExists()).toBe(true);
|
||||
process.chdir('../');
|
||||
});
|
||||
|
||||
it('expects Podfile to containing opening & closing react native tag', function() {
|
||||
process.chdir('./podfile-test');
|
||||
var setupPodfile = install.setupPodfile();
|
||||
|
||||
var openingReactTag = '#<React-Native>';
|
||||
var closingReactTag = '#</React-Native>';
|
||||
|
||||
expect(setupPodfile.podfileText()).toContain(openingReactTag);
|
||||
expect(setupPodfile.podfileText()).toContain(closingReactTag);
|
||||
process.chdir('../');
|
||||
});
|
||||
|
||||
it('expects Podfile to contain React Pod', function() {
|
||||
process.chdir('./podfile-test');
|
||||
var setupPodfile = install.setupPodfile();
|
||||
expect(setupPodfile.podfileText()).toContain('pod \'React\'');
|
||||
process.chdir('../');
|
||||
fs.unlink("./podfile-test/Podfile");
|
||||
fs.rmdirSync("./podfile-test");
|
||||
});
|
||||
});
|
@ -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,24 +86,13 @@ module.exports = {
|
||||
podfileText.slice(indexOfReactComponents)].join('');
|
||||
|
||||
fs.writeFileSync(PODFILE_PATH, newPodfileText);
|
||||
returnArgs.podfileText = newPodfileText;
|
||||
} catch(e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
podfileExists: function() {
|
||||
try {
|
||||
var podfileText = fs.readFileSync(PODFILE_PATH, 'utf8');
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
podfileText: function() {
|
||||
return podfileText;
|
||||
}
|
||||
};
|
||||
return returnArgs;
|
||||
},
|
||||
init: function(arguement) {
|
||||
// arguement is available for future arguement commands
|
||||
|
Loading…
x
Reference in New Issue
Block a user