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
|
* @format
|
||||||
* @emails oncall+javascript_foundation
|
* @emails oncall+javascript_foundation
|
||||||
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -13,20 +14,22 @@
|
||||||
const getProjectDependencies = require('../getProjectDependencies');
|
const getProjectDependencies = require('../getProjectDependencies');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
const CWD = path.resolve(__dirname, '../../..');
|
||||||
|
|
||||||
describe('getProjectDependencies', () => {
|
describe('getProjectDependencies', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
});
|
});
|
||||||
it('should return an array of project dependencies', () => {
|
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'},
|
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', () => {
|
it('should return an empty array when no dependencies set', () => {
|
||||||
jest.setMock(path.join(process.cwd(), './package.json'), {});
|
jest.setMock(path.join(CWD, './package.json'), {});
|
||||||
expect(getProjectDependencies()).toEqual([]);
|
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 => {
|
it('should register native module when android/ios projects are present', done => {
|
||||||
const registerNativeModule = sinon.stub();
|
const registerNativeModule = sinon.stub();
|
||||||
const dependencyConfig = {android: {}, ios: {}, assets: [], commands: {}};
|
const dependencyConfig = {android: {}, ios: {}, assets: [], commands: {}};
|
||||||
|
|
|
@ -12,8 +12,8 @@ const path = require('path');
|
||||||
/**
|
/**
|
||||||
* Returns an array of dependencies that should be linked/checked.
|
* Returns an array of dependencies that should be linked/checked.
|
||||||
*/
|
*/
|
||||||
module.exports = function getProjectDependencies() {
|
module.exports = function getProjectDependencies(cwd) {
|
||||||
const pjson = require(path.join(process.cwd(), './package.json'));
|
const pjson = require(path.join(cwd || process.cwd(), './package.json'));
|
||||||
return Object.keys(pjson.dependencies || {}).filter(
|
return Object.keys(pjson.dependencies || {}).filter(
|
||||||
name => name !== 'react-native',
|
name => name !== 'react-native',
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue