mirror of
https://github.com/status-im/react-native.git
synced 2025-01-17 13:01:13 +00:00
149d0b91c2
Summary: This is initial (first step) in the merging process. For now, we are just going to move our code as is into `local-cli` folder (first commit). There were other tweaks made in separate commits to make it easier to go through the code as the diff is expected to be rather large. The purpose of this is to make it easier to start working in small batches and improving the CLI incrementally on a daily basis. Current codebase will still leave in `rnpm` organisation on Github where we keep working on new features, bugs and ship releases to `npm` until we finish our integration and provide a nice interface for users to migrate (in case it changes at all) Flow, Jest and npm will ignore this folder for now until we integrate it properly. Tests are to be rewritten from mocha to jest in `rnpm/link`. We will hook them all up as soon as we start using them in local-cli. For now, there's no point in having them running and possibly breaking the builds. We will announce next steps with Kureev later this week Closes https://github.com/facebook/react-native/pull/7550 Differential Revision: D3327772 Pulled By: mkonicek fbshipit-source-id: 90faa4bd78476d93ed21b1253e0d95c755d28a30
200 lines
5.0 KiB
JavaScript
200 lines
5.0 KiB
JavaScript
const chai = require('chai');
|
|
const expect = chai.expect;
|
|
const sinon = require('sinon');
|
|
const mock = require('mock-require');
|
|
const log = require('npmlog');
|
|
const path = require('path');
|
|
|
|
const link = require('../src/link');
|
|
|
|
log.level = 'silent';
|
|
|
|
describe('link', () => {
|
|
|
|
beforeEach(() => {
|
|
delete require.cache[require.resolve('../src/link')];
|
|
});
|
|
|
|
it('should reject when run in a folder without package.json', (done) => {
|
|
const config = {
|
|
getProjectConfig: () => {
|
|
throw new Error('No package.json found');
|
|
},
|
|
};
|
|
|
|
link(config).catch(() => done());
|
|
});
|
|
|
|
it('should accept a name of a dependency to link', (done) => {
|
|
const config = {
|
|
getProjectConfig: () => ({ assets: [] }),
|
|
getDependencyConfig: sinon.stub().returns({ assets: [], commands: {} }),
|
|
};
|
|
|
|
link(config, ['react-native-gradient']).then(() => {
|
|
expect(
|
|
config.getDependencyConfig.calledWith('react-native-gradient')
|
|
).to.be.true;
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should read dependencies from package.json when name not provided', (done) => {
|
|
const config = {
|
|
getProjectConfig: () => ({ assets: [] }),
|
|
getDependencyConfig: sinon.stub().returns({ assets: [], commands: {} }),
|
|
};
|
|
|
|
mock(
|
|
path.join(process.cwd(), 'package.json'),
|
|
{
|
|
dependencies: {
|
|
'react-native-test': '*',
|
|
},
|
|
}
|
|
);
|
|
|
|
link(config, []).then(() => {
|
|
expect(
|
|
config.getDependencyConfig.calledWith('react-native-test')
|
|
).to.be.true;
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should register native module when android/ios projects are present', (done) => {
|
|
const registerNativeModule = sinon.stub();
|
|
const dependencyConfig = {android: {}, ios: {}, assets: [], commands: {}};
|
|
const config = {
|
|
getProjectConfig: () => ({android: {}, ios: {}, assets: []}),
|
|
getDependencyConfig: sinon.stub().returns(dependencyConfig),
|
|
};
|
|
|
|
mock(
|
|
'../src/android/isInstalled.js',
|
|
sinon.stub().returns(false)
|
|
);
|
|
|
|
mock(
|
|
'../src/android/registerNativeModule.js',
|
|
registerNativeModule
|
|
);
|
|
|
|
mock(
|
|
'../src/ios/isInstalled.js',
|
|
sinon.stub().returns(false)
|
|
);
|
|
|
|
mock(
|
|
'../src/ios/registerNativeModule.js',
|
|
registerNativeModule
|
|
);
|
|
|
|
const link = require('../src/link');
|
|
|
|
link(config, ['react-native-blur']).then(() => {
|
|
expect(registerNativeModule.calledTwice).to.be.true;
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should not register modules when they are already installed', (done) => {
|
|
const registerNativeModule = sinon.stub();
|
|
const dependencyConfig = {ios: {}, android: {}, assets: [], commands: {}};
|
|
const config = {
|
|
getProjectConfig: () => ({ ios: {}, android: {}, assets: [] }),
|
|
getDependencyConfig: sinon.stub().returns(dependencyConfig),
|
|
};
|
|
|
|
mock(
|
|
'../src/ios/isInstalled.js',
|
|
sinon.stub().returns(true)
|
|
);
|
|
|
|
mock(
|
|
'../src/android/isInstalled.js',
|
|
sinon.stub().returns(true)
|
|
);
|
|
|
|
mock(
|
|
'../src/ios/registerNativeModule.js',
|
|
registerNativeModule
|
|
);
|
|
|
|
mock(
|
|
'../src/android/registerNativeModule.js',
|
|
registerNativeModule
|
|
);
|
|
|
|
const link = require('../src/link');
|
|
|
|
link(config, ['react-native-blur']).then(() => {
|
|
expect(registerNativeModule.callCount).to.equal(0);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should run prelink and postlink commands at the appropriate times', (done) => {
|
|
const registerNativeModule = sinon.stub();
|
|
const prelink = sinon.stub().yieldsAsync();
|
|
const postlink = sinon.stub().yieldsAsync();
|
|
|
|
mock(
|
|
'../src/ios/registerNativeModule.js',
|
|
registerNativeModule
|
|
);
|
|
|
|
mock(
|
|
'../src/ios/isInstalled.js',
|
|
sinon.stub().returns(false)
|
|
);
|
|
|
|
const config = {
|
|
getProjectConfig: () => ({ ios: {}, assets: [] }),
|
|
getDependencyConfig: sinon.stub().returns({
|
|
ios: {}, assets: [], commands: { prelink, postlink },
|
|
}),
|
|
};
|
|
|
|
const link = require('../src/link');
|
|
|
|
link(config, ['react-native-blur']).then(() => {
|
|
expect(prelink.calledBefore(registerNativeModule)).to.be.true;
|
|
expect(postlink.calledAfter(registerNativeModule)).to.be.true;
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should copy assets from both project and dependencies projects', (done) => {
|
|
const dependencyAssets = ['Fonts/Font.ttf'];
|
|
const dependencyConfig = {assets: dependencyAssets, commands: {}};
|
|
const projectAssets = ['Fonts/FontC.ttf'];
|
|
const copyAssets = sinon.stub();
|
|
|
|
mock(
|
|
'../src/ios/copyAssets.js',
|
|
copyAssets
|
|
);
|
|
|
|
const config = {
|
|
getProjectConfig: () => ({ ios: {}, assets: projectAssets }),
|
|
getDependencyConfig: sinon.stub().returns(dependencyConfig),
|
|
};
|
|
|
|
const link = require('../src/link');
|
|
|
|
link(config, ['react-native-blur']).then(() => {
|
|
expect(copyAssets.calledOnce).to.be.true;
|
|
expect(copyAssets.getCall(0).args[0]).to.deep.equals(
|
|
projectAssets.concat(dependencyAssets)
|
|
);
|
|
done();
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
mock.stopAll();
|
|
});
|
|
|
|
});
|