Skip to content

Commit

Permalink
RN: Cleanup local-cli/core/__tests__
Browse files Browse the repository at this point in the history
Reviewed By: raluca-elena

Differential Revision: D5224347

fbshipit-source-id: 99a729c49bec28bf89d9dc91530958beec878828
  • Loading branch information
yungsters authored and facebook-github-bot committed Jun 10, 2017
1 parent 82edc13 commit 223eab9
Show file tree
Hide file tree
Showing 11 changed files with 369 additions and 193 deletions.
48 changes: 33 additions & 15 deletions local-cli/core/__tests__/android/findAndroidAppFolder.spec.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
41 changes: 29 additions & 12 deletions local-cli/core/__tests__/android/findManifest.spec.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
41 changes: 29 additions & 12 deletions local-cli/core/__tests__/android/findPackageClassName.spec.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
74 changes: 46 additions & 28 deletions local-cli/core/__tests__/android/getDependencyConfig.spec.js
Original file line number Diff line number Diff line change
@@ -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: {},
},
}));

it('should return an object with android project configuration', () => {
expect(getDependencyConfig('nested', userConfig)).not.toBe(null);
noPackage: {
android: {},
},
});
});

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();
});
});
72 changes: 45 additions & 27 deletions local-cli/core/__tests__/android/getProjectConfig.spec.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,75 @@
/**
* 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,
},
},
flat: {
android: mocks.valid,
},
multiple: {
android: mocks.userConfigManifest,
},
noManifest: {
android: {},
},
}));

it('should return `null` if manifest file hasn\'t been found', () => {
noManifest: {
android: {},
},
});
});

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

it('flat structure', () => {
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');
});
});
Expand All @@ -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();
});
});
Loading

0 comments on commit 223eab9

Please sign in to comment.