-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors_test.ts
152 lines (138 loc) · 3.68 KB
/
errors_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { assertExpectError, assertInstanceOf } from "./_assertions.ts";
import {
assertRejects,
assertThrows,
dirname,
fromFileUrl,
} from "./dev_deps.ts";
import { Encoding } from "./encoding.ts";
import { EncodingEventStream } from "./encoding_event_stream.ts";
import { EncodingProcess } from "./encoding_process.ts";
import {
EncodingEventStreamAlreadyDisposed,
EncodingProcessAlreadyStarted,
EncodingProcessNotStarted,
FFmpegBinaryNotFound,
FFmpegBinaryPermissionDenied,
FFmpegCommandFailed,
FFprobeBinaryNotFound,
FFprobeBinaryPermissionDenied,
FFprobeCommandFailed,
} from "./errors.ts";
import { EncodingErrorEvent } from "./events.ts";
import { ffmpeg } from "./ffmpeg.ts";
import { ffprobe } from "./ffprobe.ts";
const rootDir: string = dirname(fromFileUrl(import.meta.url));
const inputPath = `${rootDir}/fixtures/sample.mp4`;
Deno.test({
name: "ffprobe binary not found error",
async fn() {
await assertRejects(
() => ffprobe(inputPath, { binary: "fffprobe" }),
FFprobeBinaryNotFound,
);
},
});
Deno.test({
name: "ffprobe binary permission denied error",
async fn() {
await assertRejects(
() => ffprobe(inputPath, { binary: rootDir }),
FFprobeBinaryPermissionDenied,
);
},
});
Deno.test({
name: "ffprobe command failed error",
async fn() {
await assertRejects(
() => ffprobe(inputPath, { args: ["--abc"] }),
FFprobeCommandFailed,
);
},
});
Deno.test({
name: "ffmpeg binary not found error",
fn() {
const encoding = new Encoding();
encoding.binary = "fffprobe";
const process = new EncodingProcess(encoding);
assertThrows(() => process.run(), FFmpegBinaryNotFound);
},
});
Deno.test({
name: "ffmpeg binary permission denied error",
fn() {
const encoding = new Encoding();
encoding.binary = rootDir;
const process = new EncodingProcess(encoding);
assertThrows(() => process.run(), FFmpegBinaryPermissionDenied);
},
});
Deno.test({
name: "ffmpeg command failed error",
async fn() {
const outputPath = `${rootDir}/.tmp/ffmpeg command failed error.mp4`;
const encoder = ffmpeg(inputPath)
.output(outputPath)
.audioBitrate("192kk");
let errorEvent: EncodingErrorEvent | undefined;
for await (const process of encoder) {
process.run();
for await (const event of process) {
if (event.type === "error") {
errorEvent = event;
}
}
process.close();
}
assertInstanceOf(errorEvent, EncodingErrorEvent);
assertExpectError(errorEvent?.error, FFmpegCommandFailed);
},
});
Deno.test({
name: "encoding process not started error",
async fn() {
const encoding = new Encoding();
encoding.binary = "ffprobe";
const process = new EncodingProcess(encoding);
await assertRejects(
() => process.status(),
EncodingProcessNotStarted,
);
},
});
Deno.test({
name: "encoding process already started error",
async fn() {
const outputPath =
`${rootDir}/.tmp/encoding process already started error.mp4`;
const encoding = new Encoding();
encoding.input = inputPath;
encoding.output = outputPath;
encoding.override = true;
const process = new EncodingProcess(encoding);
process.run();
assertThrows(
() => process.run(),
EncodingProcessAlreadyStarted,
);
await process.status();
process.close();
},
});
Deno.test({
name: "encoding event stream already disposed error",
fn() {
const eventStream = new EncodingEventStream(
new EncodingProcess(
new Encoding(),
),
);
eventStream.dispose();
assertThrows(
() => eventStream.dispose(),
EncodingEventStreamAlreadyDisposed,
);
},
});