Skip to content

Commit de22193

Browse files
committed
added more unittests
1 parent 3a0cecf commit de22193

File tree

3 files changed

+10
-44
lines changed

3 files changed

+10
-44
lines changed

playground/main.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ console.log("duration", audioTest.duration.millis);
4646

4747
await audioTrack.add(audioTest);
4848
await audioTrack.removeSilences();
49-
50-
console.log("clips", audioTrack.clips);
51-
console.log("duration", audioTrack.clips.at(0)?.start);
52-
console.log("duration", audioTrack.clips.at(0)?.stop);
53-
console.log("duration", audioTrack.clips.at(1)?.start);
54-
console.log("duration", audioTrack.clips.at(1)?.stop);
49+
audioTrack.stacked(true);
5550

5651
image.animate()
5752
.rotation(-16).to(14, 5).to(-7, 10).to(24, 7).to(-3, 9).to(19, 7).to(-14, 12).to(5, 9).to(-30, 13)

src/tracks/media/media.spec.ts

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,58 +37,32 @@ describe('The Media Track Object', () => {
3737
});
3838

3939
it('ignores no silences', async () => {
40-
const clip = new MediaClip();
40+
const clip = new MockMediaClip(30000, [new Timestamp(10000), new Timestamp(20000)], [], new Audio());
4141
clip.duration.frames = 30;
4242
await track.add(clip);
4343
await track.removeSilences();
4444
expect(track.clips.length).toBe(1);
4545
});
4646

47-
// it('ignores not applicable silences', async () => {
48-
// const clip = new MockMediaClip(30000, [new Timestamp(10000), new Timestamp(20000)], [
49-
// {
50-
// start: new Timestamp(0),
51-
// stop: new Timestamp(500),
52-
// },
53-
// {
54-
// start: new Timestamp(30000),
55-
// stop: new Timestamp(30500),
56-
// },
57-
// ], new Audio());
58-
// await track.add(clip);
59-
// expect(clip.source).toBeDefined();
60-
// await track.removeSilences();
61-
// expect(track.clips.length).toBe(1);
62-
// expect(track.clips.at(0)).toBe(clip);
63-
// });
64-
65-
it('removes silences', async () => {
47+
it('ignores not applicable silences', async () => {
6648
const clip = new MockMediaClip(30000, [new Timestamp(10000), new Timestamp(20000)], [
6749
{
6850
start: new Timestamp(0),
69-
stop: new Timestamp(10050),
51+
stop: new Timestamp(500),
7052
},
7153
{
72-
start: new Timestamp(11000),
73-
stop: new Timestamp(15000),
74-
},
75-
{
76-
start: new Timestamp(19000),
54+
start: new Timestamp(30000),
7755
stop: new Timestamp(30500),
7856
},
7957
], new Audio());
8058
await track.add(clip);
8159
expect(clip.source).toBeDefined();
8260
await track.removeSilences();
83-
expect(track.clips.length).toBe(2);
84-
expect(track.clips.at(0)?.range[0].millis).toBe(10051);
85-
expect(track.clips.at(0)?.range[1].millis).toBe(11000);
86-
expect(track.clips.at(1)?.range[0].millis).toBe(15001);
87-
expect(track.clips.at(1)?.range[1].millis).toBe(19000);
61+
expect(track.clips.length).toBe(1);
62+
expect(track.clips.at(0)).toBe(clip);
8863
});
8964

90-
it('removes silences stacked', async () => {
91-
track.stacked(true);
65+
it('removes silences', async () => {
9266
const clip = new MockMediaClip(30000, [new Timestamp(10000), new Timestamp(20000)], [
9367
{
9468
start: new Timestamp(0),
@@ -109,8 +83,8 @@ describe('The Media Track Object', () => {
10983
expect(track.clips.length).toBe(2);
11084
expect(track.clips.at(0)?.range[0].millis).toBe(10051);
11185
expect(track.clips.at(0)?.range[1].millis).toBe(11000);
112-
expect(track.clips.at(1)?.range[0].millis).toBe(11001);
113-
expect(track.clips.at(1)?.range[1].millis).toBe(15000);
86+
expect(track.clips.at(1)?.range[0].millis).toBe(15001);
87+
expect(track.clips.at(1)?.range[1].millis).toBe(19000);
11488
});
11589

11690
it('should propagate a seek call', async () => {

src/tracks/media/media.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ export class MediaTrack<Clip extends MediaClip> extends Track<MediaClip> {
2727
* @returns Array of silence periods with start and stop times in seconds
2828
*/
2929
public async removeSilences() {
30-
// if (!(this.strategy instanceof StackInsertStrategy)) {
31-
// throw new Error("Cannot remove silences from a non-stacked track");
32-
// }
3330

3431
// Process each clip
3532
for (const clip of this.clips) {

0 commit comments

Comments
 (0)