diff --git a/packages/assets/src/cache/Cache.ts b/packages/assets/src/cache/Cache.ts index f9e3ae1e4b..4f33a8318d 100644 --- a/packages/assets/src/cache/Cache.ts +++ b/packages/assets/src/cache/Cache.ts @@ -111,7 +111,9 @@ class CacheClass cacheKeys.forEach((key) => { - if (this._cache.has(key) && this._cache.get(key) !== value) + const val = cacheableAssets ? cacheableAssets[key] : value; + + if (this._cache.has(key) && this._cache.get(key) !== val) { if (process.env.DEBUG) { diff --git a/packages/assets/test/assets.tests.ts b/packages/assets/test/assets.tests.ts index 839007db68..ab998d6067 100644 --- a/packages/assets/test/assets.tests.ts +++ b/packages/assets/test/assets.tests.ts @@ -493,6 +493,44 @@ describe('Assets', () => spy.mockRestore(); }); + it('should not show a cache warning if the same spritesheet asset is loaded twice', async () => + { + jest.setTimeout(10000); + await Assets.init({ + basePath, + }); + + const spy = jest.spyOn(console, 'warn'); + + await Promise.all([ + Assets.load('spritesheet/spritesheet.json'), + Assets.load('spritesheet/spritesheet.json'), + ]); + + expect(spy).not.toHaveBeenCalled(); + + spy.mockRestore(); + }); + + it('should show a cache warning if asset is different', async () => + { + jest.setTimeout(10000); + await Assets.init({ + basePath, + }); + + const spy = jest.spyOn(console, 'warn'); + + await Promise.all([ + Assets.load({ alias: 'test', src: 'textures/bunny.png' }), + Assets.load({ alias: 'test', src: 'textures/bunny.1.png' }), + ]); + + expect(spy).toHaveBeenCalled(); + + spy.mockRestore(); + }); + it('should load font assets with space in URL', async () => { await Assets.init({