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:
parent
2a3de8f192
commit
a33dd76e4f
|
@ -28,7 +28,7 @@
|
||||||
"/node_modules/",
|
"/node_modules/",
|
||||||
"/website/",
|
"/website/",
|
||||||
"local-cli/templates/",
|
"local-cli/templates/",
|
||||||
"packager/integration_tests/__tests__/basic_bundle-test.js"
|
"packager/src/integration_tests/__tests__/basic_bundle-test.js"
|
||||||
],
|
],
|
||||||
"haste": {
|
"haste": {
|
||||||
"defaultPlatform": "ios",
|
"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__) {
|
if (__DEV__) {
|
||||||
var createHotReloadingObject;
|
_require.Systrace = { beginEvent: function beginEvent() {}, endEvent: function endEvent() {} };
|
||||||
|
|
||||||
(function () {
|
var createHotReloadingObject = function createHotReloadingObject() {
|
||||||
_require.Systrace = { beginEvent: function beginEvent() {}, endEvent: function endEvent() {} };
|
var hot = {
|
||||||
|
acceptCallback: null,
|
||||||
createHotReloadingObject = function createHotReloadingObject() {
|
accept: function accept(callback) {
|
||||||
var hot = {
|
hot.acceptCallback = callback;
|
||||||
acceptCallback: null,
|
}
|
||||||
accept: function accept(callback) {
|
|
||||||
hot.acceptCallback = callback;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return hot;
|
|
||||||
};
|
};
|
||||||
|
return hot;
|
||||||
|
};
|
||||||
|
|
||||||
var acceptAll = function acceptAll(dependentModules, inverseDependencies) {
|
var acceptAll = function acceptAll(dependentModules, inverseDependencies) {
|
||||||
if (!dependentModules || dependentModules.length === 0) {
|
if (!dependentModules || dependentModules.length === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var notAccepted = dependentModules.filter(function (module) {
|
var notAccepted = dependentModules.filter(function (module) {
|
||||||
return !accept(module, undefined, inverseDependencies);
|
return !_accept(module, undefined, inverseDependencies);
|
||||||
});
|
});
|
||||||
|
|
||||||
var parents = [];
|
var parents = [];
|
||||||
for (var i = 0; i < notAccepted.length; i++) {
|
for (var i = 0; i < notAccepted.length; i++) {
|
||||||
if (inverseDependencies[notAccepted[i]].length === 0) {
|
if (inverseDependencies[notAccepted[i]].length === 0) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
parents.push.apply(parents, babelHelpers.toConsumableArray(inverseDependencies[notAccepted[i]]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return acceptAll(parents, inverseDependencies);
|
|
||||||
};
|
|
||||||
|
|
||||||
var accept = function accept(id, factory, inverseDependencies) {
|
|
||||||
var mod = modules[id];
|
|
||||||
|
|
||||||
if (!mod && factory) {
|
|
||||||
define(factory, id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var hot = mod.hot;
|
|
||||||
|
|
||||||
if (!hot) {
|
|
||||||
console.warn('Cannot accept module because Hot Module Replacement ' + 'API was not installed.');
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (factory) {
|
parents.push.apply(parents, babelHelpers.toConsumableArray(inverseDependencies[notAccepted[i]]));
|
||||||
mod.factory = factory;
|
}
|
||||||
|
|
||||||
|
return acceptAll(parents, inverseDependencies);
|
||||||
|
};
|
||||||
|
|
||||||
|
var _accept = function _accept(id, factory, inverseDependencies) {
|
||||||
|
var mod = modules[id];
|
||||||
|
|
||||||
|
if (!mod && factory) {
|
||||||
|
define(factory, id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hot = mod.hot;
|
||||||
|
|
||||||
|
if (!hot) {
|
||||||
|
console.warn('Cannot accept module because Hot Module Replacement ' + 'API was not installed.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (factory) {
|
||||||
|
mod.factory = factory;
|
||||||
|
}
|
||||||
|
mod.hasError = false;
|
||||||
|
mod.isInitialized = false;
|
||||||
|
_require(id);
|
||||||
|
|
||||||
|
if (hot.acceptCallback) {
|
||||||
|
hot.acceptCallback();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (!inverseDependencies) {
|
||||||
|
throw new Error('Undefined \`inverseDependencies\`');
|
||||||
}
|
}
|
||||||
mod.hasError = false;
|
|
||||||
mod.isInitialized = false;
|
|
||||||
_require(id);
|
|
||||||
|
|
||||||
if (hot.acceptCallback) {
|
return acceptAll(inverseDependencies[id], inverseDependencies);
|
||||||
hot.acceptCallback();
|
}
|
||||||
return true;
|
};
|
||||||
} else {
|
|
||||||
if (!inverseDependencies) {
|
|
||||||
throw new Error('Undefined \`inverseDependencies\`');
|
|
||||||
}
|
|
||||||
|
|
||||||
return acceptAll(inverseDependencies[id], inverseDependencies);
|
global.__accept = _accept;
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
global.__accept = accept;
|
|
||||||
})();
|
|
||||||
}
|
}
|
||||||
})(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);
|
})(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);
|
||||||
(function(global) {
|
(function(global) {
|
||||||
|
@ -748,17 +744,15 @@ if (Number.MIN_SAFE_INTEGER === undefined) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!Number.isNaN) {
|
if (!Number.isNaN) {
|
||||||
(function () {
|
var globalIsNaN = global.isNaN;
|
||||||
var globalIsNaN = global.isNaN;
|
Object.defineProperty(Number, 'isNaN', {
|
||||||
Object.defineProperty(Number, 'isNaN', {
|
configurable: true,
|
||||||
configurable: true,
|
enumerable: false,
|
||||||
enumerable: false,
|
value: function isNaN(value) {
|
||||||
value: function isNaN(value) {
|
return typeof value === 'number' && globalIsNaN(value);
|
||||||
return typeof value === 'number' && globalIsNaN(value);
|
},
|
||||||
},
|
writable: true
|
||||||
writable: true
|
});
|
||||||
});
|
|
||||||
})();
|
|
||||||
}
|
}
|
||||||
})(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);
|
})(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);
|
||||||
(function(global) {
|
(function(global) {
|
||||||
|
@ -1255,34 +1249,27 @@ __d(/* /TestBundle.js */function(global, require, module, exports) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Bar = require(12 ); // 12 = ./Bar
|
module.exports = { Foo: require(12 ), Bar: require(15 ) }; // 15 = ./Bar // 12 = ./Foo
|
||||||
var Foo = require(13 ); // 13 = ./Foo
|
|
||||||
|
|
||||||
module.exports = { Foo: Foo, Bar: Bar };
|
|
||||||
}, 0);
|
}, 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) {
|
__d(/* /Foo.js */function(global, require, module, exports) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var asset = require(14 ); // 14 = ./test.png
|
module.exports = { type: 'foo', asset: require(13 ) }; // 13 = ./test.png
|
||||||
|
}, 12);
|
||||||
module.exports = { type: 'foo', asset: asset };
|
__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);
|
}, 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) {
|
__d(/* /node_modules/react-native/Libraries/Image/AssetRegistry.js */function(global, require, module, exports) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.export = {};
|
module.export = {};
|
||||||
|
}, 14);
|
||||||
|
__d(/* /Bar.js */function(global, require, module, exports) {
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = { type: 'bar', foo: require(12 ).type }; // 12 = ./Foo
|
||||||
}, 15);
|
}, 15);
|
||||||
;require(0);"
|
;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();
|
||||||
|
});
|
||||||
|
});
|
Before Width: | Height: | Size: 68 B After Width: | Height: | Size: 68 B |
Loading…
Reference in New Issue