🎥 Make videos programmatically with React
Exercise Windows Whisper installation through Node.js
Jonny Burger906510e08d5a
diff --git a/packages/install-whisper-cpp/src/test/fixtures/install-whisper.mjs b/packages/install-whisper-cpp/src/test/fixtures/install-whisper.mjsnew file mode 100644index 0000000000..8af90581d9--- /dev/null+++ b/packages/install-whisper-cpp/src/test/fixtures/install-whisper.mjs@@ -0,0 +1,26 @@+import assert from 'node:assert/strict';+import {readFileSync} from 'node:fs';+import {createRequire} from 'node:module';+import {ReadableStream} from 'node:stream/web';++const {installWhisperCpp} = createRequire(import.meta.url)(process.argv[2]);+const zip = readFileSync(process.argv[3]);+const to = process.argv[4];++globalThis.fetch = () =>+ Promise.resolve({+ headers: new Map([['content-length', String(zip.length)]]),+ body: new ReadableStream({+ start(controller) {+ controller.enqueue(zip);+ controller.close();+ },+ }),+ });++assert.deepEqual(await installWhisperCpp({to, version: '1.5.5'}), {+ alreadyExisted: false,+});+assert.deepEqual(await installWhisperCpp({to, version: '1.5.5'}), {+ alreadyExisted: true,+});diff --git a/packages/install-whisper-cpp/src/test/install-whisper-cpp.test.ts b/packages/install-whisper-cpp/src/test/install-whisper-cpp.test.tsindex 65b5e1efb1..7e924a27e6 100644--- a/packages/install-whisper-cpp/src/test/install-whisper-cpp.test.ts+++ b/packages/install-whisper-cpp/src/test/install-whisper-cpp.test.ts@@ -1,14 +1,13 @@-import {expect, spyOn, test} from 'bun:test';+import {expect, test} from 'bun:test';+import {execFileSync} from 'child_process';import {existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync} from 'fs';import os from 'os';import path from 'path';-import {installWhisperCpp} from '../install-whisper-cpp';test.skipIf(process.platform !== 'win32')('installs Whisper in Windows paths containing spaces and PowerShell characters',- async () => {+ () => {const root = mkdtempSync(path.join(os.tmpdir(), 'remotion-whisper-'));- const previousCwd = process.cwd();const project = path.join(root,"NodeJs Projects [1] $value & 'quote' `tick`",@@ -19,31 +18,24 @@ test.skipIf(process.platform !== 'win32')('whisper.cpp',);const executableContents = 'Whisper executable fixture';- const fetchSpy = spyOn(globalThis, 'fetch');try {mkdirSync(project);- const zip = readFileSync(path.join(__dirname, 'fixtures', 'whisper.zip'));- fetchSpy.mockResolvedValue(- new Response(new Uint8Array(zip).buffer, {- headers: {'content-length': String(zip.length)},- }),+ execFileSync(+ 'node',+ [+ path.join(__dirname, 'fixtures', 'install-whisper.mjs'),+ path.resolve(__dirname, '../../dist/install-whisper-cpp.js'),+ path.join(__dirname, 'fixtures', 'whisper.zip'),+ to,+ ],+ {cwd: project, stdio: 'inherit', timeout: 30_000},);- process.chdir(project);-- expect(- await installWhisperCpp({to, version: '1.5.5', printOutput: true}),- ).toEqual({alreadyExisted: false});expect(readFileSync(path.join(to, 'main.exe'), 'utf8')).toBe(executableContents,);expect(existsSync(path.join(project, 'whisper-bin-x64.zip'))).toBe(false);- expect(- await installWhisperCpp({to, version: '1.5.5', printOutput: false}),- ).toEqual({alreadyExisted: true});} finally {- fetchSpy.mockRestore();- process.chdir(previousCwd);rmSync(root, {recursive: true, force: true});}},