2015-04-21 17:48:54 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
jest.dontMock('../resolveAssetSource');
|
|
|
|
|
|
|
|
var resolveAssetSource;
|
|
|
|
var SourceCode;
|
|
|
|
|
2015-04-22 20:11:30 +00:00
|
|
|
function expectResolvesAsset(input, expectedSource) {
|
|
|
|
expect(resolveAssetSource(input)).toEqual(expectedSource);
|
|
|
|
}
|
|
|
|
|
2015-04-21 17:48:54 +00:00
|
|
|
describe('resolveAssetSource', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModuleRegistry();
|
|
|
|
SourceCode = require('NativeModules').SourceCode;
|
|
|
|
resolveAssetSource = require('../resolveAssetSource');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns same source for simple static and network images', () => {
|
|
|
|
var source1 = {uri: 'https://www.facebook.com/logo'};
|
|
|
|
expect(resolveAssetSource(source1)).toBe(source1);
|
|
|
|
|
|
|
|
var source2 = {isStatic: true, uri: 'logo'};
|
|
|
|
expect(resolveAssetSource(source2)).toBe(source2);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('bundle was loaded from network', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
SourceCode.scriptURL = 'http://10.0.0.1:8081/main.bundle';
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses network image', () => {
|
2015-04-22 20:11:30 +00:00
|
|
|
expectResolvesAsset({
|
|
|
|
__packager_asset: true,
|
|
|
|
fileSystemLocation: '/root/app/module/a',
|
|
|
|
httpServerLocation: '/assets/module/a',
|
|
|
|
width: 100,
|
|
|
|
height: 200,
|
|
|
|
scales: [1],
|
|
|
|
hash: '5b6f00f',
|
|
|
|
name: 'logo',
|
|
|
|
type: 'png',
|
|
|
|
}, {
|
2015-04-21 17:48:54 +00:00
|
|
|
isStatic: false,
|
2015-04-22 20:11:30 +00:00
|
|
|
width: 100,
|
|
|
|
height: 200,
|
|
|
|
uri: 'http://10.0.0.1:8081/assets/module/a/logo.png?hash=5b6f00f',
|
2015-04-21 17:48:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not change deprecated assets', () => {
|
2015-04-22 20:11:30 +00:00
|
|
|
expectResolvesAsset({
|
|
|
|
__packager_asset: true,
|
2015-04-21 17:48:54 +00:00
|
|
|
deprecated: true,
|
2015-04-22 20:11:30 +00:00
|
|
|
fileSystemLocation: '/root/app/module/a',
|
|
|
|
httpServerLocation: '/assets/module/a',
|
|
|
|
width: 100,
|
|
|
|
height: 200,
|
|
|
|
scales: [1],
|
|
|
|
hash: '5b6f00f',
|
|
|
|
name: 'logo',
|
|
|
|
type: 'png',
|
|
|
|
}, {
|
2015-04-21 17:48:54 +00:00
|
|
|
isStatic: true,
|
2015-04-22 20:11:30 +00:00
|
|
|
width: 100,
|
|
|
|
height: 200,
|
2015-04-21 17:48:54 +00:00
|
|
|
uri: 'logo',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('bundle was loaded from file', () => {
|
2015-04-22 20:11:30 +00:00
|
|
|
beforeEach(() => {
|
2015-04-21 17:48:54 +00:00
|
|
|
SourceCode.scriptURL = 'file:///Path/To/Simulator/main.bundle';
|
2015-04-22 20:11:30 +00:00
|
|
|
});
|
2015-04-21 17:48:54 +00:00
|
|
|
|
2015-04-22 20:11:30 +00:00
|
|
|
it('uses pre-packed image', () => {
|
|
|
|
expectResolvesAsset({
|
|
|
|
__packager_asset: true,
|
|
|
|
fileSystemLocation: '/root/app/module/a',
|
|
|
|
httpServerLocation: '/assets/module/a',
|
|
|
|
width: 100,
|
|
|
|
height: 200,
|
|
|
|
scales: [1],
|
|
|
|
hash: '5b6f00f',
|
|
|
|
name: 'logo',
|
|
|
|
type: 'png',
|
|
|
|
}, {
|
2015-04-21 17:48:54 +00:00
|
|
|
isStatic: true,
|
2015-04-22 20:11:30 +00:00
|
|
|
width: 100,
|
|
|
|
height: 200,
|
|
|
|
uri: 'assets/module/a/logo.png',
|
2015-04-21 17:48:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|