mirror of
https://github.com/status-im/metro.git
synced 2025-02-17 21:46:24 +00:00
metro-bundler/src/ModuleGraph: test image asset transform
Reviewed By: davidaurelio Differential Revision: D6039836 fbshipit-source-id: 0fc022b72892f8a7064482f63e19b9fa5a3d5b00
This commit is contained in:
parent
0608332cb9
commit
55a22d2c5c
@ -1,3 +1,39 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`transforming JS modules: assets extract image sizes, platform, scale 1`] = `
|
||||
Object {
|
||||
"details": Object {
|
||||
"assetPath": "foo.png",
|
||||
"contentBase64": "eyJfX3NpemUiOnsid2lkdGgiOjMwLCJoZWlnaHQiOjIwfX0=",
|
||||
"contentType": "png",
|
||||
"filePath": "foo.png",
|
||||
"physicalSize": Object {
|
||||
"height": 20,
|
||||
"width": 30,
|
||||
},
|
||||
"platform": null,
|
||||
"scale": 1,
|
||||
},
|
||||
"type": "asset",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`transforming JS modules: assets extract image sizes, platform, scale 2`] = `
|
||||
Object {
|
||||
"details": Object {
|
||||
"assetPath": "foo.png",
|
||||
"contentBase64": "eyJfX3NpemUiOnsid2lkdGgiOjMwLCJoZWlnaHQiOjIwfX0=",
|
||||
"contentType": "png",
|
||||
"filePath": "foo@2x.ios.png",
|
||||
"physicalSize": Object {
|
||||
"height": 20,
|
||||
"width": 30,
|
||||
},
|
||||
"platform": "ios",
|
||||
"scale": 2,
|
||||
},
|
||||
"type": "asset",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`transforming JS modules: assets throws on empty images 1`] = `"Image asset \`foo.png\` cannot be an empty file."`;
|
||||
|
@ -21,6 +21,10 @@ const {parse} = require('babylon');
|
||||
const generate = require('babel-generator').default;
|
||||
const {traverse} = require('babel-core');
|
||||
|
||||
jest.mock('image-size', () => buffer => {
|
||||
return JSON.parse(buffer.toString('utf8')).__size;
|
||||
});
|
||||
|
||||
describe('transforming JS modules:', () => {
|
||||
const filename = 'arbitrary';
|
||||
|
||||
@ -212,6 +216,18 @@ describe('transforming JS modules:', () => {
|
||||
});
|
||||
|
||||
describe('assets', () => {
|
||||
it('extract image sizes, platform, scale', () => {
|
||||
const image = {__size: {width: 30, height: 20}};
|
||||
['foo.png', 'foo@2x.ios.png'].forEach(filePath => {
|
||||
expect(
|
||||
transformModule(new Buffer(JSON.stringify(image), 'utf8'), {
|
||||
...options(),
|
||||
filename: filePath,
|
||||
}),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('throws on empty images', () => {
|
||||
expect(() =>
|
||||
transformModule(new Buffer(0), {...options(), filename: 'foo.png'}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user