diff --git a/local-cli/core/__tests__/findPlugins.spec.js b/local-cli/core/__tests__/findPlugins.spec.js index c25ab77c1b21fa..e0fb5aef5635ac 100644 --- a/local-cli/core/__tests__/findPlugins.spec.js +++ b/local-cli/core/__tests__/findPlugins.spec.js @@ -1,25 +1,37 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + jest.autoMockOff(); const path = require('path'); const findPlugins = require('../findPlugins'); -const pjsonPath = path.join(process.cwd(), 'package.json'); +const ROOT = path.join(__dirname, '..', '..', '..'); +const pjsonPath = path.join(ROOT, 'package.json'); const isArray = (arg) => Object.prototype.toString.call(arg) === '[object Array]'; describe('findPlugins', () => { + beforeEach(() => jest.resetModules()); + it('should return an array of dependencies', () => { - jest.setMock(pjsonPath, { + jest.mock(pjsonPath, () => ({ dependencies: { 'rnpm-plugin-test': '*' }, - }); - expect(findPlugins([process.cwd()]).length).toBe(1); - expect(findPlugins([process.cwd()])[0]).toBe('rnpm-plugin-test'); + })); + expect(findPlugins([ROOT]).length).toBe(1); + expect(findPlugins([ROOT])[0]).toBe('rnpm-plugin-test'); }); it('should return an empty array if there\'re no plugins in this folder', () => { - jest.setMock(pjsonPath, {}); - expect(findPlugins([process.cwd()]).length).toBe(0); + jest.mock(pjsonPath, () => ({})); + expect(findPlugins([ROOT]).length).toBe(0); }); it('should return an empty array if there\'s no package.json in the supplied folder', () => { @@ -28,19 +40,19 @@ describe('findPlugins', () => { }); it('should return plugins from both dependencies and dev dependencies', () => { - jest.setMock(pjsonPath, { + jest.mock(pjsonPath, () => ({ dependencies: { 'rnpm-plugin-test': '*' }, devDependencies: { 'rnpm-plugin-test-2': '*' }, - }); - expect(findPlugins([process.cwd()]).length).toEqual(2); + })); + expect(findPlugins([ROOT]).length).toEqual(2); }); it('should return unique list of plugins', () => { - jest.setMock(pjsonPath, { + jest.mock(pjsonPath, () => ({ dependencies: { 'rnpm-plugin-test': '*' }, devDependencies: { 'rnpm-plugin-test': '*' }, - }); - expect(findPlugins([process.cwd()]).length).toEqual(1); + })); + expect(findPlugins([ROOT]).length).toEqual(1); }); }); diff --git a/package.json b/package.json index 810c7f9d04fc0d..50e7cd7d5ada7d 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,13 @@ "node": ">=4" }, "jest": { + "automock": true, "scriptPreprocessor": "jestSupport/preprocessor.js", - "setupEnvScriptFile": "jestSupport/env.js", + "setupFiles": [ + "jestSupport/env.js" + ], + "timers": "fake", + "resetModules": true, "moduleNameMapper": { "^image![a-zA-Z0-9$_-]+$": "GlobalImageStub", "^[./a-zA-Z0-9$_-]+\\.png$": "RelativeImageStub" @@ -203,9 +208,9 @@ "eslint-plugin-flow-vars": "^0.2.1", "eslint-plugin-react": "^4.2.1", "flow-bin": "^0.31.1", - "jest": "~14.1.0", - "jest-repl": "~14.1.0", - "jest-runtime": "~14.1.0", + "jest": "15.1.0", + "jest-repl": "15.1.0", + "jest-runtime": "15.1.0", "mock-fs": "^3.11.0", "portfinder": "0.4.0", "react": "15.3.1-rc.2",