mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-23 09:33:01 +03:00
fix: e2e record.ts
cleanup (#4696)
This commit is contained in:
parent
7dc829960a
commit
4aceb459a3
@ -1,19 +1,7 @@
|
||||
import path from 'node:path';
|
||||
import { spawn, type ChildProcessWithoutNullStreams } from 'child_process';
|
||||
import path from 'node:path';
|
||||
import type { Frameworks } from '@wdio/types';
|
||||
|
||||
function filePath({
|
||||
test,
|
||||
videoPath,
|
||||
extension
|
||||
}: {
|
||||
test: Frameworks.Test;
|
||||
videoPath: string;
|
||||
extension: string;
|
||||
}) {
|
||||
return path.join(videoPath, `${fileName(test.parent)}-${fileName(test.title)}.${extension}`);
|
||||
}
|
||||
|
||||
function fileName(title: string) {
|
||||
return encodeURIComponent(title.trim().replace(/\s+/g, '-'));
|
||||
}
|
||||
@ -28,38 +16,37 @@ export class TestRecorder {
|
||||
}
|
||||
|
||||
start(test: Frameworks.Test, videoPath: string) {
|
||||
if (!videoPath) {
|
||||
throw new Error('Video path not set. Set using setPath() function.');
|
||||
if (!videoPath || !test) {
|
||||
throw new Error('Cannot start recording without a test and path for the video file.');
|
||||
}
|
||||
|
||||
if (process.env.DISPLAY && process.env.DISPLAY.startsWith(':')) {
|
||||
const parsedPath = filePath({
|
||||
test,
|
||||
const parsedPath = path.join(
|
||||
videoPath,
|
||||
extension: 'mp4'
|
||||
});
|
||||
`${fileName(test.parent)}-${fileName(test.title)}.mp4`
|
||||
);
|
||||
|
||||
this.ffmpeg = spawn('ffmpeg', [
|
||||
'-f',
|
||||
'x11grab', // Grab the X11 display
|
||||
'x11grab',
|
||||
'-video_size',
|
||||
'1280x1024', // Video size
|
||||
'1280x1024',
|
||||
'-i',
|
||||
process.env.DISPLAY, // Input file url
|
||||
process.env.DISPLAY,
|
||||
'-loglevel',
|
||||
'error', // Log only errors
|
||||
'-y', // Overwrite output files without asking
|
||||
'error',
|
||||
'-y',
|
||||
'-pix_fmt',
|
||||
'yuv420p', // QuickTime Player support, "Use -pix_fmt yuv420p for compatibility with outdated media players"
|
||||
parsedPath // Output file
|
||||
'yuv420p',
|
||||
parsedPath
|
||||
]);
|
||||
|
||||
const logBuffer = function (buffer: Buffer, prefix: string) {
|
||||
function logBuffer(buffer: Buffer, prefix: string) {
|
||||
const lines = buffer.toString().trim().split('\n');
|
||||
lines.forEach(function (line) {
|
||||
console.log(prefix + line);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
this.ffmpeg.stdout.on('data', (data: Buffer) => {
|
||||
logBuffer(data, '[ffmpeg:stdout] ');
|
||||
@ -69,11 +56,11 @@ export class TestRecorder {
|
||||
logBuffer(data, '[ffmpeg:error] ');
|
||||
});
|
||||
|
||||
this.ffmpeg.on('close', (code: number, signal: string | unknown) => {
|
||||
if (code !== null) {
|
||||
this.ffmpeg.on('close', (code?: number, signal?: string) => {
|
||||
if (code) {
|
||||
console.log(`[ffmpeg:stdout] exited with code ${code}: ${videoPath}`);
|
||||
}
|
||||
if (signal !== null) {
|
||||
if (signal) {
|
||||
console.log(`[ffmpeg:stdout] received signal ${signal}: ${videoPath}`);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user