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,12 +143,9 @@ function moduleThrewError(id, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
var createHotReloadingObject;
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
_require.Systrace = { beginEvent: function beginEvent() {}, endEvent: function endEvent() {} };
|
_require.Systrace = { beginEvent: function beginEvent() {}, endEvent: function endEvent() {} };
|
||||||
|
|
||||||
createHotReloadingObject = function createHotReloadingObject() {
|
var createHotReloadingObject = function createHotReloadingObject() {
|
||||||
var hot = {
|
var hot = {
|
||||||
acceptCallback: null,
|
acceptCallback: null,
|
||||||
accept: function accept(callback) {
|
accept: function accept(callback) {
|
||||||
|
@ -164,7 +161,7 @@ if (__DEV__) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = [];
|
||||||
|
@ -179,7 +176,7 @@ if (__DEV__) {
|
||||||
return acceptAll(parents, inverseDependencies);
|
return acceptAll(parents, inverseDependencies);
|
||||||
};
|
};
|
||||||
|
|
||||||
var accept = function accept(id, factory, inverseDependencies) {
|
var _accept = function _accept(id, factory, inverseDependencies) {
|
||||||
var mod = modules[id];
|
var mod = modules[id];
|
||||||
|
|
||||||
if (!mod && factory) {
|
if (!mod && factory) {
|
||||||
|
@ -213,8 +210,7 @@ if (__DEV__) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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,7 +744,6 @@ 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,
|
||||||
|
@ -758,7 +753,6 @@ if (!Number.isNaN) {
|
||||||
},
|
},
|
||||||
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