-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFFmpeg.spec.js
69 lines (59 loc) · 2.2 KB
/
FFmpeg.spec.js
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
'use strict'
const expect = require('chai').expect
const mockRequire = require('mock-require')
const childProcess = require('child_process')
const global = require('global-modules')
const path = require('path')
describe('FFmpeg', function () {
const moduleName = '../lib/FFmpeg.js'
const errorModule = './data/throwing.js'
const defaultSpawn = childProcess.spawnSync
function cleanup () {
delete require.cache[ require.resolve(path.join(__dirname, moduleName)) ]
mockRequire.stopAll()
childProcess.spawnSync = defaultSpawn
}
beforeEach(cleanup)
afterEach(cleanup)
it('should prefer @ffmpeg-installer', function () {
mockRequire('@ffmpeg-installer/ffmpeg', { path: 'foo' })
const require1 = require(moduleName)
expect(require1).to.be.equals('foo')
})
it('should fallback to ffmpeg-static', function () {
mockRequire('@ffmpeg-installer/ffmpeg', errorModule)
mockRequire('ffmpeg-static', 1)
const require1 = require(moduleName)
expect(require1).to.be.equals(1)
})
it('should fallback to ffmpeg on $PATH', function () {
let called = false
mockRequire('@ffmpeg-installer/ffmpeg', errorModule)
mockRequire('ffmpeg-static', errorModule)
childProcess.spawnSync = function (cmd) {
called = true
expect(cmd).to.be.equals('ffmpeg')
return 'FFmpeg output'
}
expect(require(moduleName)).to.be.equals('ffmpeg')
expect(called).to.be.true
})
it('should fallback to global @ffmpeg-installer', function () {
mockRequire('@ffmpeg-installer/ffmpeg', errorModule)
mockRequire('ffmpeg-static', errorModule)
childProcess.spawnSync = errorSpawn
mockRequire(path.join(global, '@ffmpeg-installer/ffmpeg'), { path: 'qux' })
expect(require(moduleName)).to.be.equals('qux')
})
it('should fallback to global ffmpeg-static', function () {
mockRequire('@ffmpeg-installer/ffmpeg', errorModule)
mockRequire('ffmpeg-static', errorModule)
childProcess.spawnSync = errorSpawn
mockRequire(path.join(global, '@ffmpeg-installer/ffmpeg'), errorModule)
mockRequire(path.join(global, 'ffmpeg-static'), 2)
expect(require(moduleName)).to.be.equals(2)
})
function errorSpawn () {
return { error: new Error() }
}
})