Skip to content

Commit

Permalink
Migrate AssetReference tests from Karma to Node (#7214)
Browse files Browse the repository at this point in the history
* Migrate AssetReference tests from Karma to Node

* Reenable all tests

* typedef -> import
  • Loading branch information
willeastcott authored Dec 19, 2024
1 parent bb40a3f commit 5729cf1
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 100 deletions.
103 changes: 103 additions & 0 deletions test/framework/asset/asset-reference.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Application } from '../../../src/framework/application.js';
import { Asset } from '../../../src/framework/asset/asset.js';
import { AssetReference } from '../../../src/framework/asset/asset-reference.js';
import { NullGraphicsDevice } from '../../../src/platform/graphics/null/null-graphics-device.js';

import { Canvas } from 'skia-canvas';
import { expect } from 'chai';
import { fake, restore } from 'sinon';

describe('AssetReference', function () {
let app;
let parent;
let load;
let remove;
let add;

beforeEach(function () {
const canvas = new Canvas(500, 500);
app = new Application(canvas, { graphicsDevice: new NullGraphicsDevice(canvas) });
parent = fake();
load = fake();
remove = fake();
add = fake();
});

afterEach(function () {
app.destroy();
restore();
});

it('should call load callback when asset is loaded', function (done) {
const reg = new AssetReference('propName', parent, app.assets, {
load: load
});

const asset = new Asset('Reference Test', 'texture', {
url: 'test/test-assets/test.png'
});

reg.id = asset.id;

asset.once('load', function () {
expect(load.callCount).to.equal(1);
expect(load.args[0][0]).to.equal('propName');
expect(load.args[0][1]).to.equal(parent);
expect(load.args[0][2].id).to.equal(asset.id);
done();
});

app.assets.add(asset);
app.assets.load(asset);
});

it('should call add callback when asset is added', function (done) {
const reg = new AssetReference('propName', parent, app.assets, {
add: add
});

const asset = new Asset('Reference Test', 'texture', {
url: 'test/test-assets/test.png'
});

reg.id = asset.id;

app.assets.once('add', function () {
setTimeout(function () {
expect(add.callCount).to.equal(1);
expect(add.args[0][0]).to.equal('propName');
expect(add.args[0][1]).to.equal(parent);
expect(add.args[0][2].id).to.equal(asset.id);
done();
}, 0);
});

app.assets.add(asset);
});

it('should call remove callback when asset is removed', function (done) {
const reg = new AssetReference('propName', parent, app.assets, {
remove: remove
});

const asset = new Asset('Reference Test', 'texture', {
url: 'test/test-assets/test.png'
});

reg.id = asset.id;

asset.once('remove', function () {
setTimeout(function () {
expect(remove.callCount).to.equal(1);
expect(remove.args[0][0]).to.equal('propName');
expect(remove.args[0][1]).to.equal(parent);
expect(remove.args[0][2].id).to.equal(asset.id);
done();
}, 0);
});

app.assets.add(asset);
app.assets.remove(asset);
});

});
2 changes: 1 addition & 1 deletion test/framework/components/layout-group/component.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Canvas } from 'skia-canvas';
import { expect } from 'chai';
import { restore, spy, stub } from 'sinon';

/** @typedef {import('../../../../src/framework/components/layout-group/system.js').LayoutGroupComponentSystem} LayoutGroupComponentSystem */
/** @import { LayoutGroupComponentSystem } from '../../../../src/framework/components/layout-group/system.js' */

describe('LayoutGroupComponent', function () {
/** @type {Application} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Canvas } from 'skia-canvas';

import { expect } from 'chai';

/** @typedef {import('../../../../src/framework/components/element/component.js').ElementComponent} ElementComponent */
/** @import { ElementComponent } from '../../../../src/framework/components/element/component.js' */

describe('LayoutCalculator', function () {
/** @type {Application} */
Expand Down
2 changes: 1 addition & 1 deletion test/framework/utils/entity-reference.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Canvas } from 'skia-canvas';
import { expect } from 'chai';
import { restore, spy, stub } from 'sinon';

/** @typedef {import('../../../../src/framework/components/component.js').Component} Component */
/** @import { Component } from '../../../../src/framework/components/component.js' */

describe('EntityReference', function () {
/** @type {Application} */
Expand Down
97 changes: 0 additions & 97 deletions tests/framework/assets/test_asset_reference.js

This file was deleted.

0 comments on commit 5729cf1

Please sign in to comment.