import * as fs from 'fs' ; import * as path from 'path' ; import * as png from 'fast-png' ; import { toMatchImageSnapshot } from 'jest-image-snapshot' ; import { parseModel } from '../modelDataParser' ; import { buildTexture } from '../textureBuilder' ; expect . extend ( { toMatchImageSnapshot } ) ; Object . defineProperty ( global , 'ImageData' , { value : class MockImageData { constructor ( public data , public width , public height ) { } } } ) ; const leetPath = path . resolve ( __dirname , '../../__mock__/leet.mdl' ) ; const leetBuffer = fs . readFileSync ( leetPath ) . buffer ; const leetModelData = parseModel ( leetBuffer ) ; describe ( 'test textures building' , ( ) => { test ( 'just building texture without errors' , ( ) => { const texture = leetModelData . textures [ 0 ] ; buildTexture ( leetBuffer , texture ) ; } ) ; test ( 'should build valid skin texture' , ( ) => { const texture = leetModelData . textures [ 0 ] ; const buildedSkin = png . encode ( { width : texture . width , height : texture . height , data : buildTexture ( leetBuffer , texture ) } ) ; expect ( Buffer . from ( buildedSkin ) ) . toMatchImageSnapshot ( ) ; } ) ; test ( 'should build valid backpack texture' , ( ) => { const texture = leetModelData . textures [ 2 ] ; const buildedSkin = png . encode ( { width : texture . width , height : texture . height , data : buildTexture ( leetBuffer , texture ) } ) ; expect ( Buffer . from ( buildedSkin ) ) . toMatchImageSnapshot ( ) ; } ) ; } ) ;