Commit cc8a08ed authored by Jerome Wu's avatar Jerome Wu

Add exit unit test

parent 3df24c56
const fs = require('fs');
const path = require('path');
const { TIMEOUT } = require('./config');
const { runFFmpeg } = require('./utils');
const IN_FILE_NAME = 'video-1s.avi';
const OUT_FILE_NAME = 'video.mp4';
const FILE_SIZE = 38372;
let aviData = null;
beforeAll(() => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
test('transcode avi to x264 mp4 with exit', async () => {
const processExit = process.exit;
global.process.exit = jest.fn();
const args = ['-i', IN_FILE_NAME, OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME, [], [], 1000);
expect(fileSize).not.toBe(FILE_SIZE);
global.process.exit = processExit;
}, TIMEOUT);
...@@ -19,7 +19,7 @@ const ffmpeg = (Core, args) => { ...@@ -19,7 +19,7 @@ const ffmpeg = (Core, args) => {
); );
}; };
const runFFmpeg = async (ifilename, data, args, ofilename, extraFiles = [], extraFolders = []) => { const runFFmpeg = async (ifilename, data, args, ofilename, extraFiles = [], extraFolders = [], msBeforeExit = -1) => {
let resolve = null; let resolve = null;
let file = null; let file = null;
let fileSize = -1; let fileSize = -1;
...@@ -39,6 +39,12 @@ const runFFmpeg = async (ifilename, data, args, ofilename, extraFiles = [], extr ...@@ -39,6 +39,12 @@ const runFFmpeg = async (ifilename, data, args, ofilename, extraFiles = [], extr
}); });
Core.FS.writeFile(ifilename, data); Core.FS.writeFile(ifilename, data);
ffmpeg(Core, args); ffmpeg(Core, args);
if (msBeforeExit !== -1) {
setTimeout(() => {
Core.exit();
resolve();
}, msBeforeExit);
}
await new Promise((_resolve) => { resolve = _resolve }); await new Promise((_resolve) => { resolve = _resolve });
if (typeof ofilename !== 'undefined') { if (typeof ofilename !== 'undefined') {
file = Core.FS.readFile(ofilename); file = Core.FS.readFile(ofilename);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment