diff --git a/CHANGELOG.md b/CHANGELOG.md index cb76464..5ba0cbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project should be documented in this file. - [Issue #195](https://github.com/boonya/rtsp-video-recorder/issues/195) acknowledged, investigated and fixed - Dev dependencies updated +- `jest.mocked` instead of `ts-jest/mocked` due to https://github.com/facebook/jest/pull/12089 ## [2.0.2-beta.1] - Bugfix & update diff --git a/test/events/error.spec.ts b/test/events/error.spec.ts index 777f04f..f65b0c4 100644 --- a/test/events/error.spec.ts +++ b/test/events/error.spec.ts @@ -1,5 +1,4 @@ import { ChildProcessWithoutNullStreams } from 'child_process'; -import { mocked } from 'ts-jest/utils'; import { verifyAllOptions } from '../../src/validators'; import {mockSpawnProcess, URI, DESTINATION} from '../test.helpers'; import Recorder, { RecorderEvents, RecorderError } from '../../src/recorder'; @@ -10,7 +9,7 @@ let fakeProcess: ChildProcessWithoutNullStreams; let eventHandler: () => void; beforeEach(() => { - mocked(verifyAllOptions).mockReturnValue([]); + jest.mocked(verifyAllOptions).mockReturnValue([]); fakeProcess = mockSpawnProcess(); eventHandler = jest.fn().mockName('onError'); }); diff --git a/test/events/file_created.spec.ts b/test/events/file_created.spec.ts index 1d15ea0..26db7a1 100644 --- a/test/events/file_created.spec.ts +++ b/test/events/file_created.spec.ts @@ -1,5 +1,4 @@ import { ChildProcessWithoutNullStreams } from 'child_process'; -import { mocked } from 'ts-jest/utils'; import { verifyAllOptions } from '../../src/validators'; import {mockSpawnProcess, URI, DESTINATION} from '../test.helpers'; import Recorder, { RecorderEvents } from '../../src/recorder'; @@ -10,7 +9,7 @@ let fakeProcess: ChildProcessWithoutNullStreams; let eventHandler: () => void; beforeEach(() => { - mocked(verifyAllOptions).mockReturnValue([]); + jest.mocked(verifyAllOptions).mockReturnValue([]); fakeProcess = mockSpawnProcess(); eventHandler = jest.fn().mockName('onFileCreated'); }); diff --git a/test/events/progress.spec.ts b/test/events/progress.spec.ts index 69ed417..b25f621 100644 --- a/test/events/progress.spec.ts +++ b/test/events/progress.spec.ts @@ -1,6 +1,5 @@ import { ChildProcessWithoutNullStreams } from 'child_process'; -import { mocked } from 'ts-jest/utils'; import { verifyAllOptions } from '../../src/validators'; import {mockSpawnProcess, URI, DESTINATION} from '../test.helpers'; import Recorder, { RecorderEvents } from '../../src/recorder'; @@ -11,7 +10,7 @@ let fakeProcess: ChildProcessWithoutNullStreams; let eventHandler: () => void; beforeEach(() => { - mocked(verifyAllOptions).mockReturnValue([]); + jest.mocked(verifyAllOptions).mockReturnValue([]); fakeProcess = mockSpawnProcess(); eventHandler = jest.fn().mockName('onProgress'); }); diff --git a/test/events/space_full.spec.ts b/test/events/space_full.spec.ts index ff27954..50a91cd 100644 --- a/test/events/space_full.spec.ts +++ b/test/events/space_full.spec.ts @@ -1,26 +1,23 @@ import { ChildProcessWithoutNullStreams } from 'child_process'; -import { mocked } from 'ts-jest/utils'; import { verifyAllOptions } from '../../src/validators'; import {mockSpawnProcess, URI, DESTINATION} from '../test.helpers'; import dirSize from '../../src/helpers/space'; import Recorder, { RecorderEvents, RecorderError } from '../../src/recorder'; -// import transformDirSizeThreshold from '../../src/helpers/sizeThreshold'; jest.mock('../../src/validators'); jest.mock('../../src/helpers/space'); -// jest.mock('../../src/helpers/sizeThreshold'); let fakeProcess: ChildProcessWithoutNullStreams; let onSpaceFull: () => void; beforeEach(() => { - mocked(verifyAllOptions).mockReturnValue([]); + jest.mocked(verifyAllOptions).mockReturnValue([]); fakeProcess = mockSpawnProcess(); onSpaceFull = jest.fn().mockName('onSpaceFull'); }); test('should not evaluate space if "threshold" is undefined', async () => { - mocked(dirSize).mockReturnValue(Infinity); + jest.mocked(dirSize).mockReturnValue(Infinity); new Recorder(URI, DESTINATION) .on(RecorderEvents.SPACE_FULL, onSpaceFull) @@ -36,7 +33,7 @@ test('should not evaluate space if "threshold" is undefined', async () => { }); test('should evaluate space but not rise an event if "used" is less than the "threshold"', async () => { - mocked(dirSize).mockReturnValue(300); + jest.mocked(dirSize).mockReturnValue(300); const onStopped = jest.fn().mockName('onStopped'); new Recorder(URI, DESTINATION, { dirSizeThreshold: 500 }) @@ -56,7 +53,7 @@ test('should evaluate space but not rise an event if "used" is less than the "th }); test('should evaluate space on start and rise an event if "used" is close to the "threshold"', async () => { - mocked(dirSize).mockReturnValue(496); + jest.mocked(dirSize).mockReturnValue(496); const onStopped = jest.fn().mockName('onStopped'); new Recorder(URI, DESTINATION, { dirSizeThreshold: 500 }) @@ -78,7 +75,7 @@ test('should evaluate space on start and rise an event if "used" is close to the }); test('should evaluate space on start and rise an event if "used" is bigger than the "threshold"', async () => { - mocked(dirSize).mockReturnValue(600); + jest.mocked(dirSize).mockReturnValue(600); const onStopped = jest.fn().mockName('onStopped'); new Recorder(URI, DESTINATION, { dirSizeThreshold: 500 }) @@ -100,7 +97,7 @@ test('should evaluate space on start and rise an event if "used" is bigger than }); test('should evaluate space twice and rise an event if "used" became bigger than the "threshold" at progress', async () => { - mocked(dirSize).mockReturnValueOnce(200); + jest.mocked(dirSize).mockReturnValueOnce(200); const onStop = jest.fn().mockName('onStop'); new Recorder(URI, DESTINATION, { dirSizeThreshold: 500 }) @@ -111,7 +108,7 @@ test('should evaluate space twice and rise an event if "used" became bigger than // We have to wait next tick await Promise.resolve(true); - mocked(dirSize).mockReturnValueOnce(600); + jest.mocked(dirSize).mockReturnValueOnce(600); fakeProcess.stderr.emit('data', Buffer.from('Opening \'segment.mp4\' for writing', 'utf8')); @@ -126,7 +123,7 @@ test('should evaluate space twice and rise an event if "used" became bigger than }); test('should return RecorderError - space evaluation failed', async () => { - mocked(dirSize).mockImplementation(() => { + jest.mocked(dirSize).mockImplementation(() => { throw new Error('space evaluation failed'); }); const onError = jest.fn().mockName('onError'); diff --git a/test/events/start.spec.ts b/test/events/start.spec.ts index 0a02403..1728888 100644 --- a/test/events/start.spec.ts +++ b/test/events/start.spec.ts @@ -1,4 +1,3 @@ -import { mocked } from 'ts-jest/utils'; import { verifyAllOptions } from '../../src/validators'; import {mockSpawnProcess, URI, DESTINATION} from '../test.helpers'; import Recorder, { RecorderEvents } from '../../src/recorder'; @@ -8,7 +7,7 @@ jest.mock('../../src/validators'); let onStart: () => void; beforeEach(() => { - mocked(verifyAllOptions).mockReturnValue([]); + jest.mocked(verifyAllOptions).mockReturnValue([]); mockSpawnProcess(); onStart = jest.fn().mockName('onStart'); }); diff --git a/test/events/started.spec.ts b/test/events/started.spec.ts index f8a97a8..cb613f7 100644 --- a/test/events/started.spec.ts +++ b/test/events/started.spec.ts @@ -1,5 +1,4 @@ import { ChildProcessWithoutNullStreams } from 'child_process'; -import { mocked } from 'ts-jest/utils'; import { verifyAllOptions } from '../../src/validators'; import {mockSpawnProcess, URI, DESTINATION} from '../test.helpers'; import Recorder, { RecorderEvents } from '../../src/recorder'; @@ -12,10 +11,10 @@ let fakeProcess: ChildProcessWithoutNullStreams; let eventHandler: () => void; beforeEach(() => { - mocked(verifyAllOptions).mockReturnValue([]); + jest.mocked(verifyAllOptions).mockReturnValue([]); fakeProcess = mockSpawnProcess(); eventHandler = jest.fn().mockName('onStarted'); - mocked(dirSize).mockReturnValue(0); + jest.mocked(dirSize).mockReturnValue(0); }); const FFMPEG_MESSAGE = `[libx264 @ 0x148816200] 264 - core 163 r3060 5db6aa6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=15 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 diff --git a/test/events/stop.spec.ts b/test/events/stop.spec.ts index 983b2c3..e2cefe1 100644 --- a/test/events/stop.spec.ts +++ b/test/events/stop.spec.ts @@ -1,4 +1,3 @@ -import { mocked } from 'ts-jest/utils'; import { verifyAllOptions } from '../../src/validators'; import {mockSpawnProcess, URI, DESTINATION} from '../test.helpers'; import Recorder, { RecorderEvents } from '../../src/recorder'; @@ -9,7 +8,7 @@ let onStop: () => void; let onStopped: () => void; beforeEach(() => { - mocked(verifyAllOptions).mockReturnValue([]); + jest.mocked(verifyAllOptions).mockReturnValue([]); mockSpawnProcess(); onStop = jest.fn().mockName('onStop'); onStopped = jest.fn().mockName('onStopped'); diff --git a/test/events/stopped.spec.ts b/test/events/stopped.spec.ts index 4376431..dcea9ae 100644 --- a/test/events/stopped.spec.ts +++ b/test/events/stopped.spec.ts @@ -1,5 +1,4 @@ import { ChildProcessWithoutNullStreams } from 'child_process'; -import { mocked } from 'ts-jest/utils'; import { verifyAllOptions } from '../../src/validators'; import {mockSpawnProcess, URI, DESTINATION} from '../test.helpers'; import Recorder, { RecorderEvents } from '../../src/recorder'; @@ -10,7 +9,7 @@ let fakeProcess: ChildProcessWithoutNullStreams; let eventHandler: () => void; beforeEach(() => { - mocked(verifyAllOptions).mockReturnValue([]); + jest.mocked(verifyAllOptions).mockReturnValue([]); fakeProcess = mockSpawnProcess(); eventHandler = jest.fn().mockName('onStopped'); }); diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts index 76c9df5..2c18933 100644 --- a/test/helpers.spec.ts +++ b/test/helpers.spec.ts @@ -1,4 +1,3 @@ -import { mocked } from 'ts-jest/utils'; import directoryExists from '../src/helpers/directoryExists'; import dirSize from '../src/helpers/space'; import fs from 'fs'; @@ -10,15 +9,13 @@ jest.mock('path'); describe('directoryExists', () => { test('exists', () => { - // @ts-ignore - mocked(fs).lstatSync.mockReturnValue({isDirectory: () => true}); + jest.mocked(fs).lstatSync.mockReturnValue({isDirectory: () => true}); expect(directoryExists('path')).toBeTruthy(); }); test('does not exist', () => { - // @ts-ignore - mocked(fs).lstatSync.mockImplementation(() => { + jest.mocked(fs).lstatSync.mockImplementation(() => { throw new Error('no such file or directory'); }); @@ -26,8 +23,7 @@ describe('directoryExists', () => { }); test('not a directory', () => { - // @ts-ignore - mocked(fs).lstatSync.mockReturnValue({isDirectory: () => false}); + jest.mocked(fs).lstatSync.mockReturnValue({isDirectory: () => false}); expect(() => directoryExists('path')).toThrowError('path exists but it is not a directory.'); }); @@ -44,9 +40,8 @@ test('transformSegmentTime', () => { }); test('should return directory size in bytes', () => { - mocked(fs).readdirSync.mockReturnValue(new Array(3).fill(0)); - // @ts-ignore - mocked(fs).statSync.mockReturnValue({isDirectory: () => false, size: 3}); + jest.mocked(fs).readdirSync.mockReturnValue(new Array(3).fill(0)); + jest.mocked(fs).statSync.mockReturnValue({isDirectory: () => false, size: 3}); const size = dirSize(''); diff --git a/test/process.spec.ts b/test/process.spec.ts index 26c97eb..c83ca59 100644 --- a/test/process.spec.ts +++ b/test/process.spec.ts @@ -1,4 +1,3 @@ -import { mocked } from 'ts-jest/utils'; import {mockSpawnProcess, URI, DESTINATION} from './test.helpers'; import Recorder from '../src/recorder'; import { verifyAllOptions } from '../src/validators'; @@ -7,7 +6,7 @@ import { Options } from '../src/types'; jest.mock('../src/validators'); beforeEach(() => { - mocked(verifyAllOptions).mockReturnValue([]); + jest.mocked(verifyAllOptions).mockReturnValue([]); }); it('Spawn arguments with no additional options defined', () => { diff --git a/test/recorder.spec.ts b/test/recorder.spec.ts index ce67ee1..fe4a073 100644 --- a/test/recorder.spec.ts +++ b/test/recorder.spec.ts @@ -1,4 +1,3 @@ -import { mocked } from 'ts-jest/utils'; import { verifyAllOptions } from '../src/validators'; import {mockSpawnProcess, URI, DESTINATION} from './test.helpers'; import Recorder, { RecorderValidationError } from '../src/recorder'; @@ -6,12 +5,12 @@ import Recorder, { RecorderValidationError } from '../src/recorder'; jest.mock('../src/validators'); beforeEach(() => { - mocked(verifyAllOptions).mockReturnValue([]); + jest.mocked(verifyAllOptions).mockReturnValue([]); mockSpawnProcess(); }); test('should throw RecorderValidationError if validation failed', () => { - mocked(verifyAllOptions).mockReturnValue([ + jest.mocked(verifyAllOptions).mockReturnValue([ 'Any validation error message', 'One more validation error message', ]); diff --git a/test/test.helpers.ts b/test/test.helpers.ts index e54293d..cd580b3 100644 --- a/test/test.helpers.ts +++ b/test/test.helpers.ts @@ -1,5 +1,4 @@ import { EventEmitter } from 'events'; -import { mocked } from 'ts-jest/utils'; import { spawn, ChildProcessWithoutNullStreams } from 'child_process'; import path from 'path'; @@ -26,7 +25,7 @@ export function mockSpawnProcess (options: MockSpawnProcessOptions = {}) { return true; }; - mocked(spawn).mockImplementation((...args) => { + jest.mocked(spawn).mockImplementation((...args) => { onSpawn(...args); return proc; });