🎥 Make videos programmatically with React
improve naming bug and test cases in get-current-time.ts
Tobias Boneracb708aa8b7c
diff --git a/packages/core/src/test/get-current-time.test.ts b/packages/core/src/test/get-current-time.test.tsnew file mode 100644index 0000000000..218a343a44--- /dev/null+++ b/packages/core/src/test/get-current-time.test.ts@@ -0,0 +1,84 @@+import {getMediaTime} from '../video/get-current-time';++describe('correctly calculate media time of video element', () => {+ const mp4Precision = 0.04;+ const webmPrecision = 0.02;++ describe('src mp4', () => {+ test('mp4 - Should correctly calculate the media time of a video element', () => {+ expect(+ getMediaTime({+ fps: 30,+ frame: 30,+ playbackRate: 1,+ src: 'video.mp4',+ startFrom: 0,+ })+ ).toBeCloseTo(1, mp4Precision);+ });++ test('mp4 - Should correctly calculate the media time of a video element with faster framerate', () => {+ expect(+ getMediaTime({+ fps: 30,+ frame: 30,+ playbackRate: 2,+ src: 'video.mp4',+ startFrom: 0,+ })+ ).toBeCloseTo(2, mp4Precision);+ });++ test('mp4 - Should correctly calculate the media time of a video element with faster framerate and a startFrom', () => {+ // If playbackrate is 2, but the video only starts after 1 second, at 2sec, the video position should be 3sec+ expect(+ getMediaTime({+ fps: 30,+ frame: 60,+ playbackRate: 2,+ src: 'video.mp4',+ startFrom: 30,+ })+ ).toBeCloseTo(3, mp4Precision);+ });+ });++ describe('src webm', () => {+ test('webm - Should correctly calculate the media time of a video element', () => {+ expect(+ getMediaTime({+ fps: 30,+ frame: 30,+ playbackRate: 1,+ src: 'video.webm',+ startFrom: 0,+ })+ ).toBeCloseTo(1, webmPrecision);+ });++ test('webm - Should correctly calculate the media time of a video element with faster framerate', () => {+ expect(+ getMediaTime({+ fps: 30,+ frame: 30,+ playbackRate: 2,+ src: 'video.webm',+ startFrom: 0,+ })+ ).toBeCloseTo(2, webmPrecision);+ });++ test('webm - Should correctly calculate the media time of a video element with faster framerate and a startFrom', () => {+ // If playbackrate is 2, but the video only starts after 1 second, at 2sec, the video position should be 3sec+ expect(+ getMediaTime({+ fps: 30,+ frame: 60,+ playbackRate: 2,+ src: 'video.webm',+ startFrom: 30,+ })+ ).toBeCloseTo(3, webmPrecision);+ });+ });+});diff --git a/packages/core/src/test/get-media-time.ts b/packages/core/src/test/get-media-time.tsdeleted file mode 100644index 0d01d03d91..0000000000--- a/packages/core/src/test/get-media-time.ts+++ /dev/null@@ -1,38 +0,0 @@-import {getMediaTime} from '../video/get-current-time';--test('Should correctly calculate the media time of a video element', () => {- expect(- getMediaTime({- fps: 30,- frame: 30,- playbackRate: 1,- src: 'video.mp4',- startFrom: 0,- })- ).toBe(1);-});--test('Should correctly calculate the media time of a video element with faster framerate', () => {- expect(- getMediaTime({- fps: 30,- frame: 30,- playbackRate: 2,- src: 'video.mp4',- startFrom: 0,- })- ).toBe(2);-});--test('Should correctly calculate the media time of a video element with faster framerate and a startFrom', () => {- // If playbackrate is 2, but the video only starts after 1 second, at 2sec, the video position should be 3sec- expect(- getMediaTime({- fps: 30,- frame: 60,- playbackRate: 2,- src: 'video.mp4',- startFrom: 30,- })- ).toBe(3);-});