Permalink
Browse files

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
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed Jun 1, 2017
1 parent 2a3de8f commit a33dd76e4fc8bda804fe420fb36f92598c6d5aa1
View
@@ -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",
@@ -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();
});
});
@@ -143,78 +143,74 @@ function moduleThrewError(id, error) {
}
if (__DEV__) {
var createHotReloadingObject;
_require.Systrace = { beginEvent: function beginEvent() {}, endEvent: function endEvent() {} };
(function () {
_require.Systrace = { beginEvent: function beginEvent() {}, endEvent: function endEvent() {} };
createHotReloadingObject = function createHotReloadingObject() {
var hot = {
acceptCallback: null,
accept: function accept(callback) {
hot.acceptCallback = callback;
}
};
return hot;
};
var acceptAll = function acceptAll(dependentModules, inverseDependencies) {
if (!dependentModules || dependentModules.length === 0) {
return true;
var createHotReloadingObject = function createHotReloadingObject() {
var hot = {
acceptCallback: null,
accept: function accept(callback) {
hot.acceptCallback = callback;
}
};
return hot;
};
var notAccepted = dependentModules.filter(function (module) {
return !accept(module, undefined, inverseDependencies);
});
var acceptAll = function acceptAll(dependentModules, inverseDependencies) {
if (!dependentModules || dependentModules.length === 0) {
return true;
}
var parents = [];
for (var i = 0; i < notAccepted.length; i++) {
if (inverseDependencies[notAccepted[i]].length === 0) {
return false;
}
var notAccepted = dependentModules.filter(function (module) {
return !_accept(module, undefined, inverseDependencies);
});
parents.push.apply(parents, babelHelpers.toConsumableArray(inverseDependencies[notAccepted[i]]));
var parents = [];
for (var i = 0; i < notAccepted.length; i++) {
if (inverseDependencies[notAccepted[i]].length === 0) {
return false;
}
return acceptAll(parents, inverseDependencies);
};
parents.push.apply(parents, babelHelpers.toConsumableArray(inverseDependencies[notAccepted[i]]));
}
var accept = function accept(id, factory, inverseDependencies) {
var mod = modules[id];
return acceptAll(parents, inverseDependencies);
};
if (!mod && factory) {
define(factory, id);
return true;
}
var _accept = function _accept(id, factory, inverseDependencies) {
var mod = modules[id];
var hot = mod.hot;
if (!mod && factory) {
define(factory, id);
return true;
}
if (!hot) {
console.warn('Cannot accept module because Hot Module Replacement ' + 'API was not installed.');
return false;
}
var hot = mod.hot;
if (factory) {
mod.factory = factory;
}
mod.hasError = false;
mod.isInitialized = false;
_require(id);
if (!hot) {
console.warn('Cannot accept module because Hot Module Replacement ' + 'API was not installed.');
return false;
}
if (hot.acceptCallback) {
hot.acceptCallback();
return true;
} else {
if (!inverseDependencies) {
throw new Error('Undefined \`inverseDependencies\`');
}
if (factory) {
mod.factory = factory;
}
mod.hasError = false;
mod.isInitialized = false;
_require(id);
return acceptAll(inverseDependencies[id], inverseDependencies);
if (hot.acceptCallback) {
hot.acceptCallback();
return true;
} else {
if (!inverseDependencies) {
throw new Error('Undefined \`inverseDependencies\`');
}
};
global.__accept = accept;
})();
return acceptAll(inverseDependencies[id], inverseDependencies);
}
};
global.__accept = _accept;
}
})(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);
(function(global) {
@@ -748,17 +744,15 @@ if (Number.MIN_SAFE_INTEGER === undefined) {
});
}
if (!Number.isNaN) {
(function () {
var globalIsNaN = global.isNaN;
Object.defineProperty(Number, 'isNaN', {
configurable: true,
enumerable: false,
value: function isNaN(value) {
return typeof value === 'number' && globalIsNaN(value);
},
writable: true
});
})();
var globalIsNaN = global.isNaN;
Object.defineProperty(Number, 'isNaN', {
configurable: true,
enumerable: false,
value: function isNaN(value) {
return typeof value === 'number' && globalIsNaN(value);
},
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) {
__d(/* /Foo.js */function(global, require, module, exports) {
'use strict';
var Foo = require(13 ); // 13 = ./Foo
module.exports = { type: 'bar', foo: Foo.type };
module.exports = { type: 'foo', asset: require(13 ) }; // 13 = ./test.png
}, 12);
__d(/* /Foo.js */function(global, require, module, exports) {
__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(/* /node_modules/react-native/Libraries/Image/AssetRegistry.js */function(global, require, module, exports) {
'use strict';
var asset = require(14 ); // 14 = ./test.png
module.exports = { type: 'foo', asset: asset };
}, 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
module.export = {};
}, 14);
__d(/* /node_modules/react-native/Libraries/Image/AssetRegistry.js */function(global, require, module, exports) {
__d(/* /Bar.js */function(global, require, module, exports) {
'use strict';
module.export = {};
module.exports = { type: 'bar', foo: require(12 ).type }; // 12 = ./Foo
}, 15);
;require(0);"
`;
@@ -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();
});
});

0 comments on commit a33dd76

Please sign in to comment.