Skip to content

Commit

Permalink
Update to Jest 15
Browse files Browse the repository at this point in the history
Reviewed By: kassens

Differential Revision: D3805404

fbshipit-source-id: 0aa60cf1be889b306b41876f7b09f4f7f933fcf1
  • Loading branch information
cpojer authored and Facebook Github Bot 6 committed Sep 2, 2016
1 parent cd1a86d commit d7fdc44
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
38 changes: 25 additions & 13 deletions 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', () => {
Expand All @@ -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);
});

});
13 changes: 9 additions & 4 deletions package.json
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit d7fdc44

Please sign in to comment.