Skip to content

Commit

Permalink
Fix: incorrect cache warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Apr 9, 2024
1 parent 9104ebd commit b0421fb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/assets/src/cache/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
38 changes: 38 additions & 0 deletions packages/assets/test/assets.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit b0421fb

Please sign in to comment.