diff --git a/local-cli/link/__tests__/getProjectDependencies.spec.js b/local-cli/link/__tests__/getProjectDependencies.spec.js index 974f12819..1a2916351 100644 --- a/local-cli/link/__tests__/getProjectDependencies.spec.js +++ b/local-cli/link/__tests__/getProjectDependencies.spec.js @@ -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([]); }); }); diff --git a/local-cli/link/__tests__/link.spec.js b/local-cli/link/__tests__/link.spec.js index 7e658eb7d..9cbe601f2 100644 --- a/local-cli/link/__tests__/link.spec.js +++ b/local-cli/link/__tests__/link.spec.js @@ -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: {}}; diff --git a/local-cli/link/getProjectDependencies.js b/local-cli/link/getProjectDependencies.js index c078aab1a..9b4838ba9 100644 --- a/local-cli/link/getProjectDependencies.js +++ b/local-cli/link/getProjectDependencies.js @@ -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', );