mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 15:45:32 +00:00
Remove mockFs dependency
Summary: This is first PR from the series I am going to be sending as a result of fixing 0.50-stable test suite. This one removes `mockFS` dependency that has been causing failures on Node 6.x container. Here's build before this change: https://circleci.com/gh/facebook/react-native/22529 Here's build after this change: https://circleci.com/gh/facebook/react-native/22538 (green) Note that the CI may be still red as there are other PRs to be addressed. You can see this in the wild on 0.50. Closes https://github.com/facebook/react-native/pull/16301 Differential Revision: D6031352 Pulled By: hramos fbshipit-source-id: 5c97ae6c87864c094e29e5d8987521071c67f5bd
This commit is contained in:
parent
0ec04ed8ef
commit
1f498010e8
@ -94,6 +94,9 @@ fs.readFileSync.mockImplementation(function(filepath, encoding) {
|
||||
if (isDirNode(node)) {
|
||||
throw new Error('Error readFileSync a dir: ' + filepath);
|
||||
}
|
||||
if (Buffer.isBuffer(node) && typeof encoding !== 'undefined') {
|
||||
return node.toString();
|
||||
}
|
||||
return node;
|
||||
});
|
||||
|
||||
@ -133,7 +136,12 @@ function fsError(code, message) {
|
||||
}
|
||||
|
||||
function isDirNode(node) {
|
||||
return node && typeof node === 'object' && node.SYMLINK == null;
|
||||
return (
|
||||
node &&
|
||||
typeof node === 'object' &&
|
||||
node.SYMLINK == null &&
|
||||
Buffer.isBuffer(node) === false
|
||||
);
|
||||
}
|
||||
|
||||
function readlinkSync(filepath) {
|
@ -1,4 +1,4 @@
|
||||
const fs = require('fs');
|
||||
const fs = require.requireActual('fs');
|
||||
const path = require('path');
|
||||
|
||||
const manifest = fs.readFileSync(path.join(__dirname, './files/AndroidManifest.xml'));
|
||||
|
@ -1,4 +1,4 @@
|
||||
const fs = require('fs');
|
||||
const fs = require.requireActual('fs');
|
||||
const path = require('path');
|
||||
const android = require('./android');
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
const fs = require('fs');
|
||||
const fs = require.requireActual('fs');
|
||||
const path = require('path');
|
||||
|
||||
exports.valid = {
|
||||
|
@ -1,5 +1,3 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const android = require('./android');
|
||||
const ios = require('./ios');
|
||||
|
||||
|
@ -11,13 +11,15 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
const fs = require('fs');
|
||||
const findAndroidAppFolder = require('../../android/findAndroidAppFolder');
|
||||
const mockFS = require('mock-fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
describe('android::findAndroidAppFolder', () => {
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
fs.__setMockFilesystem({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
@ -31,15 +33,11 @@ describe('android::findAndroidAppFolder', () => {
|
||||
});
|
||||
|
||||
it('returns an android app folder if it exists in the given folder', () => {
|
||||
expect(findAndroidAppFolder('flat')).toBe('android');
|
||||
expect(findAndroidAppFolder('nested')).toBe('android/app');
|
||||
expect(findAndroidAppFolder('/flat')).toBe('android');
|
||||
expect(findAndroidAppFolder('/nested')).toBe('android/app');
|
||||
});
|
||||
|
||||
it('returns `null` if there is no android app folder', () => {
|
||||
expect(findAndroidAppFolder('empty')).toBeNull();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
expect(findAndroidAppFolder('/empty')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
@ -11,13 +11,15 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
const findManifest = require('../../android/findManifest');
|
||||
const mockFS = require('mock-fs');
|
||||
const fs = require('fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
describe('android::findManifest', () => {
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
fs.__setMockFilesystem({
|
||||
empty: {},
|
||||
flat: {
|
||||
android: mocks.valid,
|
||||
@ -26,14 +28,10 @@ describe('android::findManifest', () => {
|
||||
});
|
||||
|
||||
it('returns a manifest path if file exists in the folder', () => {
|
||||
expect(typeof findManifest('flat')).toBe('string');
|
||||
expect(typeof findManifest('/flat')).toBe('string');
|
||||
});
|
||||
|
||||
it('returns `null` if there is no manifest in the folder', () => {
|
||||
expect(findManifest('empty')).toBeNull();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
expect(findManifest('/empty')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
@ -11,13 +11,15 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
const findPackageClassName = require('../../android/findPackageClassName');
|
||||
const mockFS = require('mock-fs');
|
||||
const fs = require('fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
describe('android::findPackageClassName', () => {
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
fs.__setMockFilesystem({
|
||||
empty: {},
|
||||
flatJava: {
|
||||
android: mocks.valid,
|
||||
@ -29,22 +31,20 @@ describe('android::findPackageClassName', () => {
|
||||
});
|
||||
|
||||
it('returns manifest content if file exists in the folder', () => {
|
||||
expect(typeof findPackageClassName('flatJava')).toBe('string');
|
||||
expect(typeof findPackageClassName('/flatJava')).toBe('string');
|
||||
});
|
||||
|
||||
it('returns the name of the java class implementing ReactPackage', () => {
|
||||
expect(findPackageClassName('flatJava')).toBe('SomeExampleJavaPackage');
|
||||
expect(findPackageClassName('/flatJava')).toBe('SomeExampleJavaPackage');
|
||||
});
|
||||
|
||||
it('returns the name of the kotlin class implementing ReactPackage', () => {
|
||||
expect(findPackageClassName('flatKotlin')).toBe('SomeExampleKotlinPackage');
|
||||
expect(findPackageClassName('/flatKotlin')).toBe(
|
||||
'SomeExampleKotlinPackage',
|
||||
);
|
||||
});
|
||||
|
||||
it('returns `null` if there are no matches', () => {
|
||||
expect(findPackageClassName('empty')).toBeNull();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
expect(findPackageClassName('/empty')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
@ -11,15 +11,17 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
const getDependencyConfig = require('../../android').dependencyConfig;
|
||||
const mockFS = require('mock-fs');
|
||||
const fs = require('fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
const userConfig = {};
|
||||
|
||||
describe('android::getDependencyConfig', () => {
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
fs.__setMockFilesystem({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
@ -38,27 +40,23 @@ describe('android::getDependencyConfig', () => {
|
||||
});
|
||||
|
||||
it('returns an object with android project configuration', () => {
|
||||
expect(getDependencyConfig('nested', userConfig)).not.toBeNull();
|
||||
expect(typeof getDependencyConfig('nested', userConfig)).toBe('object');
|
||||
expect(getDependencyConfig('/nested', userConfig)).not.toBeNull();
|
||||
expect(typeof getDependencyConfig('/nested', userConfig)).toBe('object');
|
||||
});
|
||||
|
||||
it('returns `null` if manifest file has not been found', () => {
|
||||
expect(getDependencyConfig('empty', userConfig)).toBeNull();
|
||||
expect(getDependencyConfig('/empty', userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns `null` if android project was not found', () => {
|
||||
expect(getDependencyConfig('empty', userConfig)).toBeNull();
|
||||
expect(getDependencyConfig('/empty', userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns `null` if android project does not contain ReactPackage', () => {
|
||||
expect(getDependencyConfig('noPackage', userConfig)).toBeNull();
|
||||
expect(getDependencyConfig('/noPackage', userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns `null` if it cannot find a packageClassName', () => {
|
||||
expect(getDependencyConfig('corrupted', userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
expect(getDependencyConfig('/corrupted', userConfig)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
@ -11,13 +11,15 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
const getProjectConfig = require('../../android').projectConfig;
|
||||
const mockFS = require('mock-fs');
|
||||
const fs = require('fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
describe('android::getProjectConfig', () => {
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
fs.__setMockFilesystem({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
@ -38,7 +40,7 @@ describe('android::getProjectConfig', () => {
|
||||
|
||||
it("returns `null` if manifest file hasn't been found", () => {
|
||||
const userConfig = {};
|
||||
const folder = 'noManifest';
|
||||
const folder = '/noManifest';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).toBeNull();
|
||||
});
|
||||
@ -46,7 +48,7 @@ describe('android::getProjectConfig', () => {
|
||||
describe('returns an object with android project configuration for', () => {
|
||||
it('nested structure', () => {
|
||||
const userConfig = {};
|
||||
const folder = 'nested';
|
||||
const folder = '/nested';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBeNull();
|
||||
expect(typeof getProjectConfig(folder, userConfig)).toBe('object');
|
||||
@ -54,7 +56,7 @@ describe('android::getProjectConfig', () => {
|
||||
|
||||
it('flat structure', () => {
|
||||
const userConfig = {};
|
||||
const folder = 'flat';
|
||||
const folder = '/flat';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBeNull();
|
||||
expect(typeof getProjectConfig(folder, userConfig)).toBe('object');
|
||||
@ -64,7 +66,7 @@ describe('android::getProjectConfig', () => {
|
||||
const userConfig = {
|
||||
manifestPath: 'src/main/AndroidManifest.xml',
|
||||
};
|
||||
const folder = 'multiple';
|
||||
const folder = '/multiple';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBeNull();
|
||||
expect(typeof getProjectConfig(folder, userConfig)).toBe('object');
|
||||
@ -73,12 +75,8 @@ describe('android::getProjectConfig', () => {
|
||||
|
||||
it('should return `null` if android project was not found', () => {
|
||||
const userConfig = {};
|
||||
const folder = 'empty';
|
||||
const folder = '/empty';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
@ -11,14 +11,16 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
const findManifest = require('../../android/findManifest');
|
||||
const readManifest = require('../../android/readManifest');
|
||||
const mockFS = require('mock-fs');
|
||||
const fs = require('fs');
|
||||
const mocks = require('../../__fixtures__/android');
|
||||
|
||||
describe('android::readManifest', () => {
|
||||
beforeAll(() => {
|
||||
mockFS({
|
||||
fs.__setMockFilesystem({
|
||||
empty: {},
|
||||
nested: {
|
||||
android: {
|
||||
@ -29,19 +31,15 @@ describe('android::readManifest', () => {
|
||||
});
|
||||
|
||||
it('returns manifest content if file exists in the folder', () => {
|
||||
const manifestPath = findManifest('nested');
|
||||
const manifestPath = findManifest('/nested');
|
||||
expect(readManifest(manifestPath)).not.toBeNull();
|
||||
expect(typeof readManifest(manifestPath)).toBe('object');
|
||||
});
|
||||
|
||||
it('throws an error if there is no manifest in the folder', () => {
|
||||
const fakeManifestPath = findManifest('empty');
|
||||
const fakeManifestPath = findManifest('/empty');
|
||||
expect(() => {
|
||||
readManifest(fakeManifestPath);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
@ -11,24 +11,26 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
const findAssets = require('../findAssets');
|
||||
const dependencies = require('../__fixtures__/dependencies');
|
||||
const mockFs = require('mock-fs');
|
||||
const fs = require('fs');
|
||||
|
||||
describe('findAssets', () => {
|
||||
beforeEach(() => {
|
||||
mockFs({testDir: dependencies.withAssets});
|
||||
fs.__setMockFilesystem({testDir: dependencies.withAssets});
|
||||
});
|
||||
|
||||
it('returns an array of all files in given folders', () => {
|
||||
const assets = findAssets('testDir', ['fonts', 'images']);
|
||||
const assets = findAssets('/testDir', ['fonts', 'images']);
|
||||
|
||||
expect(Array.isArray(assets)).toBeTruthy();
|
||||
expect(assets).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('prepends assets paths with the folder path', () => {
|
||||
const assets = findAssets('testDir', ['fonts', 'images']);
|
||||
const assets = findAssets('/testDir', ['fonts', 'images']);
|
||||
|
||||
assets.forEach(assetPath => {
|
||||
expect(assetPath).toContain('testDir');
|
||||
@ -36,10 +38,6 @@ describe('findAssets', () => {
|
||||
});
|
||||
|
||||
it('returns an empty array if given assets are null', () => {
|
||||
expect(findAssets('testDir', null)).toHaveLength(0);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
expect(findAssets('/testDir', null)).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
@ -11,49 +11,51 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
const findProject = require('../../ios/findProject');
|
||||
const mockFS = require('mock-fs');
|
||||
const fs = require('fs');
|
||||
const projects = require('../../__fixtures__/projects');
|
||||
const ios = require('../../__fixtures__/ios');
|
||||
|
||||
describe('ios::findProject', () => {
|
||||
it('returns path to xcodeproj if found', () => {
|
||||
mockFS(projects.flat);
|
||||
expect(findProject('')).not.toBeNull();
|
||||
fs.__setMockFilesystem(projects.flat);
|
||||
expect(findProject('/')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('returns null if there are no projects', () => {
|
||||
mockFS({testDir: projects});
|
||||
expect(findProject('')).toBeNull();
|
||||
fs.__setMockFilesystem({testDir: projects});
|
||||
expect(findProject('/')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns ios project regardless of its name', () => {
|
||||
mockFS({ios: ios.validTestName});
|
||||
expect(findProject('')).not.toBeNull();
|
||||
fs.__setMockFilesystem({ios: ios.validTestName});
|
||||
expect(findProject('/')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('ignores node_modules', () => {
|
||||
mockFS({node_modules: projects.flat});
|
||||
expect(findProject('')).toBeNull();
|
||||
fs.__setMockFilesystem({node_modules: projects.flat});
|
||||
expect(findProject('/')).toBeNull();
|
||||
});
|
||||
|
||||
it('ignores Pods', () => {
|
||||
mockFS({Pods: projects.flat});
|
||||
expect(findProject('')).toBeNull();
|
||||
fs.__setMockFilesystem({Pods: projects.flat});
|
||||
expect(findProject('/')).toBeNull();
|
||||
});
|
||||
|
||||
it('ignores Pods inside `ios` folder', () => {
|
||||
mockFS({
|
||||
fs.__setMockFilesystem({
|
||||
ios: {
|
||||
Pods: projects.flat,
|
||||
DemoApp: projects.flat.ios,
|
||||
},
|
||||
});
|
||||
expect(findProject('')).toBe('ios/DemoApp/demoProject.xcodeproj');
|
||||
expect(findProject('/')).toBe('ios/DemoApp/demoProject.xcodeproj');
|
||||
});
|
||||
|
||||
it('ignores xcodeproj from example folders', () => {
|
||||
mockFS({
|
||||
fs.__setMockFilesystem({
|
||||
examples: projects.flat,
|
||||
Examples: projects.flat,
|
||||
example: projects.flat,
|
||||
@ -61,11 +63,11 @@ describe('ios::findProject', () => {
|
||||
Zpp: projects.flat,
|
||||
});
|
||||
|
||||
expect(findProject('').toLowerCase()).not.toContain('example');
|
||||
expect(findProject('/').toLowerCase()).not.toContain('example');
|
||||
});
|
||||
|
||||
it('ignores xcodeproj from sample folders', () => {
|
||||
mockFS({
|
||||
fs.__setMockFilesystem({
|
||||
samples: projects.flat,
|
||||
Samples: projects.flat,
|
||||
sample: projects.flat,
|
||||
@ -73,11 +75,11 @@ describe('ios::findProject', () => {
|
||||
Zpp: projects.flat,
|
||||
});
|
||||
|
||||
expect(findProject('').toLowerCase()).not.toContain('sample');
|
||||
expect(findProject('/').toLowerCase()).not.toContain('sample');
|
||||
});
|
||||
|
||||
it('ignores xcodeproj from test folders at any level', () => {
|
||||
mockFS({
|
||||
fs.__setMockFilesystem({
|
||||
test: projects.flat,
|
||||
IntegrationTests: projects.flat,
|
||||
tests: projects.flat,
|
||||
@ -87,10 +89,6 @@ describe('ios::findProject', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(findProject('').toLowerCase()).not.toContain('test');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFS.restore();
|
||||
expect(findProject('/').toLowerCase()).not.toContain('test');
|
||||
});
|
||||
});
|
||||
|
@ -11,32 +11,34 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
const getProjectConfig = require('../../ios').projectConfig;
|
||||
const mockFS = require('mock-fs');
|
||||
const fs = require('fs');
|
||||
const projects = require('../../__fixtures__/projects');
|
||||
|
||||
describe('ios::getProjectConfig', () => {
|
||||
const userConfig = {};
|
||||
|
||||
beforeEach(() => {
|
||||
mockFS({testDir: projects});
|
||||
fs.__setMockFilesystem({testDir: projects});
|
||||
});
|
||||
|
||||
it('returns an object with ios project configuration', () => {
|
||||
const folder = 'testDir/nested';
|
||||
const folder = '/testDir/nested';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).not.toBeNull();
|
||||
expect(typeof getProjectConfig(folder, userConfig)).toBe('object');
|
||||
});
|
||||
|
||||
it('returns `null` if ios project was not found', () => {
|
||||
const folder = 'testDir/empty';
|
||||
const folder = '/testDir/empty';
|
||||
|
||||
expect(getProjectConfig(folder, userConfig)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns normalized shared library names', () => {
|
||||
const projectConfig = getProjectConfig('testDir/nested', {
|
||||
const projectConfig = getProjectConfig('/testDir/nested', {
|
||||
sharedLibraries: ['libc++', 'libz.tbd', 'HealthKit', 'HomeKit.framework'],
|
||||
});
|
||||
|
||||
@ -47,8 +49,4 @@ describe('ios::getProjectConfig', () => {
|
||||
'HomeKit.framework',
|
||||
]);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFS.restore();
|
||||
});
|
||||
});
|
||||
|
@ -200,7 +200,6 @@
|
||||
"eslint-plugin-react": "^7.2.1",
|
||||
"flow-bin": "^0.56.0",
|
||||
"jest": "^21",
|
||||
"mock-fs": "^4.4.1",
|
||||
"prettier": "1.7.0",
|
||||
"react": "16.0.0",
|
||||
"react-test-renderer": "16.0.0",
|
||||
|
Loading…
x
Reference in New Issue
Block a user