2016-09-02 12:54:18 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-06-10 06:56:03 +00:00
|
|
|
*
|
|
|
|
* @format
|
2017-11-02 13:14:11 +00:00
|
|
|
* @emails oncall+javascript_foundation
|
2016-09-02 12:54:18 +00:00
|
|
|
*/
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-08-22 15:56:14 +00:00
|
|
|
const findPlugins = require('../findPlugins');
|
2017-06-10 06:56:03 +00:00
|
|
|
const path = require('path');
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2016-09-02 12:54:18 +00:00
|
|
|
const ROOT = path.join(__dirname, '..', '..', '..');
|
|
|
|
const pjsonPath = path.join(ROOT, 'package.json');
|
2016-05-20 11:52:08 +00:00
|
|
|
|
|
|
|
describe('findPlugins', () => {
|
2017-06-10 06:56:03 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules();
|
|
|
|
});
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('returns an array of dependencies', () => {
|
2016-09-02 12:54:18 +00:00
|
|
|
jest.mock(pjsonPath, () => ({
|
2017-06-10 06:56:03 +00:00
|
|
|
dependencies: {'rnpm-plugin-test': '*'},
|
2016-09-02 12:54:18 +00:00
|
|
|
}));
|
2018-02-08 17:45:16 +00:00
|
|
|
|
|
|
|
expect(findPlugins([ROOT])).toHaveProperty('commands');
|
|
|
|
expect(findPlugins([ROOT])).toHaveProperty('platforms');
|
|
|
|
expect(findPlugins([ROOT]).commands).toHaveLength(1);
|
|
|
|
expect(findPlugins([ROOT]).commands[0]).toBe('rnpm-plugin-test');
|
|
|
|
expect(findPlugins([ROOT]).platforms).toHaveLength(0);
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('returns an empty array if there are no plugins in this folder', () => {
|
2016-09-02 12:54:18 +00:00
|
|
|
jest.mock(pjsonPath, () => ({}));
|
2018-02-08 17:45:16 +00:00
|
|
|
expect(findPlugins([ROOT])).toHaveProperty('commands');
|
|
|
|
expect(findPlugins([ROOT])).toHaveProperty('platforms');
|
|
|
|
expect(findPlugins([ROOT]).commands).toHaveLength(0);
|
|
|
|
expect(findPlugins([ROOT]).platforms).toHaveLength(0);
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|
|
|
|
|
2018-02-08 17:45:16 +00:00
|
|
|
it('returns an object with empty arrays if there is no package.json in the supplied folder', () => {
|
|
|
|
expect(findPlugins(['fake-path'])).toHaveProperty('commands');
|
|
|
|
expect(findPlugins(['fake-path'])).toHaveProperty('platforms');
|
|
|
|
expect(findPlugins(['fake-path']).commands).toHaveLength(0);
|
|
|
|
expect(findPlugins(['fake-path']).platforms).toHaveLength(0);
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('returns plugins from both dependencies and dev dependencies', () => {
|
2016-09-02 12:54:18 +00:00
|
|
|
jest.mock(pjsonPath, () => ({
|
2017-06-10 06:56:03 +00:00
|
|
|
dependencies: {'rnpm-plugin-test': '*'},
|
|
|
|
devDependencies: {'rnpm-plugin-test-2': '*'},
|
2016-09-02 12:54:18 +00:00
|
|
|
}));
|
2018-02-08 17:45:16 +00:00
|
|
|
expect(findPlugins([ROOT])).toHaveProperty('commands');
|
|
|
|
expect(findPlugins([ROOT])).toHaveProperty('platforms');
|
|
|
|
expect(findPlugins([ROOT]).commands).toHaveLength(2);
|
|
|
|
expect(findPlugins([ROOT]).platforms).toHaveLength(0);
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('returns unique list of plugins', () => {
|
2016-09-02 12:54:18 +00:00
|
|
|
jest.mock(pjsonPath, () => ({
|
2017-06-10 06:56:03 +00:00
|
|
|
dependencies: {'rnpm-plugin-test': '*'},
|
|
|
|
devDependencies: {'rnpm-plugin-test': '*'},
|
2016-09-02 12:54:18 +00:00
|
|
|
}));
|
2018-02-08 17:45:16 +00:00
|
|
|
expect(findPlugins([ROOT]).commands).toHaveLength(1);
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|
|
|
|
});
|