Add test
This commit is contained in:
6
tests/.eslintrc
Normal file
6
tests/.eslintrc
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"rules": {
|
||||
"no-undef": 0,
|
||||
"camelcase": 0
|
||||
}
|
||||
}
|
||||
18
tests/constants.js
Normal file
18
tests/constants.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const TIMEOUT = 30000;
|
||||
const BASE_URL = 'http://localhost:3000/tests/assets';
|
||||
const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
||||
const OPTIONS = {
|
||||
corePath: '../node_modules/@ffmpeg/core/ffmpeg-core.js',
|
||||
...(IS_BROWSER ? { workerPath: '../dist/worker.dev.js' } : {}),
|
||||
};
|
||||
const FLAME_MP4_LENGTH = 100374;
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = {
|
||||
TIMEOUT,
|
||||
BASE_URL,
|
||||
IS_BROWSER,
|
||||
OPTIONS,
|
||||
FLAME_MP4_LENGTH,
|
||||
};
|
||||
}
|
||||
20
tests/ffmpeg.test.html
Normal file
20
tests/ffmpeg.test.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>FFmpeg Unit Test</title>
|
||||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="../node_modules/mocha/mocha.js"></script>
|
||||
<script src="../node_modules/expect.js/index.js"></script>
|
||||
<script src="../dist/ffmpeg.dev.js"></script>
|
||||
<script src="./constants.js"></script>
|
||||
<script>mocha.setup('bdd');</script>
|
||||
<script src="./ffmpeg.test.js"></script>
|
||||
<script>
|
||||
mocha.run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
22
tests/ffmpeg.test.js
Normal file
22
tests/ffmpeg.test.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const { createWorker } = FFmpeg;
|
||||
const worker = createWorker(OPTIONS);
|
||||
|
||||
before(async function cb() {
|
||||
this.timeout(0);
|
||||
await worker.load();
|
||||
});
|
||||
|
||||
describe('transcode()', () => {
|
||||
describe('should transcode different format', () => {
|
||||
['flame.avi'].forEach((name) => (
|
||||
it(`transcode ${name}`, async () => {
|
||||
await worker.write(name, `${BASE_URL}/${name}`);
|
||||
await worker.transcode(name, 'output.mp4');
|
||||
await worker.remove(name);
|
||||
const { data } = await worker.read('output.mp4');
|
||||
await worker.remove('output.mp4');
|
||||
expect(data.length).to.be(FLAME_MP4_LENGTH);
|
||||
}).timeout(TIMEOUT)
|
||||
));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user