forked from harvard-lil/scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.test.js
53 lines (43 loc) · 1.64 KB
/
options.test.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
import test from 'node:test'
import assert from 'node:assert/strict'
import * as CONSTANTS from './constants.js'
import { defaults, filterOptions } from './options.js'
test('filterOptions invalid or empty argument should return full defaults.', async (_t) => {
for (const input of [{}, [], null, undefined, true, 'FOO', () => {}]) {
const options = filterOptions(input)
assert(options !== defaults)
assert(Object.keys(options).length === Object.keys(defaults).length)
for (const key of Object.keys(options)) {
assert(options[key] === defaults[key])
}
}
})
test('filterOptions entries that are not provided should be filled with defaults.', async (_t) => {
const newOptions = { logLevel: 'trace', screenshot: false, captureWindowX: 1920, captureWindowY: 1080 }
for (const [key, value] of Object.entries(filterOptions(newOptions))) {
// Modified
if (key in newOptions) {
assert(value === newOptions[key])
// Default
} else {
assert(value === defaults[key])
}
}
})
test('filterOptions entries are typecast based on defaults.', async (_t) => {
const newOptions = filterOptions({
screenshot: 0,
captureWindowX: '1920',
captureWindowY: '1080',
intercepter: 12
})
for (const key of Object.keys(newOptions)) {
assert(newOptions[key].constructor === defaults[key].constructor)
}
})
test('filterOptions ytDlpPath must be a valid path to a file.', async (_t) => {
assert.doesNotThrow(() => filterOptions()) // Default should not throw
for (const ytDlpPath of [null, false, true, 12, () => {}, 'FOO', CONSTANTS.TMP_PATH]) {
assert.throws(() => filterOptions({ ytDlpPath }))
}
})