Update to Jest 15

Reviewed By: kassens

Differential Revision: D3805404

fbshipit-source-id: 0aa60cf1be889b306b41876f7b09f4f7f933fcf1
This commit is contained in:
Christoph Pojer 2016-09-02 05:54:18 -07:00 committed by Facebook Github Bot 6
parent cd1a86db36
commit d7fdc448d5
2 changed files with 34 additions and 17 deletions

View File

@ -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);
});
});

View File

@ -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",