Skip to content

Commit

Permalink
facebook#1331 Add information about ReactNative to runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
ptmt committed Jul 28, 2015
1 parent 757d6d2 commit 82c4dba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ function setUpGeolocation() {
GLOBAL.navigator.geolocation = require('Geolocation');
}

function setUpProduct() {
GLOBAL.navigator.product = 'ReactNative';
GLOBAL.navigator.productSub = GLOBAL.navigator.rnVersion = RN_VERSION;
}

function setUpWebSockets() {
GLOBAL.WebSocket = require('WebSocket');
}
Expand All @@ -135,5 +140,6 @@ setUpPromise();
setUpXHR();
setUpRedBoxConsoleErrorHandler();
setUpGeolocation();
setUpProduct();
setUpWebSockets();
setupProfile();
11 changes: 6 additions & 5 deletions packager/react-packager/src/Server/__tests__/Server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('processRequest', function() {
var watcherFunc = jest.genMockFunction();
var requestHandler;
var triggerFileChange;
var rnVersion = "var RN_VERSION = '" + require('../../../../../package.json').version + "';";

beforeEach(function() {
Packager = require('../../Packager');
Expand Down Expand Up @@ -93,7 +94,7 @@ describe('processRequest', function() {
requestHandler,
'mybundle.bundle?runModule=true'
).then(function(response) {
expect(response).toEqual('this is the source');
expect(response).toEqual(rnVersion + 'this is the source');
});
});

Expand All @@ -102,7 +103,7 @@ describe('processRequest', function() {
requestHandler,
'mybundle.runModule.bundle'
).then(function(response) {
expect(response).toEqual('this is the source');
expect(response).toEqual(rnVersion + 'this is the source');
});
});

Expand All @@ -120,7 +121,7 @@ describe('processRequest', function() {
requestHandler,
'index.ios.includeRequire.bundle'
).then(function(response) {
expect(response).toEqual('this is the source');
expect(response).toEqual(rnVersion + 'this is the source');
expect(Packager.prototype.package).toBeCalledWith(
'index.ios.js',
true,
Expand Down Expand Up @@ -183,7 +184,7 @@ describe('processRequest', function() {

return makeRequest(requestHandler, 'mybundle.bundle?runModule=true')
.then(function(response) {
expect(response).toEqual('this is the first source');
expect(response).toEqual(rnVersion + 'this is the first source');
expect(packageFunc.mock.calls.length).toBe(1);
triggerFileChange('all','path/file.js', options.projectRoots[0]);
jest.runAllTimers();
Expand All @@ -193,7 +194,7 @@ describe('processRequest', function() {
expect(packageFunc.mock.calls.length).toBe(2);
return makeRequest(requestHandler, 'mybundle.bundle?runModule=true')
.then(function(response) {
expect(response).toEqual('this is the rebuilt source');
expect(response).toEqual(rnVersion + 'this is the rebuilt source');
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion packager/react-packager/src/Server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ Server.prototype.processRequest = function(req, res, next) {
building.then(
function(p) {
if (requestType === 'bundle') {
var bundleSource = p.getSource({
var rnGlobalVersion = "var RN_VERSION = '" + require('../../../../package.json').version + "';";
var bundleSource = rnGlobalVersion + p.getSource({
inlineSourceMap: options.inlineSourceMap,
minify: options.minify,
});
Expand Down

0 comments on commit 82c4dba

Please sign in to comment.