Skip to content

🎥 Make videos programmatically with React

fix webcodecs tests

JonnyBurger1ecbb24a3c49
diff --git a/packages/webcodecs/src/it-tests/extract-frames-accuracy.test.mts b/packages/webcodecs/src/it-tests/extract-frames-accuracy.test.mts
index a5dea1da7e..ad92ae20a2 100644
--- a/packages/webcodecs/src/it-tests/extract-frames-accuracy.test.mts
+++ b/packages/webcodecs/src/it-tests/extract-frames-accuracy.test.mts
@@ -38,7 +38,12 @@ test.describe('Should return correct frame even when it is out of order', () =>
'http://localhost:' + (viteServer?.config.server.port ?? 5173),
);
- await page.waitForFunction(() => (window as any).videoFrames?.length === 1);
+ await page.waitForFunction(() => (window as any).done === true);
+ const errors = await page.evaluate(() => (window as any).errors);
+ if (errors.length > 0) {
+ throw new Error(errors[0].message);
+ }
+
const value = await page.evaluate(() => (window as any).videoFrames);
expect(value[0]).toBe(Math.floor((11 / 30) * WEBCODECS_TIMESCALE));
});
diff --git a/packages/webcodecs/src/it-tests/extract-frames-accuracy/main.mts b/packages/webcodecs/src/it-tests/extract-frames-accuracy/main.mts
index 05734063b1..2f59bd5a2c 100644
--- a/packages/webcodecs/src/it-tests/extract-frames-accuracy/main.mts
+++ b/packages/webcodecs/src/it-tests/extract-frames-accuracy/main.mts
@@ -3,17 +3,27 @@ import {extractFrames} from '../../extract-frames';
declare global {
interface Window {
videoFrames: number[];
+ done: boolean;
+ errors: Error[];
}
}
window.videoFrames = [];
+window.done = false;
+window.errors = [];
-// @ts-expect-error
-await extractFrames({
+extractFrames({
src: 'https://parser.media/framer.mp4',
onFrame(frame) {
window.videoFrames.push(frame.timestamp);
},
timestampsInSeconds: [11 / 30],
acknowledgeRemotionLicense: true,
-});
+})
+ .catch((err) => {
+ window.errors.push(err);
+ console.error(err);
+ })
+ .finally(() => {
+ window.done = true;
+ });
diff --git a/packages/webcodecs/src/it-tests/extract-frames.test.mts b/packages/webcodecs/src/it-tests/extract-frames.test.mts
index ef968fdf0f..a744fcf3a5 100644
--- a/packages/webcodecs/src/it-tests/extract-frames.test.mts
+++ b/packages/webcodecs/src/it-tests/extract-frames.test.mts
@@ -24,15 +24,19 @@ test.afterAll(async () => {
}
});
-test.describe('Vite app', () => {
- test('should execute vite script and set window property', async ({page}) => {
+test.describe('Extract frames', () => {
+ test('should extract frames', async ({page}) => {
await page.goto(
'http://localhost:' + (viteServer?.config.server.port ?? 5173),
);
- await page.waitForFunction(() => (window as any).videoFrames?.length === 5);
+ await page.waitForFunction(() => (window as any).done === true);
+ const errors = await page.evaluate(() => (window as any).errors);
+ if (errors.length > 0) {
+ throw new Error(errors[0].message);
+ }
+
const value = await page.evaluate(() => (window as any).videoFrames);
- console.log(value);
expect(value[0]).toBe(0);
expect(value[1] === 1000000 || value[1] === 920000).toBe(true);
expect(value[2] === 2000000 || value[2] === 1880000).toBe(true);
diff --git a/packages/webcodecs/src/it-tests/extract-frames/main.mts b/packages/webcodecs/src/it-tests/extract-frames/main.mts
index 23e18be22c..b47484c7fd 100644
--- a/packages/webcodecs/src/it-tests/extract-frames/main.mts
+++ b/packages/webcodecs/src/it-tests/extract-frames/main.mts
@@ -3,17 +3,27 @@ import {extractFrames} from '../../extract-frames';
declare global {
interface Window {
videoFrames: number[];
+ done: boolean;
+ errors: Error[];
}
}
+window.done = false;
window.videoFrames = [];
+window.errors = [];
-// @ts-expect-error
-await extractFrames({
+extractFrames({
src: 'https://parser.media/video.mp4',
onFrame(frame) {
window.videoFrames.push(frame.timestamp);
},
timestampsInSeconds: [0, 1, 2, 3, 4],
acknowledgeRemotionLicense: true,
-});
+})
+ .catch((err) => {
+ window.errors.push(err);
+ console.error(err);
+ })
+ .finally(() => {
+ window.done = true;
+ });