-
-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed order of normalize and transform in load sprites
- Loading branch information
Showing
5 changed files
with
55 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,9 +66,39 @@ describe('loadSprite', () => { | |
|
||
const result = await promise; | ||
|
||
expect(transform).toHaveBeenCalledTimes(2); | ||
expect(transform).toHaveBeenNthCalledWith(1, 'http://localhost:9966/test/unit/assets/sprite1.json', 'SpriteJSON'); | ||
expect(transform).toHaveBeenNthCalledWith(2, 'http://localhost:9966/test/unit/assets/sprite1.png', 'SpriteImage'); | ||
expect(transform).toHaveBeenCalledTimes(1); | ||
expect(transform).toHaveBeenNthCalledWith(1, 'http://localhost:9966/test/unit/assets/sprite1', 'Sprite'); | ||
|
||
expect(Object.keys(result)).toHaveLength(1); | ||
expect(Object.keys(result)[0]).toBe('default'); | ||
|
||
Object.values(result['default']).forEach(styleImage => { | ||
expect(styleImage.spriteData).toBeTruthy(); | ||
expect(styleImage.spriteData.context).toBeInstanceOf(CanvasRenderingContext2D); | ||
}); | ||
|
||
expect(server.requests[0].url).toBe('http://localhost:9966/test/unit/assets/sprite1.json'); | ||
expect(server.requests[1].url).toBe('http://localhost:9966/test/unit/assets/sprite1.png'); | ||
}); | ||
|
||
test('transform of invalid url', async () => { | ||
const transform = jest.fn().mockImplementation((url, type) => { | ||
return {url: `http://localhost:9966${url}`, type}; | ||
}); | ||
|
||
const manager = new RequestManager(transform); | ||
|
||
server.respondWith('GET', 'http://localhost:9966/test/unit/assets/sprite1.json', fs.readFileSync(path.join(__dirname, '../../test/unit/assets/sprite1.json')).toString()); | ||
server.respondWith('GET', 'http://localhost:9966/test/unit/assets/sprite1.png', bufferToArrayBuffer(fs.readFileSync(path.join(__dirname, '../../test/unit/assets/sprite1.png')))); | ||
|
||
const promise = loadSprite('/test/unit/assets/sprite1', manager, 1, new AbortController()); | ||
|
||
server.respond(); | ||
|
||
const result = await promise; | ||
|
||
expect(transform).toHaveBeenCalledTimes(1); | ||
expect(transform).toHaveBeenNthCalledWith(1, '/test/unit/assets/sprite1', 'Sprite'); | ||
|
||
expect(Object.keys(result)).toHaveLength(1); | ||
expect(Object.keys(result)[0]).toBe('default'); | ||
|
@@ -98,9 +128,8 @@ describe('loadSprite', () => { | |
|
||
const result = await promise; | ||
|
||
expect(transform).toHaveBeenCalledTimes(2); | ||
expect(transform).toHaveBeenNthCalledWith(1, '/test/unit/assets/sprite1.json', 'SpriteJSON'); | ||
expect(transform).toHaveBeenNthCalledWith(2, '/test/unit/assets/sprite1.png', 'SpriteImage'); | ||
expect(transform).toHaveBeenCalledTimes(1); | ||
expect(transform).toHaveBeenNthCalledWith(1, '/test/unit/assets/sprite1', 'Sprite'); | ||
|
||
expect(Object.keys(result)).toHaveLength(1); | ||
expect(Object.keys(result)[0]).toBe('default'); | ||
|
@@ -131,11 +160,9 @@ describe('loadSprite', () => { | |
server.respond(); | ||
|
||
const result = await promise; | ||
expect(transform).toHaveBeenCalledTimes(4); | ||
expect(transform).toHaveBeenNthCalledWith(1, 'http://localhost:9966/test/unit/assets/sprite1.json', 'SpriteJSON'); | ||
expect(transform).toHaveBeenNthCalledWith(2, 'http://localhost:9966/test/unit/assets/sprite1.png', 'SpriteImage'); | ||
expect(transform).toHaveBeenNthCalledWith(3, 'http://localhost:9966/test/unit/assets/sprite2.json', 'SpriteJSON'); | ||
expect(transform).toHaveBeenNthCalledWith(4, 'http://localhost:9966/test/unit/assets/sprite2.png', 'SpriteImage'); | ||
expect(transform).toHaveBeenCalledTimes(2); | ||
expect(transform).toHaveBeenNthCalledWith(1, 'http://localhost:9966/test/unit/assets/sprite1', 'Sprite'); | ||
expect(transform).toHaveBeenNthCalledWith(2, 'http://localhost:9966/test/unit/assets/sprite2', 'Sprite'); | ||
|
||
expect(Object.keys(result)).toHaveLength(2); | ||
expect(Object.keys(result)[0]).toBe('sprite1'); | ||
|
@@ -209,9 +236,8 @@ describe('loadSprite', () => { | |
server.respond(); | ||
|
||
const result = await promise; | ||
expect(transform).toHaveBeenCalledTimes(2); | ||
expect(transform).toHaveBeenNthCalledWith(1, 'http://localhost:9966/test/unit/assets/[email protected]', 'SpriteJSON'); | ||
expect(transform).toHaveBeenNthCalledWith(2, 'http://localhost:9966/test/unit/assets/[email protected]', 'SpriteImage'); | ||
expect(transform).toHaveBeenCalledTimes(1); | ||
expect(transform).toHaveBeenNthCalledWith(1, 'http://localhost:9966/test/unit/assets/sprite1', 'Sprite'); | ||
|
||
expect(Object.keys(result)).toHaveLength(1); | ||
expect(Object.keys(result)[0]).toBe('default'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters