Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Suggestion, Add npm run test-unit-examples command #20900

Merged
merged 1 commit into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"lint-examples": "eslint examples/js examples/jsm --ext js --ext ts --ignore-pattern libs && tsc -p utils/build/tsconfig-examples.lint.json",
"test-lint": "eslint src --ext js --ext ts && tsc -p utils/build/tsconfig.lint.json",
"test-unit": "npm run unit --prefix test",
"test-unit-examples": "npm run unit-examples --prefix test",
"test-e2e": "node test/e2e/puppeteer.js",
"test-e2e-cov": "node test/e2e/check-coverage.js",
"make-screenshot": "node test/e2e/puppeteer.js --make"
Expand Down
3 changes: 2 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "This package hiding test dependincies from main repo because puppeteer is pretty big.",
"scripts": {
"dev": "rollup -c rollup.unit.config.js -w -m inline",
"unit": "rollup -c rollup.unit.config.js && rimraf node_modules/three && qunit -r failonlyreporter -f !-webonly unit/build/three.source.unit.js"
"unit": "rollup -c rollup.unit.config.js && rimraf node_modules/three && qunit -r failonlyreporter -f !-webonly unit/build/three.source.unit.js",
"unit-examples": "rollup -c rollup.unit.config.js && rimraf node_modules/three && qunit -r failonlyreporter -f !-webonly unit/build/three.example.unit.js"
},
"devDependencies": {
"failonlyreporter": "^1.0.0",
Expand Down
210 changes: 107 additions & 103 deletions test/unit/example/exporters/GLTFExporter.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,113 @@ export default QUnit.module( 'Exporters', () => {

} );

QUnit.test( 'utils - insertKeyframe', ( assert ) => {

var track;
var index;

function createTrack() {

return new VectorKeyframeTrack(
'foo.bar',
[ 5, 10, 15, 20, 25, 30 ],
[ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ],
InterpolateLinear
);

}

track = createTrack();
index = GLTFExporter.Utils.insertKeyframe( track, 0 );
assert.equal( index, 0, 'prepend - index' );
assert.smartEqual( Array.from( track.times ), [ 0, 5, 10, 15, 20, 25, 30 ], 'prepend - time' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'prepend - value' );

track = createTrack();
index = GLTFExporter.Utils.insertKeyframe( track, 7.5 );
assert.equal( index, 1, 'insert - index (linear)' );
assert.smartEqual( Array.from( track.times ), [ 5, 7.5, 10, 15, 20, 25, 30 ], 'insert - time (linear)' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 0.5, 4.5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'insert - value (linear)' );

track = createTrack();
track.setInterpolation( InterpolateDiscrete );
index = GLTFExporter.Utils.insertKeyframe( track, 16 );
assert.equal( index, 3, 'insert - index (linear)' );
assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 16, 20, 25, 30 ], 'insert - time (discrete)' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 2, 3, 3, 2, 4, 1, 5, 0 ], 'insert - value (discrete)' );

track = createTrack();
index = GLTFExporter.Utils.insertKeyframe( track, 100 );
assert.equal( index, 6, 'append - index' );
assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30, 100 ], 'append time' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0, 5, 0 ], 'append value' );

track = createTrack();
index = GLTFExporter.Utils.insertKeyframe( track, 15 );
assert.equal( index, 2, 'existing - index' );
assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30 ], 'existing - time' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'existing - value' );

track = createTrack();
index = GLTFExporter.Utils.insertKeyframe( track, 20.000005 );
assert.equal( index, 3, 'tolerance - index' );
assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30 ], 'tolerance - time' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'tolerance - value' );

} );

QUnit.test( 'utils - mergeMorphTargetTracks', ( assert ) => {

var trackA = new NumberKeyframeTrack(
'foo.morphTargetInfluences[a]',
[ 5, 10, 15, 20, 25, 30 ],
[ 0, 0.2, 0.4, 0.6, 0.8, 1.0 ],
InterpolateLinear
);

var trackB = new NumberKeyframeTrack(
'foo.morphTargetInfluences[b]',
[ 10, 50 ],
[ 0.25, 0.75 ],
InterpolateLinear
);

var geometry = new BufferGeometry();
var position = new BufferAttribute( new Float32Array( [ 0, 0, 0, 0, 0, 1, 1, 0, 1 ] ), 3 );
geometry.setAttribute( 'position', position );
geometry.morphAttributes.position = [ position, position ];

var mesh = new Mesh( geometry );
mesh.name = 'foo';
mesh.morphTargetDictionary.a = 0;
mesh.morphTargetDictionary.b = 1;

var root = new Object3D();
root.add( mesh );

var clip = new AnimationClip( 'waltz', undefined, [ trackA, trackB ] );
clip = GLTFExporter.Utils.mergeMorphTargetTracks( clip, root );

assert.equal( clip.tracks.length, 1, 'tracks are merged' );

var track = clip.tracks[ 0 ];

assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30, 50 ], 'all keyframes are present' );

var expectedValues = [ 0, 0.25, 0.2, 0.25, 0.4, 0.3125, 0.6, 0.375, 0.8, 0.4375, 1.0, 0.5, 1.0, 0.75 ];

for ( var i = 0; i < track.values.length; i ++ ) {

assert.numEqual( track.values[ i ], expectedValues[ i ], 'all values are merged or interpolated - ' + i );

}

} );

} );

QUnit.module( 'GLTFExporter-webonly', () => {

QUnit.test( 'parse - metadata', ( assert ) => {

var done = assert.async();
Expand Down Expand Up @@ -236,109 +343,6 @@ export default QUnit.module( 'Exporters', () => {

} );

QUnit.test( 'utils - insertKeyframe', ( assert ) => {

var track;
var index;

function createTrack() {

return new VectorKeyframeTrack(
'foo.bar',
[ 5, 10, 15, 20, 25, 30 ],
[ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ],
InterpolateLinear
);

}

track = createTrack();
index = GLTFExporter.Utils.insertKeyframe( track, 0 );
assert.equal( index, 0, 'prepend - index' );
assert.smartEqual( Array.from( track.times ), [ 0, 5, 10, 15, 20, 25, 30 ], 'prepend - time' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'prepend - value' );

track = createTrack();
index = GLTFExporter.Utils.insertKeyframe( track, 7.5 );
assert.equal( index, 1, 'insert - index (linear)' );
assert.smartEqual( Array.from( track.times ), [ 5, 7.5, 10, 15, 20, 25, 30 ], 'insert - time (linear)' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 0.5, 4.5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'insert - value (linear)' );

track = createTrack();
track.setInterpolation( InterpolateDiscrete );
index = GLTFExporter.Utils.insertKeyframe( track, 16 );
assert.equal( index, 3, 'insert - index (linear)' );
assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 16, 20, 25, 30 ], 'insert - time (discrete)' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 2, 3, 3, 2, 4, 1, 5, 0 ], 'insert - value (discrete)' );

track = createTrack();
index = GLTFExporter.Utils.insertKeyframe( track, 100 );
assert.equal( index, 6, 'append - index' );
assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30, 100 ], 'append time' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0, 5, 0 ], 'append value' );

track = createTrack();
index = GLTFExporter.Utils.insertKeyframe( track, 15 );
assert.equal( index, 2, 'existing - index' );
assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30 ], 'existing - time' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'existing - value' );

track = createTrack();
index = GLTFExporter.Utils.insertKeyframe( track, 20.000005 );
assert.equal( index, 3, 'tolerance - index' );
assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30 ], 'tolerance - time' );
assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'tolerance - value' );

} );

QUnit.test( 'utils - mergeMorphTargetTracks', ( assert ) => {

var trackA = new NumberKeyframeTrack(
'foo.morphTargetInfluences[a]',
[ 5, 10, 15, 20, 25, 30 ],
[ 0, 0.2, 0.4, 0.6, 0.8, 1.0 ],
InterpolateLinear
);

var trackB = new NumberKeyframeTrack(
'foo.morphTargetInfluences[b]',
[ 10, 50 ],
[ 0.25, 0.75 ],
InterpolateLinear
);

var geometry = new BufferGeometry();
var position = new BufferAttribute( new Float32Array( [ 0, 0, 0, 0, 0, 1, 1, 0, 1 ] ), 3 );
geometry.setAttribute( 'position', position );
geometry.morphAttributes.position = [ position, position ];

var mesh = new Mesh( geometry );
mesh.name = 'foo';
mesh.morphTargetDictionary.a = 0;
mesh.morphTargetDictionary.b = 1;

var root = new Object3D();
root.add( mesh );

var clip = new AnimationClip( 'waltz', undefined, [ trackA, trackB ] );
clip = GLTFExporter.Utils.mergeMorphTargetTracks( clip, root );

assert.equal( clip.tracks.length, 1, 'tracks are merged' );

var track = clip.tracks[ 0 ];

assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30, 50 ], 'all keyframes are present' );

var expectedValues = [ 0, 0.25, 0.2, 0.25, 0.4, 0.3125, 0.6, 0.375, 0.8, 0.4375, 1.0, 0.5, 1.0, 0.75 ];

for ( var i = 0; i < track.values.length; i ++ ) {

assert.numEqual( track.values[ i ], expectedValues[ i ], 'all values are merged or interpolated - ' + i );

}

} );

QUnit.test( 'parse - KHR_lights_punctual extension', ( assert ) => {

const done = assert.async();
Expand Down
4 changes: 4 additions & 0 deletions test/unit/example/loaders/GLTFLoader.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default QUnit.module( 'Loaders', () => {

} );

} );

QUnit.module( 'GLTFLoader-webonly', () => {

QUnit.test( 'parse - basic', ( assert ) => {

var done = assert.async();
Expand Down