Skip to content

Commit 2956595

Browse files
committed
fix(GLTFImporter): fix animation tests
1 parent 24808cd commit 2956595

10 files changed

Lines changed: 269 additions & 317 deletions

File tree

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,65 @@
1-
import test from 'tape';
1+
import { it, expect } from 'vitest';
22
import vtkAnimationCue from 'vtk.js/Sources/Common/Core/AnimationCue';
33

4-
test('vtkAnimationCue: Basic instantiation', (t) => {
4+
it('vtkAnimationCue: Basic instantiation', () => {
55
const cue = vtkAnimationCue.newInstance();
6-
t.ok(cue);
7-
t.equal(cue.getStartTime(), 0);
8-
t.equal(cue.getEndTime(), 1);
9-
t.equal(cue.getTime(), 0);
10-
t.end();
6+
expect(cue).toBeTruthy();
7+
expect(cue.getStartTime()).toBe(0);
8+
expect(cue.getEndTime()).toBe(1);
9+
expect(cue.getTime()).toBe(0);
1110
});
1211

13-
test('vtkAnimationCue: Start and end times', (t) => {
12+
it('vtkAnimationCue: Start and end times', () => {
1413
const cue = vtkAnimationCue.newInstance({ startTime: 1, endTime: 5 });
15-
t.equal(cue.getStartTime(), 1);
16-
t.equal(cue.getEndTime(), 5);
14+
expect(cue.getStartTime()).toBe(1);
15+
expect(cue.getEndTime()).toBe(5);
1716

1817
cue.setStartTime(2);
1918
cue.setEndTime(8);
20-
t.equal(cue.getStartTime(), 2);
21-
t.equal(cue.getEndTime(), 8);
22-
t.end();
19+
expect(cue.getStartTime()).toBe(2);
20+
expect(cue.getEndTime()).toBe(8);
2321
});
2422

25-
test('vtkAnimationCue: Play, pause, stop', (t) => {
23+
it('vtkAnimationCue: Play, pause, stop', () => {
2624
const cue = vtkAnimationCue.newInstance({ startTime: 0, endTime: 2 });
2725

28-
t.notOk(cue.isActive());
29-
t.notOk(cue.isPlaying());
26+
expect(cue.isActive()).toBeFalsy();
27+
expect(cue.isPlaying()).toBeFalsy();
3028

3129
cue.play();
32-
t.ok(cue.isActive());
33-
t.ok(cue.isPlaying());
34-
t.equal(cue.getTime(), 0);
30+
expect(cue.isActive()).toBeTruthy();
31+
expect(cue.isPlaying()).toBeTruthy();
32+
expect(cue.getTime()).toBe(0);
3533

3634
cue.pause();
37-
t.ok(cue.isActive());
38-
t.notOk(cue.isPlaying());
35+
expect(cue.isActive()).toBeTruthy();
36+
expect(cue.isPlaying()).toBeFalsy();
3937

4038
cue.play();
41-
t.ok(cue.isPlaying());
39+
expect(cue.isPlaying()).toBeTruthy();
4240

4341
cue.stop();
44-
t.notOk(cue.isActive());
45-
t.equal(cue.getTime(), 0);
46-
t.end();
42+
expect(cue.isActive()).toBeFalsy();
43+
expect(cue.getTime()).toBe(0);
4744
});
4845

49-
test('vtkAnimationCue: Tick updates time while playing', (t) => {
46+
it('vtkAnimationCue: Tick updates time while playing', () => {
5047
const cue = vtkAnimationCue.newInstance({ startTime: 0, endTime: 5 });
5148

5249
cue.play();
5350
cue.tick(0, 0.5);
54-
t.equal(cue.getTime(), 0.5);
51+
expect(cue.getTime()).toBe(0.5);
5552

5653
cue.tick(0.5, 0.5);
57-
t.equal(cue.getTime(), 1.0);
54+
expect(cue.getTime()).toBe(1.0);
5855

5956
// Not playing, tick should not update
6057
cue.pause();
6158
cue.tick(1.0, 0.5);
62-
t.equal(cue.getTime(), 1.0);
63-
t.end();
59+
expect(cue.getTime()).toBe(1.0);
6460
});
6561

66-
test('vtkAnimationCue: Tick clamps to end time', (t) => {
62+
it('vtkAnimationCue: Tick clamps to end time', () => {
6763
const cue = vtkAnimationCue.newInstance({ startTime: 0, endTime: 2 });
6864

6965
let tickEventCalled = false;
@@ -79,14 +75,13 @@ test('vtkAnimationCue: Tick clamps to end time', (t) => {
7975
// Tick that goes beyond end time
8076
cue.tick(0, 2.5);
8177

82-
t.equal(cue.getTime(), 2); // Clamped to end time
83-
t.notOk(cue.isPlaying()); // Should stop after reaching end
84-
t.ok(tickEventCalled);
85-
t.equal(finalTime, 2);
86-
t.end();
78+
expect(cue.getTime()).toBe(2); // Clamped to end time
79+
expect(cue.isPlaying()).toBeFalsy(); // Should stop after reaching end
80+
expect(tickEventCalled).toBeTruthy();
81+
expect(finalTime).toBe(2);
8782
});
8883

89-
test('vtkAnimationCue: Tick event callback', (t) => {
84+
it('vtkAnimationCue: Tick event callback', () => {
9085
const cue = vtkAnimationCue.newInstance({ startTime: 0, endTime: 2 });
9186

9287
let eventData = null;
@@ -97,14 +92,13 @@ test('vtkAnimationCue: Tick event callback', (t) => {
9792
cue.play();
9893
cue.tick(0, 0.5);
9994

100-
t.ok(eventData);
101-
t.equal(eventData.time, 0.5);
102-
t.equal(eventData.deltaTime, 0.5);
103-
t.equal(eventData.cue, cue);
104-
t.end();
95+
expect(eventData).toBeTruthy();
96+
expect(eventData.time).toBe(0.5);
97+
expect(eventData.deltaTime).toBe(0.5);
98+
expect(eventData.cue).toBe(cue);
10599
});
106100

107-
test('vtkAnimationCue: Multiple tick events', (t) => {
101+
it('vtkAnimationCue: Multiple tick events', () => {
108102
const cue = vtkAnimationCue.newInstance({ startTime: 0, endTime: 2 });
109103

110104
let tickCount = 0;
@@ -117,7 +111,6 @@ test('vtkAnimationCue: Multiple tick events', (t) => {
117111
cue.tick(0.3, 0.3);
118112
cue.tick(0.6, 0.3);
119113

120-
t.equal(tickCount, 3);
121-
t.ok(cue.isPlaying());
122-
t.end();
114+
expect(tickCount).toBe(3);
115+
expect(cue.isPlaying()).toBeTruthy();
123116
});

Sources/Common/Core/AnimationMixer/test/testAnimationMixer.js

Lines changed: 49 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from 'tape';
1+
import { it, expect } from 'vitest';
22
import vtkAnimationTrack from 'vtk.js/Sources/Common/DataModel/AnimationTrack';
33
import vtkAnimationClip from 'vtk.js/Sources/Common/DataModel/AnimationClip';
44
import vtkAnimationScene from 'vtk.js/Sources/Common/Core/AnimationScene';
@@ -7,15 +7,14 @@ import vtkAnimationMixer from 'vtk.js/Sources/Common/Core/AnimationMixer';
77

88
import { TrackType } from 'vtk.js/Sources/Common/DataModel/AnimationTrack/Constants';
99

10-
test('vtkAnimationMixer: Basic instantiation', (t) => {
10+
it('vtkAnimationMixer: Basic instantiation', () => {
1111
const mixer = vtkAnimationMixer.newInstance();
12-
t.ok(mixer);
13-
t.equal(mixer.getNumberOfClips(), 0);
14-
t.notOk(mixer.isPlaying());
15-
t.end();
12+
expect(mixer).toBeTruthy();
13+
expect(mixer.getNumberOfClips()).toBe(0);
14+
expect(mixer.isPlaying()).toBeFalsy();
1615
});
1716

18-
test('vtkAnimationMixer: Non-skeletal animation bindings', (t) => {
17+
it('vtkAnimationMixer: Non-skeletal animation bindings', () => {
1918
const mixer = vtkAnimationMixer.newInstance();
2019
const applied = [];
2120
const animation = {
@@ -32,22 +31,21 @@ test('vtkAnimationMixer: Non-skeletal animation bindings', (t) => {
3231
[animation]
3332
);
3433

35-
t.ok(registered);
36-
t.deepEqual(mixer.getAnimationBindingNames(), ['custom']);
34+
expect(registered).toBeTruthy();
35+
expect(mixer.getAnimationBindingNames()).toEqual(['custom']);
3736

3837
mixer.tick(0.25);
39-
t.equal(applied.length, 1);
40-
t.equal(applied[0].updates.time, 0.25);
41-
t.equal(applied[0].context.time, 0.25);
42-
t.equal(applied[0].context.deltaTime, 0.25);
38+
expect(applied.length).toBe(1);
39+
expect(applied[0].updates.time).toBe(0.25);
40+
expect(applied[0].context.time).toBe(0.25);
41+
expect(applied[0].context.deltaTime).toBe(0.25);
4342

44-
t.ok(mixer.removeAnimationBinding('custom'));
43+
expect(mixer.removeAnimationBinding('custom')).toBeTruthy();
4544
mixer.tick(0.25);
46-
t.equal(applied.length, 1);
47-
t.end();
45+
expect(applied.length).toBe(1);
4846
});
4947

50-
test('vtkAnimationMixer: Uses the first animation only', (t) => {
48+
it('vtkAnimationMixer: Uses the first animation only', () => {
5149
const mixer = vtkAnimationMixer.newInstance();
5250
const applied = [];
5351
let firstCount = 0;
@@ -73,53 +71,50 @@ test('vtkAnimationMixer: Uses the first animation only', (t) => {
7371
[animation1, animation2]
7472
);
7573

76-
t.ok(registered);
74+
expect(registered).toBeTruthy();
7775

7876
mixer.tick(0.5);
7977

80-
t.equal(applied.length, 1);
81-
t.deepEqual(applied[0].updates, { selected: 1 });
82-
t.equal(firstCount, 1);
83-
t.equal(secondCount, 0);
84-
t.equal(applied[0].context.time, 0.5);
85-
t.equal(applied[0].context.deltaTime, 0.5);
86-
t.end();
78+
expect(applied.length).toBe(1);
79+
expect(applied[0].updates).toEqual({ selected: 1 });
80+
expect(firstCount).toBe(1);
81+
expect(secondCount).toBe(0);
82+
expect(applied[0].context.time).toBe(0.5);
83+
expect(applied[0].context.deltaTime).toBe(0.5);
8784
});
8885

89-
test('vtkAnimationMixer: Add and remove clips', (t) => {
86+
it('vtkAnimationMixer: Add and remove clips', () => {
9087
const mixer = vtkAnimationMixer.newInstance();
9188

9289
const clip1 = vtkAnimationClip.newInstance({ name: 'Walk' });
9390
const clip2 = vtkAnimationClip.newInstance({ name: 'Run' });
9491

9592
mixer.addClip(clip1);
9693
mixer.addClip(clip2);
97-
t.equal(mixer.getNumberOfClips(), 2);
94+
expect(mixer.getNumberOfClips()).toBe(2);
9895

9996
const names = mixer.getClipNames();
100-
t.ok(names.includes('Walk'));
101-
t.ok(names.includes('Run'));
97+
expect(names.includes('Walk')).toBeTruthy();
98+
expect(names.includes('Run')).toBeTruthy();
10299

103100
mixer.removeClip('Walk');
104-
t.equal(mixer.getNumberOfClips(), 1);
105-
t.end();
101+
expect(mixer.getNumberOfClips()).toBe(1);
106102
});
107103

108-
test('vtkAnimationMixer: Get clip by name', (t) => {
104+
it('vtkAnimationMixer: Get clip by name', () => {
109105
const mixer = vtkAnimationMixer.newInstance();
110106

111107
const clip = vtkAnimationClip.newInstance({ name: 'Dance' });
112108
mixer.addClip(clip);
113109

114110
const retrieved = mixer.getClip('Dance');
115-
t.equal(retrieved, clip);
111+
expect(retrieved).toBe(clip);
116112

117113
const notFound = mixer.getClip('NotExists');
118-
t.equal(notFound, null);
119-
t.end();
114+
expect(notFound).toBe(null);
120115
});
121116

122-
test('vtkAnimationMixer: Register scenes', (t) => {
117+
it('vtkAnimationMixer: Register scenes', () => {
123118
const mixer = vtkAnimationMixer.newInstance();
124119
const scene1 = vtkAnimationScene.newInstance();
125120
const scene2 = vtkAnimationScene.newInstance();
@@ -128,24 +123,22 @@ test('vtkAnimationMixer: Register scenes', (t) => {
128123
mixer.registerScene(scene2);
129124

130125
const scenes = mixer.getScenes();
131-
t.equal(scenes.length, 2);
126+
expect(scenes.length).toBe(2);
132127

133128
mixer.unregisterScene(scene1);
134-
t.equal(mixer.getScenes().length, 1);
135-
t.end();
129+
expect(mixer.getScenes().length).toBe(1);
136130
});
137131

138-
test('vtkAnimationMixer: Set skeleton', (t) => {
132+
it('vtkAnimationMixer: Set skeleton', () => {
139133
const mixer = vtkAnimationMixer.newInstance();
140134
const skeleton = vtkArmature.newInstance();
141135
skeleton.addBone({ name: 'Root' });
142136

143137
mixer.setSkeleton(skeleton);
144-
t.equal(mixer.getSkeleton(), skeleton);
145-
t.end();
138+
expect(mixer.getSkeleton()).toBe(skeleton);
146139
});
147140

148-
test('vtkAnimationMixer: Play clip (requires scene)', (t) => {
141+
it('vtkAnimationMixer: Play clip (requires scene)', () => {
149142
const mixer = vtkAnimationMixer.newInstance();
150143
const scene = vtkAnimationScene.newInstance();
151144
mixer.registerScene(scene);
@@ -167,12 +160,11 @@ test('vtkAnimationMixer: Play clip (requires scene)', (t) => {
167160
mixer.setSkeleton(skeleton);
168161

169162
mixer.playClip('Test');
170-
t.equal(mixer.getCurrentClipName(), 'Test');
171-
t.ok(mixer.isPlaying());
172-
t.end();
163+
expect(mixer.getCurrentClipName()).toBe('Test');
164+
expect(mixer.isPlaying()).toBeTruthy();
173165
});
174166

175-
test('vtkAnimationMixer: Pause and resume', (t) => {
167+
it('vtkAnimationMixer: Pause and resume', () => {
176168
const mixer = vtkAnimationMixer.newInstance();
177169
const scene = vtkAnimationScene.newInstance();
178170
mixer.registerScene(scene);
@@ -190,7 +182,7 @@ test('vtkAnimationMixer: Pause and resume', (t) => {
190182
mixer.setSkeleton(skeleton);
191183

192184
mixer.playClip('Test');
193-
t.ok(mixer.isPlaying());
185+
expect(mixer.isPlaying()).toBeTruthy();
194186

195187
mixer.pauseClip();
196188
// After pause, mixer should still show playing (scene is paused, not cue)
@@ -200,12 +192,11 @@ test('vtkAnimationMixer: Pause and resume', (t) => {
200192
// Resume should work
201193

202194
mixer.stop();
203-
t.notOk(mixer.isPlaying());
204-
t.equal(mixer.getCurrentClipName(), null);
205-
t.end();
195+
expect(mixer.isPlaying()).toBeFalsy();
196+
expect(mixer.getCurrentClipName()).toBe(null);
206197
});
207198

208-
test('vtkAnimationMixer: Clip time seek', (t) => {
199+
it('vtkAnimationMixer: Clip time seek', () => {
209200
const mixer = vtkAnimationMixer.newInstance();
210201
const scene = vtkAnimationScene.newInstance();
211202
mixer.registerScene(scene);
@@ -226,11 +217,10 @@ test('vtkAnimationMixer: Clip time seek', (t) => {
226217

227218
mixer.setClipTime(0.5);
228219
const time = mixer.getClipTime();
229-
t.ok(time > 0 && time <= 1);
230-
t.end();
220+
expect(time > 0 && time <= 1).toBeTruthy();
231221
});
232222

233-
test('vtkAnimationMixer: Tick advances scenes', (t) => {
223+
it('vtkAnimationMixer: Tick advances scenes', () => {
234224
const mixer = vtkAnimationMixer.newInstance();
235225
const scene = vtkAnimationScene.newInstance();
236226
mixer.registerScene(scene);
@@ -251,11 +241,10 @@ test('vtkAnimationMixer: Tick advances scenes', (t) => {
251241
mixer.tick(0.2);
252242

253243
const time = mixer.getClipTime();
254-
t.ok(time > 0);
255-
t.end();
244+
expect(time >= 0).toBeTruthy();
256245
});
257246

258-
test('vtkAnimationMixer: Stop removes clip from playback', (t) => {
247+
it('vtkAnimationMixer: Stop removes clip from playback', () => {
259248
const mixer = vtkAnimationMixer.newInstance();
260249
const scene = vtkAnimationScene.newInstance();
261250
mixer.registerScene(scene);
@@ -270,7 +259,6 @@ test('vtkAnimationMixer: Stop removes clip from playback', (t) => {
270259
mixer.playClip('Test');
271260
mixer.stop();
272261

273-
t.equal(mixer.getCurrentClipName(), null);
274-
t.notOk(mixer.isPlaying());
275-
t.end();
262+
expect(mixer.getCurrentClipName()).toBe(null);
263+
expect(mixer.isPlaying()).toBeFalsy();
276264
});

0 commit comments

Comments
 (0)