Attach platform to asset url

Summary: Depends on D2420548

Reviewed By: @martinbigio

Differential Revision: D2421696
This commit is contained in:
Alex Kotliarskyi 2015-09-09 08:49:45 -07:00 committed by facebook-github-bot-8
parent c4305fe9af
commit ce47e56b7b
2 changed files with 6 additions and 23 deletions

View File

@ -25,6 +25,7 @@ function expectResolvesAsset(input, expectedSource) {
describe('resolveAssetSource', () => {
beforeEach(() => {
jest.resetModuleRegistry();
__DEV__ = true;
AssetRegistry = require('AssetRegistry');
Platform = require('Platform');
SourceCode = require('NativeModules').SourceCode;
@ -64,6 +65,7 @@ describe('resolveAssetSource', () => {
describe('bundle was loaded from network (DEV)', () => {
beforeEach(() => {
SourceCode.scriptURL = 'http://10.0.0.1:8081/main.bundle';
Platform.OS = 'ios';
});
it('uses network image', () => {
@ -81,7 +83,7 @@ describe('resolveAssetSource', () => {
isStatic: false,
width: 100,
height: 200,
uri: 'http://10.0.0.1:8081/assets/module/a/logo.png?hash=5b6f00f',
uri: 'http://10.0.0.1:8081/assets/module/a/logo.png?platform=ios&hash=5b6f00f',
});
});
@ -100,29 +102,19 @@ describe('resolveAssetSource', () => {
isStatic: false,
width: 100,
height: 200,
uri: 'http://10.0.0.1:8081/assets/module/a/logo@2x.png?hash=5b6f00f',
uri: 'http://10.0.0.1:8081/assets/module/a/logo@2x.png?platform=ios&hash=5b6f00f',
});
});
});
describe('bundle was loaded from file (PROD) on iOS', () => {
var originalDevMode;
var originalPlatform;
beforeEach(() => {
SourceCode.scriptURL = 'file:///Path/To/Simulator/main.bundle';
originalDevMode = __DEV__;
originalPlatform = Platform.OS;
__DEV__ = false;
Platform.OS = 'ios';
});
afterEach(() => {
__DEV__ = originalDevMode;
Platform.OS = originalPlatform;
});
it('uses pre-packed image', () => {
expectResolvesAsset({
__packager_asset: true,
@ -144,22 +136,12 @@ describe('resolveAssetSource', () => {
});
describe('bundle was loaded from file (PROD) on Android', () => {
var originalDevMode;
var originalPlatform;
beforeEach(() => {
SourceCode.scriptURL = 'file:///Path/To/Simulator/main.bundle';
originalDevMode = __DEV__;
originalPlatform = Platform.OS;
__DEV__ = false;
Platform.OS = 'android';
});
afterEach(() => {
__DEV__ = originalDevMode;
Platform.OS = originalPlatform;
});
it('uses pre-packed image', () => {
expectResolvesAsset({
__packager_asset: true,

View File

@ -63,7 +63,8 @@ function getPathInArchive(asset) {
* from the devserver
*/
function getPathOnDevserver(devServerUrl, asset) {
return devServerUrl + getScaledAssetPath(asset) + '?hash=' + asset.hash;
return devServerUrl + getScaledAssetPath(asset) + '?platform=' + Platform.OS +
'&hash=' + asset.hash;
}
/**