Commit 4c807f78 authored by Jerome Wu's avatar Jerome Wu

Setup basic jest environment

parent ed509d24
......@@ -4,7 +4,7 @@
"description": "ffmpeg.wasm core",
"main": "dist/ffmpeg-core.js",
"scripts": {
"test": "jest"
"test": "node --experimental-wasm-threads --experimental-wasm-bulk-memory ./node_modules/.bin/jest"
},
"repository": {
"type": "git",
......
const {
initModule,
parseArgs,
} = require('./utils');
let Module = null;
let ffmpeg = null;
beforeAll(async () => {
Module = await initModule();
ffmpeg = Module.cwrap('proxy_main', 'number', ['number', 'number']);
});
test('test', () => {
const ret = ffmpeg(...parseArgs(['ffmpeg', '-v']));
expect(ret).toBe(0);
});
let Module = null;
exports.initModule = () => (
new Promise((resolve) => {
const _Module = require('../dist/ffmpeg-core.js');
_Module.onRuntimeInitialized = () => {
Module = _Module;
resolve(Module);
}
})
);
exports.parseArgs = (args) => {
const argsPtr = Module._malloc(args.length * Uint32Array.BYTES_PER_ELEMENT);
args.forEach((s, idx) => {
const buf = Module._malloc(s.length + 1);
Module.writeAsciiToMemory(s, buf);
Module.setValue(argsPtr + (Uint32Array.BYTES_PER_ELEMENT * idx), buf, 'i32');
});
return [args.length, argsPtr];
};
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