mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-29 07:48:17 +08:00
Update to Jest 15
Reviewed By: kassens Differential Revision: D3805404 fbshipit-source-id: 0aa60cf1be889b306b41876f7b09f4f7f933fcf1
This commit is contained in:
committed by
Facebook Github Bot 6
parent
cd1a86db36
commit
d7fdc448d5
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user