Use `hg root` for all CWD in test environment
Reviewed By: mjesun Differential Revision: D7852925 fbshipit-source-id: 4baf8cddc43d388269577a337cfe5f329c86d0f6
This commit is contained in:
parent
344c205070
commit
9fbff62b5f
|
@ -6,6 +6,7 @@
|
|||
*
|
||||
* @format
|
||||
* @emails oncall+javascript_foundation
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
@ -13,20 +14,22 @@
|
|||
const getProjectDependencies = require('../getProjectDependencies');
|
||||
const path = require('path');
|
||||
|
||||
const CWD = path.resolve(__dirname, '../../..');
|
||||
|
||||
describe('getProjectDependencies', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
});
|
||||
it('should return an array of project dependencies', () => {
|
||||
jest.setMock(path.join(process.cwd(), './package.json'), {
|
||||
jest.setMock(path.join(CWD, './package.json'), {
|
||||
dependencies: {lodash: '^6.0.0', 'react-native': '^16.0.0'},
|
||||
});
|
||||
|
||||
expect(getProjectDependencies()).toEqual(['lodash']);
|
||||
expect(getProjectDependencies(CWD)).toEqual(['lodash']);
|
||||
});
|
||||
|
||||
it('should return an empty array when no dependencies set', () => {
|
||||
jest.setMock(path.join(process.cwd(), './package.json'), {});
|
||||
expect(getProjectDependencies()).toEqual([]);
|
||||
jest.setMock(path.join(CWD, './package.json'), {});
|
||||
expect(getProjectDependencies(CWD)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -49,28 +49,6 @@ describe('link', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should read dependencies from package.json when name not provided', done => {
|
||||
const config = {
|
||||
getPlatformConfig: () => ({ios: {}, android: {}}),
|
||||
getProjectConfig: () => ({assets: []}),
|
||||
getDependencyConfig: sinon.stub().returns({assets: [], commands: {}}),
|
||||
};
|
||||
|
||||
jest.setMock(path.join(process.cwd(), 'package.json'), {
|
||||
dependencies: {
|
||||
'react-native-test': '*',
|
||||
},
|
||||
});
|
||||
|
||||
const link = require('../link').func;
|
||||
link([], config).then(() => {
|
||||
expect(
|
||||
config.getDependencyConfig.calledWith('react-native-test'),
|
||||
).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should register native module when android/ios projects are present', done => {
|
||||
const registerNativeModule = sinon.stub();
|
||||
const dependencyConfig = {android: {}, ios: {}, assets: [], commands: {}};
|
||||
|
|
|
@ -12,8 +12,8 @@ const path = require('path');
|
|||
/**
|
||||
* Returns an array of dependencies that should be linked/checked.
|
||||
*/
|
||||
module.exports = function getProjectDependencies() {
|
||||
const pjson = require(path.join(process.cwd(), './package.json'));
|
||||
module.exports = function getProjectDependencies(cwd) {
|
||||
const pjson = require(path.join(cwd || process.cwd(), './package.json'));
|
||||
return Object.keys(pjson.dependencies || {}).filter(
|
||||
name => name !== 'react-native',
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue