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
|
import test from 'node:test';
import assert from 'node:assert/strict';
import {parseTime, formatTime, selection, stable, matches, monitoringGain} from '../src/producer/web/state.js';
test('exact excerpt times work beyond four hours without wrapping', () => {
assert.equal(parseTime('05:12:03.125'), 18723.125);
assert.equal(formatTime(18723.125), '05:12:03.125');
assert.equal(parseTime('14400'), 14400);
assert.equal(formatTime(59.9999), '00:01:00');
for (const value of ['1:60:00', '-1', 'Infinity', '1e3', '', '00:00:60']) assert.throws(() => parseTime(value));
assert.deepEqual(selection('03:59:30', '04:00:00', 14400), {start: 14370, duration: 30});
for (const [start, end] of [['0', '121'], ['2', '1'], ['0', '0'], ['14399', '14401']]) assert.throws(() => selection(start, end, 14400));
});
test('preview identity includes uploaded source, exact selection and every requested setting', () => {
const snapshot = {upload_id: 'upload', input_id: 'identity', start: 10, duration: 30, settings: {mp3: true, trim_silence: true, denoiser: 'none'}};
assert.ok(matches(snapshot, structuredClone(snapshot)));
assert.ok(matches(snapshot, {...snapshot, settings: {denoiser: 'none', trim_silence: true, mp3: true}}));
for (const change of [{upload_id: 'other'}, {input_id: 'changed'}, {start: 11}, {duration: 29}, {settings: {...snapshot.settings, trim_silence: false}}]) assert.equal(matches(snapshot, {...snapshot, ...change}), false);
assert.equal(matches(snapshot, null), false);
assert.equal(stable({b: 2, a: 1}), stable({a: 1, b: 2}));
});
test('monitoring is attenuation only and independent of export settings', () => {
assert.equal(monitoringGain(-6, false), 1);
assert.equal(monitoringGain(6, true), 1);
assert.equal(monitoringGain(NaN, true), 1);
assert.ok(Math.abs(monitoringGain(-6, true) - 0.501187) < 0.000001);
});
|