metro-bundler: fix integration test for OSS

Summary: This should fix the e2e test for OSS.

Reviewed By: cpojer

Differential Revision: D5164267

fbshipit-source-id: d858b4811f0eb80ca7363177f4f384b66af13994
This commit is contained in:
Jean Lauliac 2017-06-01 09:58:07 -07:00 committed by Facebook Github Bot
parent 2a3de8f192
commit a33dd76e4f
8 changed files with 166 additions and 133 deletions

View File

@ -28,7 +28,7 @@
"/node_modules/",
"/website/",
"local-cli/templates/",
"packager/integration_tests/__tests__/basic_bundle-test.js"
"packager/src/integration_tests/__tests__/basic_bundle-test.js"
],
"haste": {
"defaultPlatform": "ios",

View File

@ -1,43 +0,0 @@
/**
* Copyright (c) 2015-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.disableAutomock();
jest.useRealTimers();
const Packager = require('../..');
const path = require('path');
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30 * 1000;
const INPUT_PATH = path.resolve(__dirname, '../basic_bundle');
const POLYFILLS_PATH = path.resolve(__dirname, '../../src/Resolver/polyfills');
describe('basic_bundle', () => {
it('bundles package as expected', async () => {
const bundle = await Packager.buildBundle(
{
projectRoots: [INPUT_PATH, POLYFILLS_PATH],
transformCache: Packager.TransformCaching.none(),
transformModulePath: require.resolve('../../transformer'),
},
{
dev: false,
entryFile: path.join(INPUT_PATH, 'TestBundle.js'),
platform: 'ios',
},
);
const absPathRe = new RegExp(INPUT_PATH, 'g');
expect(bundle.getSource().replace(absPathRe, '')).toMatchSnapshot();
});
});

View File

@ -143,12 +143,9 @@ function moduleThrewError(id, error) {
}
if (__DEV__) {
var createHotReloadingObject;
(function () {
_require.Systrace = { beginEvent: function beginEvent() {}, endEvent: function endEvent() {} };
createHotReloadingObject = function createHotReloadingObject() {
var createHotReloadingObject = function createHotReloadingObject() {
var hot = {
acceptCallback: null,
accept: function accept(callback) {
@ -164,7 +161,7 @@ if (__DEV__) {
}
var notAccepted = dependentModules.filter(function (module) {
return !accept(module, undefined, inverseDependencies);
return !_accept(module, undefined, inverseDependencies);
});
var parents = [];
@ -179,7 +176,7 @@ if (__DEV__) {
return acceptAll(parents, inverseDependencies);
};
var accept = function accept(id, factory, inverseDependencies) {
var _accept = function _accept(id, factory, inverseDependencies) {
var mod = modules[id];
if (!mod && factory) {
@ -213,8 +210,7 @@ if (__DEV__) {
}
};
global.__accept = accept;
})();
global.__accept = _accept;
}
})(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);
(function(global) {
@ -748,7 +744,6 @@ if (Number.MIN_SAFE_INTEGER === undefined) {
});
}
if (!Number.isNaN) {
(function () {
var globalIsNaN = global.isNaN;
Object.defineProperty(Number, 'isNaN', {
configurable: true,
@ -758,7 +753,6 @@ if (!Number.isNaN) {
},
writable: true
});
})();
}
})(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);
(function(global) {
@ -1255,34 +1249,27 @@ __d(/* /TestBundle.js */function(global, require, module, exports) {
'use strict';
var Bar = require(12 ); // 12 = ./Bar
var Foo = require(13 ); // 13 = ./Foo
module.exports = { Foo: Foo, Bar: Bar };
module.exports = { Foo: require(12 ), Bar: require(15 ) }; // 15 = ./Bar // 12 = ./Foo
}, 0);
__d(/* /Bar.js */function(global, require, module, exports) {
'use strict';
var Foo = require(13 ); // 13 = ./Foo
module.exports = { type: 'bar', foo: Foo.type };
}, 12);
__d(/* /Foo.js */function(global, require, module, exports) {
'use strict';
var asset = require(14 ); // 14 = ./test.png
module.exports = { type: 'foo', asset: asset };
module.exports = { type: 'foo', asset: require(13 ) }; // 13 = ./test.png
}, 12);
__d(/* /test.png */function(global, require, module, exports) {module.exports=require(14 ).registerAsset({\\"__packager_asset\\":true,\\"httpServerLocation\\":\\"/assets\\",\\"width\\":8,\\"height\\":8,\\"scales\\":[1],\\"hash\\":\\"77d45c1f7fa73c0f6c444a830dc42f67\\",\\"name\\":\\"test\\",\\"type\\":\\"png\\"}); // 14 = react-native/Libraries/Image/AssetRegistry
}, 13);
__d(/* /test.png */function(global, require, module, exports) {module.exports=require(15 ).registerAsset({\\"__packager_asset\\":true,\\"httpServerLocation\\":\\"/assets\\",\\"width\\":8,\\"height\\":8,\\"scales\\":[1],\\"hash\\":\\"77d45c1f7fa73c0f6c444a830dc42f67\\",\\"name\\":\\"test\\",\\"type\\":\\"png\\"}); // 15 = react-native/Libraries/Image/AssetRegistry
}, 14);
__d(/* /node_modules/react-native/Libraries/Image/AssetRegistry.js */function(global, require, module, exports) {
'use strict';
module.export = {};
}, 14);
__d(/* /Bar.js */function(global, require, module, exports) {
'use strict';
module.exports = { type: 'bar', foo: require(12 ).type }; // 12 = ./Foo
}, 15);
;require(0);"
`;

View File

@ -0,0 +1,89 @@
/**
* Copyright (c) 2015-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.disableAutomock();
jest.useRealTimers();
jest.dontMock('fs');
jest.dontMock('graceful-fs');
/**
* Don't waste time creating a worker-farm from jest-haste-map, use the function
* directly instead.
*/
jest.mock('worker-farm', () => {
function workerFarm(opts, workerPath, methodNames) {
return require(workerPath);
}
workerFarm.end = () => {};
return workerFarm;
});
/**
* We replace the farm by a simple require, so that the worker sources are
* transformed and managed by jest.
*/
jest.mock('../../worker-farm', () => {
let ended = false;
function workerFarm(opts, workerPath, methodNames) {
const {Readable} = require('stream');
const methods = {};
const worker = require(workerPath);
methodNames.forEach(name => {
methods[name] = function() {
if (ended) {
throw new Error('worker farm was ended');
}
return worker[name].apply(null, arguments);
};
});
return {
stdout: new Readable({read() {}}),
stderr: new Readable({read() {}}),
methods,
};
}
workerFarm.end = () => {
ended = true;
};
return workerFarm;
});
const Packager = require('../..');
const path = require('path');
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30 * 1000;
const INPUT_PATH = path.resolve(__dirname, '../basic_bundle');
const POLYFILLS_PATH = path.resolve(__dirname, '../../Resolver/polyfills');
describe('basic_bundle', () => {
it('bundles package as expected', async () => {
const bundle = await Packager.buildBundle(
{
projectRoots: [INPUT_PATH, POLYFILLS_PATH],
transformCache: Packager.TransformCaching.none(),
transformModulePath: require.resolve('../../transformer'),
nonPersistent: true,
},
{
dev: false,
entryFile: path.join(INPUT_PATH, 'TestBundle.js'),
platform: 'ios',
},
);
const absPathRe = new RegExp(INPUT_PATH, 'g');
expect(bundle.getSource().replace(absPathRe, '')).toMatchSnapshot();
});
});

View File

Before

Width:  |  Height:  |  Size: 68 B

After

Width:  |  Height:  |  Size: 68 B