Merge pull request #86 from JonnyBurger/url-source-allow-reading-small-files

Do not make UrlSource fail if the size of the file is smaller than 512kb (+ add a Vitest browser mode test)
This commit is contained in:
Jonny Burger
2025-09-03 18:13:42 +02:00
committed by GitHub
parent a2a30c3e92
commit f13a2e6732
7 changed files with 2792 additions and 8 deletions
+2753 -4
View File
File diff suppressed because it is too large Load Diff
+6 -2
View File
@@ -27,7 +27,9 @@
"build": "./build.sh",
"watch": "tsx scripts/bundle.ts --watch",
"lint": "eslint .",
"test": "vitest --run",
"test-node": "cd test && vitest node --run",
"test-web": "cd test && vitest browser --run --browser",
"test": "npm run test-node && npm run test-web",
"check": "tsc -p src --noEmit && tsc -p packages/mp3-encoder/src --noEmit && tsc -p scripts --noEmit && tsc -p tsconfig.vite.json --noEmit && rm tsconfig.vite.tsbuildinfo",
"check-docblocks": "tsx scripts/check-docblocks.ts dist/mediabunny.d.ts",
"docs:dev": "vitepress dev docs",
@@ -83,7 +85,9 @@
"vitepress": "^1.6.3",
"vitepress-plugin-llms": "^1.5.1",
"vitepress-plugin-mermaid": "^2.0.17",
"vitest": "3.2.4"
"vitest": "3.2.4",
"@vitest/browser": "3.2.4",
"webdriverio": "9.19.2"
},
"keywords": [
"media",
@@ -0,0 +1,19 @@
import { expect, test } from 'vitest';
import { UrlSource } from '../../src/source.js';
import { ALL_FORMATS } from '../../src/input-format.js';
import { Input } from '../../src/input.js';
test('Should be able to load a very small video file via URL (<512 kB)', async () => {
const source = new UrlSource('/frames.webm');
const input = new Input({
source,
formats: ALL_FORMATS,
});
const primaryVideoTrack = await input.getPrimaryVideoTrack();
if (!primaryVideoTrack) {
throw new Error('No video track found');
};
const duration = await primaryVideoTrack.computeDuration();
expect(duration).toBeCloseTo(3.33333);
});
@@ -1,11 +1,13 @@
import { expect, test } from 'vitest';
import { ALL_FORMATS, MP4, EncodedPacketSink, Input, FilePathSource } from '../src/index.js';
import path from 'node:path';
import { ALL_FORMATS, MP4, EncodedPacketSink, Input, FilePathSource } from '../../src/index.js';
const __dirname = new URL('.', import.meta.url).pathname;
test('Should be able to get packets from a .MP4 file', async () => {
const filePath = path.join(__dirname, '..', 'public/video.mp4');
const input = new Input({
source: new FilePathSource(`${__dirname}/files/video.mp4`),
source: new FilePathSource(filePath),
formats: ALL_FORMATS,
});
Binary file not shown.
+10
View File
@@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
browser: {
provider: 'webdriverio',
instances: [{ browser: 'chrome' }],
},
},
});