RN: Cleanup `local-cli/core/__tests__`
Reviewed By: raluca-elena Differential Revision: D5224347 fbshipit-source-id: 99a729c49bec28bf89d9dc91530958beec878828
This commit is contained in:
parent
82edc131b0
commit
223eab930b
|
@ -1,30 +1,48 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
const mockFS = require('mock-fs');
|
||||
|
||||
const findAndroidAppFolder = require('../../android/findAndroidAppFolder');
|
||||
const mockFs = require('mock-fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
describe('android::findAndroidAppFolder', () => {
|
||||
beforeAll(() => mockFs({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
app: mocks.valid,
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
app: mocks.valid,
|
||||
},
|
||||
},
|
||||
},
|
||||
flat: {
|
||||
android: mocks.valid,
|
||||
},
|
||||
}));
|
||||
flat: {
|
||||
android: mocks.valid,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an android app folder if it exists in the given folder', () => {
|
||||
it('returns an android app folder if it exists in the given folder', () => {
|
||||
expect(findAndroidAppFolder('flat')).toBe('android');
|
||||
expect(findAndroidAppFolder('nested')).toBe('android/app');
|
||||
});
|
||||
|
||||
it('should return `null` if there\'s no android app folder', () => {
|
||||
expect(findAndroidAppFolder('empty')).toBe(null);
|
||||
it('returns `null` if there is no android app folder', () => {
|
||||
expect(findAndroidAppFolder('empty')).toBeNull();
|
||||
});
|
||||
|
||||
afterAll(mockFs.restore);
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,25 +1,42 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
const mockFS = require('mock-fs');
|
||||
|
||||
const findManifest = require('../../android/findManifest');
|
||||
const mockFs = require('mock-fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
describe('android::findManifest', () => {
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
empty: {},
|
||||
flat: {
|
||||
android: mocks.valid,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
beforeAll(() => mockFs({
|
||||
empty: {},
|
||||
flat: {
|
||||
android: mocks.valid,
|
||||
},
|
||||
}));
|
||||
|
||||
it('should return a manifest path if file exists in the folder', () => {
|
||||
it('returns a manifest path if file exists in the folder', () => {
|
||||
expect(typeof findManifest('flat')).toBe('string');
|
||||
});
|
||||
|
||||
it('should return `null` if there is no manifest in the folder', () => {
|
||||
expect(findManifest('empty')).toBe(null);
|
||||
it('returns `null` if there is no manifest in the folder', () => {
|
||||
expect(findManifest('empty')).toBeNull();
|
||||
});
|
||||
|
||||
afterAll(mockFs.restore);
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,25 +1,42 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
const mockFS = require('mock-fs');
|
||||
|
||||
const findPackageClassName = require('../../android/findPackageClassName');
|
||||
const mockFs = require('mock-fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
describe('android::findPackageClassName', () => {
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
empty: {},
|
||||
flat: {
|
||||
android: mocks.valid,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
beforeAll(() => mockFs({
|
||||
empty: {},
|
||||
flat: {
|
||||
android: mocks.valid,
|
||||
},
|
||||
}));
|
||||
|
||||
it('should return manifest content if file exists in the folder', () => {
|
||||
it('returns manifest content if file exists in the folder', () => {
|
||||
expect(typeof findPackageClassName('flat')).toBe('string');
|
||||
});
|
||||
|
||||
it('should return `null` if there\'s no matches', () => {
|
||||
expect(findPackageClassName('empty')).toBe(null);
|
||||
it('returns `null` if there are no matches', () => {
|
||||
expect(findPackageClassName('empty')).toBeNull();
|
||||
});
|
||||
|
||||
afterAll(mockFs.restore);
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,49 +1,67 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
const mockFS = require('mock-fs');
|
||||
|
||||
const getDependencyConfig = require('../../android').dependencyConfig;
|
||||
const mockFs = require('mock-fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
const userConfig = {};
|
||||
|
||||
describe('android::getDependencyConfig', () => {
|
||||
|
||||
beforeAll(() => mockFs({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
app: mocks.valid,
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
app: mocks.valid,
|
||||
},
|
||||
},
|
||||
},
|
||||
corrupted: {
|
||||
android: {
|
||||
app: mocks.corrupted,
|
||||
corrupted: {
|
||||
android: {
|
||||
app: mocks.corrupted,
|
||||
},
|
||||
},
|
||||
},
|
||||
noPackage: {
|
||||
android: {},
|
||||
},
|
||||
}));
|
||||
noPackage: {
|
||||
android: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an object with android project configuration', () => {
|
||||
expect(getDependencyConfig('nested', userConfig)).not.toBe(null);
|
||||
it('returns an object with android project configuration', () => {
|
||||
expect(getDependencyConfig('nested', userConfig)).not.toBeNull();
|
||||
expect(typeof getDependencyConfig('nested', userConfig)).toBe('object');
|
||||
});
|
||||
|
||||
it('should return `null` if manifest file hasn\'t been found', () => {
|
||||
expect(getDependencyConfig('empty', userConfig)).toBe(null);
|
||||
it('returns `null` if manifest file has not been found', () => {
|
||||
expect(getDependencyConfig('empty', userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return `null` if android project was not found', () => {
|
||||
expect(getDependencyConfig('empty', userConfig)).toBe(null);
|
||||
it('returns `null` if android project was not found', () => {
|
||||
expect(getDependencyConfig('empty', userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return `null` if android project does not contain ReactPackage', () => {
|
||||
expect(getDependencyConfig('noPackage', userConfig)).toBe(null);
|
||||
it('returns `null` if android project does not contain ReactPackage', () => {
|
||||
expect(getDependencyConfig('noPackage', userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return `null` if it can\'t find a packageClassName', () => {
|
||||
expect(getDependencyConfig('corrupted', userConfig)).toBe(null);
|
||||
it('returns `null` if it cannot find a packageClassName', () => {
|
||||
expect(getDependencyConfig('corrupted', userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
afterAll(mockFs.restore);
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,41 +1,57 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
const mockFS = require('mock-fs');
|
||||
|
||||
const getProjectConfig = require('../../android').projectConfig;
|
||||
const mockFs = require('mock-fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
describe('android::getProjectConfig', () => {
|
||||
beforeAll(() => mockFs({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
app: mocks.valid,
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
app: mocks.valid,
|
||||
},
|
||||
},
|
||||
},
|
||||
flat: {
|
||||
android: mocks.valid,
|
||||
},
|
||||
multiple: {
|
||||
android: mocks.userConfigManifest,
|
||||
},
|
||||
noManifest: {
|
||||
android: {},
|
||||
},
|
||||
}));
|
||||
flat: {
|
||||
android: mocks.valid,
|
||||
},
|
||||
multiple: {
|
||||
android: mocks.userConfigManifest,
|
||||
},
|
||||
noManifest: {
|
||||
android: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should return `null` if manifest file hasn\'t been found', () => {
|
||||
it("returns `null` if manifest file hasn't been found", () => {
|
||||
const userConfig = {};
|
||||
const folder = 'noManifest';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).toBe(null);
|
||||
expect(getProjectConfig(folder, userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
describe('return an object with android project configuration for', () => {
|
||||
describe('returns an object with android project configuration for', () => {
|
||||
it('nested structure', () => {
|
||||
const userConfig = {};
|
||||
const folder = 'nested';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBe(null);
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBeNull();
|
||||
expect(typeof getProjectConfig(folder, userConfig)).toBe('object');
|
||||
});
|
||||
|
||||
|
@ -43,17 +59,17 @@ describe('android::getProjectConfig', () => {
|
|||
const userConfig = {};
|
||||
const folder = 'flat';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBe(null);
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBeNull();
|
||||
expect(typeof getProjectConfig(folder, userConfig)).toBe('object');
|
||||
});
|
||||
|
||||
it('multiple', () => {
|
||||
const userConfig = {
|
||||
manifestPath: 'src/main/AndroidManifest.xml'
|
||||
manifestPath: 'src/main/AndroidManifest.xml',
|
||||
};
|
||||
const folder = 'multiple';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBe(null);
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBeNull();
|
||||
expect(typeof getProjectConfig(folder, userConfig)).toBe('object');
|
||||
});
|
||||
});
|
||||
|
@ -62,8 +78,10 @@ describe('android::getProjectConfig', () => {
|
|||
const userConfig = {};
|
||||
const folder = 'empty';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).toBe(null);
|
||||
expect(getProjectConfig(folder, userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
afterAll(mockFs.restore);
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,31 +1,50 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
const mockFS = require('mock-fs');
|
||||
|
||||
const findManifest = require('../../android/findManifest');
|
||||
const readManifest = require('../../android/readManifest');
|
||||
const mockFs = require('mock-fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
describe('android::readManifest', () => {
|
||||
|
||||
beforeAll(() => mockFs({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
app: mocks.valid,
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
app: mocks.valid,
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
it('should return manifest content if file exists in the folder', () => {
|
||||
it('returns manifest content if file exists in the folder', () => {
|
||||
const manifestPath = findManifest('nested');
|
||||
expect(readManifest(manifestPath)).not.toBe(null);
|
||||
expect(readManifest(manifestPath)).not.toBeNull();
|
||||
expect(typeof readManifest(manifestPath)).toBe('object');
|
||||
});
|
||||
|
||||
it('should throw an error if there is no manifest in the folder', () => {
|
||||
it('throws an error if there is no manifest in the folder', () => {
|
||||
const fakeManifestPath = findManifest('empty');
|
||||
expect(() => readManifest(fakeManifestPath)).toThrow();
|
||||
expect(() => {
|
||||
readManifest(fakeManifestPath);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
afterAll(mockFs.restore);
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,31 +1,48 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
const findAssets = require('../findAssets');
|
||||
const mockFs = require('mock-fs');
|
||||
|
||||
const findAssets = require('../findAssets');
|
||||
const dependencies = require('../__fixtures__/dependencies');
|
||||
const isArray = (arg) =>
|
||||
Object.prototype.toString.call(arg) === '[object Array]';
|
||||
|
||||
describe('findAssets', () => {
|
||||
beforeEach(() => {
|
||||
mockFs({testDir: dependencies.withAssets});
|
||||
});
|
||||
|
||||
beforeEach(() => mockFs({ testDir: dependencies.withAssets }));
|
||||
|
||||
it('should return an array of all files in given folders', () => {
|
||||
it('returns an array of all files in given folders', () => {
|
||||
const assets = findAssets('testDir', ['fonts', 'images']);
|
||||
|
||||
expect(isArray(assets)).toBeTruthy();
|
||||
expect(assets.length).toEqual(3);
|
||||
expect(Array.isArray(assets)).toBeTruthy();
|
||||
expect(assets).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('should prepend assets paths with the folder path', () => {
|
||||
it('prepends assets paths with the folder path', () => {
|
||||
const assets = findAssets('testDir', ['fonts', 'images']);
|
||||
|
||||
assets.forEach(assetPath => expect(assetPath).toContain('testDir'));
|
||||
assets.forEach(assetPath => {
|
||||
expect(assetPath).toContain('testDir');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an empty array if given assets are null', () => {
|
||||
expect(findAssets('testDir', null).length).toEqual(0);
|
||||
it('returns an empty array if given assets are null', () => {
|
||||
expect(findAssets('testDir', null)).toHaveLength(0);
|
||||
});
|
||||
|
||||
afterEach(mockFs.restore);
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,54 +5,56 @@
|
|||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
const path = require('path');
|
||||
const findPlugins = require('../findPlugins');
|
||||
const path = require('path');
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
beforeEach(() => jest.resetModules());
|
||||
|
||||
it('should return an array of dependencies', () => {
|
||||
it('returns an array of dependencies', () => {
|
||||
jest.mock(pjsonPath, () => ({
|
||||
dependencies: { 'rnpm-plugin-test': '*' },
|
||||
dependencies: {'rnpm-plugin-test': '*'},
|
||||
}));
|
||||
expect(findPlugins([ROOT]).length).toBe(1);
|
||||
expect(findPlugins([ROOT])).toHaveLength(1);
|
||||
expect(findPlugins([ROOT])[0]).toBe('rnpm-plugin-test');
|
||||
});
|
||||
|
||||
it('should return an empty array if there\'re no plugins in this folder', () => {
|
||||
it('returns an empty array if there are no plugins in this folder', () => {
|
||||
jest.mock(pjsonPath, () => ({}));
|
||||
expect(findPlugins([ROOT]).length).toBe(0);
|
||||
expect(findPlugins([ROOT])).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should return an empty array if there\'s no package.json in the supplied folder', () => {
|
||||
expect(isArray(findPlugins(['fake-path']))).toBeTruthy();
|
||||
expect(findPlugins(['fake-path']).length).toBe(0);
|
||||
it('returns an empty array if there is no package.json in the supplied folder', () => {
|
||||
expect(Array.isArray(findPlugins(['fake-path']))).toBeTruthy();
|
||||
expect(findPlugins(['fake-path'])).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should return plugins from both dependencies and dev dependencies', () => {
|
||||
it('returns plugins from both dependencies and dev dependencies', () => {
|
||||
jest.mock(pjsonPath, () => ({
|
||||
dependencies: { 'rnpm-plugin-test': '*' },
|
||||
devDependencies: { 'rnpm-plugin-test-2': '*' },
|
||||
dependencies: {'rnpm-plugin-test': '*'},
|
||||
devDependencies: {'rnpm-plugin-test-2': '*'},
|
||||
}));
|
||||
expect(findPlugins([ROOT]).length).toEqual(2);
|
||||
expect(findPlugins([ROOT])).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should return unique list of plugins', () => {
|
||||
it('returns unique list of plugins', () => {
|
||||
jest.mock(pjsonPath, () => ({
|
||||
dependencies: { 'rnpm-plugin-test': '*' },
|
||||
devDependencies: { 'rnpm-plugin-test': '*' },
|
||||
dependencies: {'rnpm-plugin-test': '*'},
|
||||
devDependencies: {'rnpm-plugin-test': '*'},
|
||||
}));
|
||||
expect(findPlugins([ROOT]).length).toEqual(1);
|
||||
expect(findPlugins([ROOT])).toHaveLength(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,39 +1,52 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
const mockFS = require('mock-fs');
|
||||
|
||||
const findProject = require('../../ios/findProject');
|
||||
const mockFs = require('mock-fs');
|
||||
const projects = require('../../__fixtures__/projects');
|
||||
const ios = require('../../__fixtures__/ios');
|
||||
const userConfig = {};
|
||||
|
||||
describe('ios::findProject', () => {
|
||||
it('should return path to xcodeproj if found', () => {
|
||||
mockFs(projects.flat);
|
||||
expect(findProject('')).not.toBe(null);
|
||||
it('returns path to xcodeproj if found', () => {
|
||||
mockFS(projects.flat);
|
||||
expect(findProject('')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should return null if there\'re no projects', () => {
|
||||
mockFs({ testDir: projects });
|
||||
expect(findProject('')).toBe(null);
|
||||
it('returns null if there are no projects', () => {
|
||||
mockFS({testDir: projects});
|
||||
expect(findProject('')).toBeNull();
|
||||
});
|
||||
|
||||
it('should return ios project regardless of its name', () => {
|
||||
mockFs({ ios: ios.validTestName });
|
||||
expect(findProject('')).not.toBe(null);
|
||||
it('returns ios project regardless of its name', () => {
|
||||
mockFS({ios: ios.validTestName});
|
||||
expect(findProject('')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should ignore node_modules', () => {
|
||||
mockFs({ node_modules: projects.flat });
|
||||
expect(findProject('')).toBe(null);
|
||||
it('ignores node_modules', () => {
|
||||
mockFS({node_modules: projects.flat});
|
||||
expect(findProject('')).toBeNull();
|
||||
});
|
||||
|
||||
it('should ignore Pods', () => {
|
||||
mockFs({ Pods: projects.flat });
|
||||
expect(findProject('')).toBe(null);
|
||||
it('ignores Pods', () => {
|
||||
mockFS({Pods: projects.flat});
|
||||
expect(findProject('')).toBeNull();
|
||||
});
|
||||
|
||||
it('should ignore Pods inside `ios` folder', () => {
|
||||
mockFs({
|
||||
it('ignores Pods inside `ios` folder', () => {
|
||||
mockFS({
|
||||
ios: {
|
||||
Pods: projects.flat,
|
||||
DemoApp: projects.flat.ios,
|
||||
|
@ -42,8 +55,8 @@ describe('ios::findProject', () => {
|
|||
expect(findProject('')).toBe('ios/DemoApp/demoProject.xcodeproj');
|
||||
});
|
||||
|
||||
it('should ignore xcodeproj from example folders', () => {
|
||||
mockFs({
|
||||
it('ignores xcodeproj from example folders', () => {
|
||||
mockFS({
|
||||
examples: projects.flat,
|
||||
Examples: projects.flat,
|
||||
example: projects.flat,
|
||||
|
@ -54,8 +67,8 @@ describe('ios::findProject', () => {
|
|||
expect(findProject('').toLowerCase()).not.toContain('example');
|
||||
});
|
||||
|
||||
it('should ignore xcodeproj from sample folders', () => {
|
||||
mockFs({
|
||||
it('ignores xcodeproj from sample folders', () => {
|
||||
mockFS({
|
||||
samples: projects.flat,
|
||||
Samples: projects.flat,
|
||||
sample: projects.flat,
|
||||
|
@ -66,8 +79,8 @@ describe('ios::findProject', () => {
|
|||
expect(findProject('').toLowerCase()).not.toContain('sample');
|
||||
});
|
||||
|
||||
it('should ignore xcodeproj from test folders at any level', () => {
|
||||
mockFs({
|
||||
it('ignores xcodeproj from test folders at any level', () => {
|
||||
mockFS({
|
||||
test: projects.flat,
|
||||
IntegrationTests: projects.flat,
|
||||
tests: projects.flat,
|
||||
|
@ -80,5 +93,7 @@ describe('ios::findProject', () => {
|
|||
expect(findProject('').toLowerCase()).not.toContain('test');
|
||||
});
|
||||
|
||||
afterEach(mockFs.restore);
|
||||
afterEach(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,36 +1,57 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
const mockFS = require('mock-fs');
|
||||
|
||||
const getProjectConfig = require('../../ios').projectConfig;
|
||||
const mockFs = require('mock-fs');
|
||||
const projects = require('../../__fixtures__/projects');
|
||||
|
||||
describe('ios::getProjectConfig', () => {
|
||||
const userConfig = {};
|
||||
|
||||
beforeEach(() => mockFs({ testDir: projects }));
|
||||
beforeEach(() => {
|
||||
mockFS({testDir: projects});
|
||||
});
|
||||
|
||||
it('should return an object with ios project configuration', () => {
|
||||
it('returns an object with ios project configuration', () => {
|
||||
const folder = 'testDir/nested';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBe(null);
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBeNull();
|
||||
expect(typeof getProjectConfig(folder, userConfig)).toBe('object');
|
||||
});
|
||||
|
||||
it('should return `null` if ios project was not found', () => {
|
||||
it('returns `null` if ios project was not found', () => {
|
||||
const folder = 'testDir/empty';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).toBe(null);
|
||||
expect(getProjectConfig(folder, userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return normalized shared library names', () => {
|
||||
it('returns normalized shared library names', () => {
|
||||
const projectConfig = getProjectConfig('testDir/nested', {
|
||||
sharedLibraries: ['libc++', 'libz.tbd', 'HealthKit', 'HomeKit.framework'],
|
||||
});
|
||||
|
||||
expect(projectConfig.sharedLibraries).toEqual(
|
||||
['libc++.tbd', 'libz.tbd', 'HealthKit.framework', 'HomeKit.framework']
|
||||
);
|
||||
expect(projectConfig.sharedLibraries).toEqual([
|
||||
'libc++.tbd',
|
||||
'libz.tbd',
|
||||
'HealthKit.framework',
|
||||
'HomeKit.framework',
|
||||
]);
|
||||
});
|
||||
|
||||
afterEach(mockFs.restore);
|
||||
afterEach(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,36 +1,50 @@
|
|||
jest.disableAutomock();
|
||||
var spawnError = false;
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
let spawnError = false;
|
||||
|
||||
jest.setMock('child_process', {
|
||||
spawn: () => ({
|
||||
on: (ev, cb) => cb(spawnError),
|
||||
on: (event, cb) => cb(spawnError),
|
||||
}),
|
||||
});
|
||||
jest.dontMock('../makeCommand');
|
||||
|
||||
const makeCommand = require('../makeCommand');
|
||||
|
||||
describe('makeCommand', () => {
|
||||
const command = makeCommand('echo');
|
||||
|
||||
it('should generate a function around shell command', () => {
|
||||
it('generates a function around shell command', () => {
|
||||
expect(typeof command).toBe('function');
|
||||
});
|
||||
|
||||
it('should throw an error if there\'s no callback provided', () => {
|
||||
it('throws an error if there is no callback provided', () => {
|
||||
expect(command).toThrow();
|
||||
});
|
||||
|
||||
it('should invoke a callback after command execution', () => {
|
||||
const spy = jest.genMockFunction();
|
||||
it('invokes a callback after command execution', () => {
|
||||
const spy = jest.fn();
|
||||
command(spy);
|
||||
|
||||
expect(spy.mock.calls.length).toBe(1);
|
||||
expect(spy.mock.calls).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should throw an error if spawn ended up with error', () => {
|
||||
it('throws an error if spawn ended up with error', () => {
|
||||
spawnError = true;
|
||||
const cb = jest.genMockFunction();
|
||||
expect(() => command(cb)).toThrow();
|
||||
const cb = jest.fn();
|
||||
expect(() => {
|
||||
command(cb);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue