Skip to content

Commit b17f74a

Browse files
authored
Minor refactor to unit tests (#7227)
* Minor refactor to unit tests * Reorder imports * Don't console log device type * Remove unused import * Put app creation in a utility function * Lint fix * Remove newlines * Update ESLint config for tests
1 parent accc78d commit b17f74a

File tree

73 files changed

+376
-344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+376
-344
lines changed

eslint.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default [
5252
{
5353
files: ['test/**/*.mjs'],
5454
rules: {
55+
'import/order': 'error',
5556
'no-unused-expressions': 'off',
5657
'prefer-arrow-callback': 'off' // Mocha uses function callbacks
5758
}

src/platform/graphics/null/null-graphics-device.js

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Debug } from '../../../core/debug.js';
21
import {
32
DEVICETYPE_NULL
43
} from '../constants.js';
@@ -18,8 +17,6 @@ class NullGraphicsDevice extends GraphicsDevice {
1817
this.isNull = true;
1918
this._deviceType = DEVICETYPE_NULL;
2019
this.samples = 1;
21-
22-
Debug.log('NullGraphicsDevice');
2320
}
2421

2522
destroy() {

test/app.mjs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Application } from '../src/framework/application.js';
2+
import { NullGraphicsDevice } from '../src/platform/graphics/null/null-graphics-device.js';
3+
4+
/**
5+
* Create a new application instance that uses the null graphics device.
6+
* @returns {Application} The new application instance.
7+
*/
8+
function createApp() {
9+
const canvas = document.createElement('canvas');
10+
const graphicsDevice = new NullGraphicsDevice(canvas);
11+
return new Application(canvas, { graphicsDevice });
12+
}
13+
14+
export { createApp };

test/core/core.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { extend } from '../../src/core/core.js';
2-
31
import { expect } from 'chai';
42

3+
import { extend } from '../../src/core/core.js';
4+
55
describe('core', function () {
66

77
describe('#extend', function () {

test/core/event-handler.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { EventHandler } from '../../src/core/event-handler.js';
2-
31
import { expect } from 'chai';
42

3+
import { EventHandler } from '../../src/core/event-handler.js';
4+
55
describe('EventHandler', function () {
66

77
describe('#hasEvent', function () {

test/core/guid.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { guid } from '../../src/core/guid.js';
2-
31
import { expect } from 'chai';
42

3+
import { guid } from '../../src/core/guid.js';
4+
55
describe('guid', function () {
66

77
describe('#create', function () {

test/core/hash.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { hashCode, hash32Fnv1a } from '../../src/core/hash.js';
2-
31
import { expect } from 'chai';
42

3+
import { hashCode, hash32Fnv1a } from '../../src/core/hash.js';
4+
55
describe('hashCode', function () {
66

77
it('returns 0 for the empty string', function () {

test/core/indexed-list.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { IndexedList } from '../../src/core/indexed-list.js';
2-
31
import { expect } from 'chai';
42

3+
import { IndexedList } from '../../src/core/indexed-list.js';
4+
55
describe('IndexedList', function () {
66

77
describe('#constructor', function () {

test/core/math/bit-packing.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { BitPacking } from '../../../src/core/math/bit-packing.js';
2-
31
import { expect } from 'chai';
42

3+
import { BitPacking } from '../../../src/core/math/bit-packing.js';
4+
55
describe('BitPacking', function () {
66

77
describe('#set', function () {

test/core/math/color.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Color } from '../../../src/core/math/color.js';
2-
31
import { expect } from 'chai';
42

3+
import { Color } from '../../../src/core/math/color.js';
4+
55
describe('Color', function () {
66

77
describe('#constructor', function () {

test/core/math/curve-set.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { expect } from 'chai';
2+
13
import { CURVE_LINEAR, CURVE_SMOOTHSTEP, CURVE_SPLINE, CURVE_STEP } from '../../../src/core/math/constants.js';
24
import { CurveSet } from '../../../src/core/math/curve-set.js';
35

4-
import { expect } from 'chai';
5-
66
describe('CurveSet', function () {
77

88
describe('#constructor', function () {

test/core/math/curve.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { expect } from 'chai';
2+
13
import { CURVE_LINEAR, CURVE_SMOOTHSTEP, CURVE_SPLINE, CURVE_STEP } from '../../../src/core/math/constants.js';
24
import { Curve } from '../../../src/core/math/curve.js';
35

4-
import { expect } from 'chai';
5-
66
describe('Curve', function () {
77

88
describe('#constructor', function () {

test/core/math/mat3.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { expect } from 'chai';
2+
13
import { Mat3 } from '../../../src/core/math/mat3.js';
24
import { Mat4 } from '../../../src/core/math/mat4.js';
35
import { Vec3 } from '../../../src/core/math/vec3.js';
46

5-
import { expect } from 'chai';
6-
77
const identity = [1, 0, 0, 0, 1, 0, 0, 0, 1];
88
const increasing = [1, 2, 3, 4, 5, 6, 7, 8, 9];
99
const decreasing = [9, 8, 7, 6, 5, 4, 3, 2, 1];

test/core/math/mat4.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { expect } from 'chai';
2+
13
import { Mat4 } from '../../../src/core/math/mat4.js';
24
import { Quat } from '../../../src/core/math/quat.js';
35
import { Vec3 } from '../../../src/core/math/vec3.js';
46
import { Vec4 } from '../../../src/core/math/vec4.js';
57

6-
import { expect } from 'chai';
7-
88
describe('Mat4', function () {
99

1010
describe('#data', function () {

test/core/math/math.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { math } from '../../../src/core/math/math.js';
2-
31
import { expect } from 'chai';
42

3+
import { math } from '../../../src/core/math/math.js';
4+
55
describe('math', function () {
66

77
describe('#DEG_TO_RAD', function () {

test/core/math/quat.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { expect } from 'chai';
2+
13
import { Mat4 } from '../../../src/core/math/mat4.js';
24
import { Quat } from '../../../src/core/math/quat.js';
35
import { Vec3 } from '../../../src/core/math/vec3.js';
46

5-
import { expect } from 'chai';
6-
77
describe('Quat', function () {
88

99
describe('#constructor()', function () {

test/core/math/vec2.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Vec2 } from '../../../src/core/math/vec2.js';
2-
31
import { expect } from 'chai';
42

3+
import { Vec2 } from '../../../src/core/math/vec2.js';
4+
55
describe('Vec2', function () {
66

77
describe('#constructor', function () {

test/core/math/vec3.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Vec3 } from '../../../src/core/math/vec3.js';
2-
31
import { expect } from 'chai';
42

3+
import { Vec3 } from '../../../src/core/math/vec3.js';
4+
55
describe('Vec3', function () {
66

77
describe('#constructor', function () {

test/core/math/vec4.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Vec4 } from '../../../src/core/math/vec4.js';
2-
31
import { expect } from 'chai';
42

3+
import { Vec4 } from '../../../src/core/math/vec4.js';
4+
55
describe('Vec4', function () {
66

77
describe('#constructor', function () {

test/core/path.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { path } from '../../src/core/path.js';
2-
31
import { expect } from 'chai';
42

3+
import { path } from '../../src/core/path.js';
4+
55
describe('path', function () {
66

77
describe('#extractPath', function () {

test/core/preprocessor.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Preprocessor } from '../../src/core/preprocessor.js';
2-
31
import { expect } from 'chai';
42

3+
import { Preprocessor } from '../../src/core/preprocessor.js';
4+
55
describe('Preprocessor', function () {
66

77
const includes = new Map([

test/core/shape/plane.test.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Plane } from '../../../src/core/shape/plane.js';
2-
import { Vec3 } from '../../../src/core/math/vec3.js';
3-
41
import { expect } from 'chai';
52

3+
import { Vec3 } from '../../../src/core/math/vec3.js';
4+
import { Plane } from '../../../src/core/shape/plane.js';
5+
66
describe('Plane', function () {
77

88
describe('#constructor', function () {

test/core/sorted-loop-array.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { SortedLoopArray } from '../../src/core/sorted-loop-array.js';
2-
31
import { expect } from 'chai';
42

3+
import { SortedLoopArray } from '../../src/core/sorted-loop-array.js';
4+
55
describe('SortedLoopArray', function () {
66

77
describe('#constructor', function () {

test/core/string.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { string } from '../../src/core/string.js';
2-
31
import { expect } from 'chai';
42

3+
import { string } from '../../src/core/string.js';
4+
55
describe('string', function () {
66

77
describe('#format', function () {

test/core/uri.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createURI, URI } from '../../src/core/uri.js';
2-
31
import { expect } from 'chai';
42

3+
import { createURI, URI } from '../../src/core/uri.js';
4+
55
describe('URI', function () {
66

77
describe('#constructor', function () {

test/fixtures.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import http from 'http';
2+
13
import globalJsdom from 'global-jsdom';
24
import handler from 'serve-handler';
3-
import http from 'http';
45

56
let cleanup;
67
let server;

test/framework/anim/controller/anim-blend-tree.test.mjs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { AnimBlendTree } from '../../../../src/framework/anim/controller/anim-blend-tree.js';
1+
import { expect } from 'chai';
2+
23
import { AnimBlendTree1D } from '../../../../src/framework/anim/controller/anim-blend-tree-1d.js';
3-
import { AnimBlendTreeDirect } from '../../../../src/framework/anim/controller/anim-blend-tree-direct.js';
44
import { AnimBlendTreeCartesian2D } from '../../../../src/framework/anim/controller/anim-blend-tree-2d-cartesian.js';
55
import { AnimBlendTreeDirectional2D } from '../../../../src/framework/anim/controller/anim-blend-tree-2d-directional.js';
6+
import { AnimBlendTreeDirect } from '../../../../src/framework/anim/controller/anim-blend-tree-direct.js';
7+
import { AnimBlendTree } from '../../../../src/framework/anim/controller/anim-blend-tree.js';
68
import { AnimState } from '../../../../src/framework/anim/controller/anim-state.js';
7-
import { expect } from 'chai';
89

910
describe('AnimBlendTree', function () {
1011
const findParameter = () => {};

test/framework/anim/controller/anim-controller.test.mjs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1+
import { expect } from 'chai';
2+
3+
import { INTERPOLATION_LINEAR } from '../../../../src/framework/anim/constants.js';
14
import { AnimController } from '../../../../src/framework/anim/controller/anim-controller.js';
2-
import { Entity } from '../../../../src/framework/entity.js';
3-
import { AnimComponentBinder } from '../../../../src/framework/components/anim/component-binder.js';
5+
import { ANIM_LESS_THAN } from '../../../../src/framework/anim/controller/constants.js';
6+
import { AnimCurve } from '../../../../src/framework/anim/evaluator/anim-curve.js';
7+
import { AnimData } from '../../../../src/framework/anim/evaluator/anim-data.js';
48
import { AnimEvaluator } from '../../../../src/framework/anim/evaluator/anim-evaluator.js';
5-
import { Application } from '../../../../src/framework/application.js';
69
import { AnimTrack } from '../../../../src/framework/anim/evaluator/anim-track.js';
7-
import { AnimData } from '../../../../src/framework/anim/evaluator/anim-data.js';
8-
import { AnimCurve } from '../../../../src/framework/anim/evaluator/anim-curve.js';
9-
import { INTERPOLATION_LINEAR } from '../../../../src/framework/anim/constants.js';
10-
import { ANIM_LESS_THAN } from '../../../../src/framework/anim/controller/constants.js';
11-
import { NullGraphicsDevice } from '../../../../src/platform/graphics/null/null-graphics-device.js';
12-
13-
import { expect } from 'chai';
10+
import { AnimComponentBinder } from '../../../../src/framework/components/anim/component-binder.js';
11+
import { Entity } from '../../../../src/framework/entity.js';
12+
import { createApp } from '../../../app.mjs';
1413

1514
describe('AnimController', function () {
1615

1716
let app;
1817
let controller;
1918

2019
beforeEach(function () {
21-
const canvas = document.createElement('canvas');
22-
app = new Application(canvas, { graphicsDevice: new NullGraphicsDevice(canvas) });
20+
app = createApp();
21+
2322
const states = [
2423
{
2524
name: 'START'
@@ -100,7 +99,8 @@ describe('AnimController', function () {
10099
});
101100

102101
afterEach(function () {
103-
app.destroy();
102+
app?.destroy();
103+
app = null;
104104
});
105105

106106
describe('#constructor', function () {

test/framework/anim/controller/anim-node.test.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { expect } from 'chai';
2+
13
import { AnimNode } from '../../../../src/framework/anim/controller/anim-node.js';
24
import { AnimState } from '../../../../src/framework/anim/controller/anim-state.js';
3-
import { expect } from 'chai';
45

56
describe('AnimNode', function () {
67

test/framework/anim/controller/anim-state.test.mjs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { AnimState } from '../../../../src/framework/anim/controller/anim-state.js';
21
import { expect } from 'chai';
3-
import { ANIM_BLEND_1D } from '../../../../src/framework/anim/controller/constants.js';
2+
43
import { INTERPOLATION_LINEAR } from '../../../../src/framework/anim/constants.js';
4+
import { AnimState } from '../../../../src/framework/anim/controller/anim-state.js';
5+
import { ANIM_BLEND_1D } from '../../../../src/framework/anim/controller/constants.js';
56
import { AnimCurve } from '../../../../src/framework/anim/evaluator/anim-curve.js';
67
import { AnimData } from '../../../../src/framework/anim/evaluator/anim-data.js';
78
import { AnimTrack } from '../../../../src/framework/anim/evaluator/anim-track.js';

test/framework/anim/controller/anim-transition.test.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { AnimTransition } from '../../../../src/framework/anim/controller/anim-transition.js';
21
import { expect } from 'chai';
32

3+
import { AnimTransition } from '../../../../src/framework/anim/controller/anim-transition.js';
4+
45
describe('AnimTransition', function () {
56

67
describe('#constructor', function () {

test/framework/anim/evaluator/anim-cache.test.mjs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { expect } from 'chai';
2+
3+
import { INTERPOLATION_STEP, INTERPOLATION_LINEAR } from '../../../../src/framework/anim/constants.js';
14
import { AnimCache } from '../../../../src/framework/anim/evaluator/anim-cache.js';
25
import { AnimData } from '../../../../src/framework/anim/evaluator/anim-data.js';
3-
import { INTERPOLATION_STEP, INTERPOLATION_LINEAR } from '../../../../src/framework/anim/constants.js';
4-
import { expect } from 'chai';
56

67
describe('AnimCache', function () {
78
const animCache = new AnimCache();

test/framework/anim/evaluator/anim-clip.test.mjs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { AnimTrack } from '../../../../src/framework/anim/evaluator/anim-track.js';
2-
import { AnimData } from '../../../../src/framework/anim/evaluator/anim-data.js';
3-
import { AnimCurve } from '../../../../src/framework/anim/evaluator/anim-curve.js';
1+
import { expect } from 'chai';
2+
3+
import { INTERPOLATION_LINEAR } from '../../../../src/framework/anim/constants.js';
44
import { AnimClip } from '../../../../src/framework/anim/evaluator/anim-clip.js';
5+
import { AnimCurve } from '../../../../src/framework/anim/evaluator/anim-curve.js';
6+
import { AnimData } from '../../../../src/framework/anim/evaluator/anim-data.js';
57
import { AnimEvents } from '../../../../src/framework/anim/evaluator/anim-events.js';
6-
import { INTERPOLATION_LINEAR } from '../../../../src/framework/anim/constants.js';
7-
import { expect } from 'chai';
8+
import { AnimTrack } from '../../../../src/framework/anim/evaluator/anim-track.js';
89

910
describe('AnimClip', function () {
1011
let animClip;

0 commit comments

Comments
 (0)