-
Notifications
You must be signed in to change notification settings - Fork 64
/
parse.test.ts
35 lines (29 loc) · 936 Bytes
/
parse.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
import * as utils from '../test-utils'
import { parse } from '../src'
test.each(utils.fixtures)('parse SRT fixture: %s', async fixture => {
const buffer = await utils.pipeline(
utils.getFixtureStream(fixture, 'srt').pipe(parse())
)
const expected = JSON.parse(await utils.getFixture(fixture, 'srt.json'))
expect(buffer).toEqual(expected)
})
test.each(utils.fixtures)('parse VTT fixture: %s', async fixture => {
const buffer = await utils.pipeline(
utils.getFixtureStream(fixture, 'vtt').pipe(parse())
)
const expected = JSON.parse(await utils.getFixture(fixture, 'vtt.json'))
expect(buffer).toEqual(expected)
})
test('error handling', done => {
const stream = utils.createStreamFromString(`
1
Foo Bar
{{ THIS IS A INVALID TIMESTAMP }}
`)
stream.pipe(parse()).on('error', err => {
expect(err).toEqual(
new Error(`expected timestamp at row 2, but received: "Foo Bar"`)
)
done()
})
})