Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions scripts/test-camera-capture-single-encode.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env node

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const cameraExtensionPath = path.join(root, 'src/renderer/src/CameraExtension.tsx');
const mainPath = path.join(root, 'src/main/main.ts');

test('Camera capture save path avoids redundant mkdir subprocess', async (t) => {
await t.test('camera capture writes image bytes without shelling out for mkdir', () => {
const source = fs.readFileSync(cameraExtensionPath, 'utf8');

assert.ok(!source.includes('/bin/mkdir'));
assert.ok(!source.includes("['-p', saveDir]"));
assert.ok(source.includes('const saveDir = homeDir ? `${homeDir}/Pictures/SuperCmd Captures` : \'/tmp/SuperCmd Captures\';'));
assert.ok(source.includes('const savePath = `${saveDir}/supercmd-capture-${timestamp}.png`;'));
assert.ok(source.includes('const bytes = new Uint8Array(await captureBlob.arrayBuffer());'));
assert.ok(source.includes('await window.electron.fsWriteBinaryFile(savePath, bytes);'));
});

await t.test('fsWriteBinaryFile IPC creates parent directories recursively', () => {
const source = fs.readFileSync(mainPath, 'utf8');
const mkdirLine = 'await fs.promises.mkdir(nodePath.dirname(filePath), { recursive: true });';
const writeLine = 'await fs.promises.writeFile(filePath, Buffer.from(data));';

assert.ok(source.includes("ipcMain.handle('fs-write-binary-file'"));
assert.ok(source.includes(mkdirLine));
assert.ok(source.includes(writeLine));
assert.ok(source.indexOf(mkdirLine) < source.indexOf(writeLine));
});
});
1 change: 0 additions & 1 deletion src/renderer/src/CameraExtension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ const CameraExtension: React.FC<CameraExtensionProps> = ({ onClose }) => {
let savedToDisk = false;
if (captureBlob) {
try {
await window.electron.execCommand('/bin/mkdir', ['-p', saveDir], {});
const bytes = new Uint8Array(await captureBlob.arrayBuffer());
await window.electron.fsWriteBinaryFile(savePath, bytes);
savedToDisk = true;
Expand Down
Loading