Refactor tests
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
@ -1,8 +1,7 @@
|
|||||||
const TIMEOUT = 60000;
|
const TIMEOUT = 60000;
|
||||||
const BASE_URL = 'http://localhost:3000/tests/assets';
|
|
||||||
const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
||||||
const OPTIONS = {
|
const OPTIONS = {
|
||||||
corePath: 'http://localhost:3000/node_modules/@ffmpeg/core/ffmpeg-core.js',
|
corePath: IS_BROWSER ? 'http://localhost:3000/node_modules/@ffmpeg/core/dist/ffmpeg-core.js' : '@ffmpeg/core',
|
||||||
};
|
};
|
||||||
const FLAME_MP4_LENGTH = 100374;
|
const FLAME_MP4_LENGTH = 100374;
|
||||||
const META_FLAME_MP4_LENGTH = 100408;
|
const META_FLAME_MP4_LENGTH = 100408;
|
||||||
@ -11,7 +10,6 @@ const META_FLAME_MP4_LENGTH_NO_SPACE = 100404;
|
|||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
TIMEOUT,
|
TIMEOUT,
|
||||||
BASE_URL,
|
|
||||||
IS_BROWSER,
|
IS_BROWSER,
|
||||||
OPTIONS,
|
OPTIONS,
|
||||||
FLAME_MP4_LENGTH,
|
FLAME_MP4_LENGTH,
|
||||||
|
@ -8,12 +8,13 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="mocha"></div>
|
<div id="mocha"></div>
|
||||||
<script src="../node_modules/mocha/mocha.js"></script>
|
<script src="../node_modules/mocha/mocha.js"></script>
|
||||||
<script src="../node_modules/expect.js/index.js"></script>
|
<script src="../node_modules/chai/chai.js"></script>
|
||||||
<script src="../dist/ffmpeg.dev.js"></script>
|
<script src="../dist/ffmpeg.dev.js"></script>
|
||||||
<script src="./constants.js"></script>
|
<script src="./constants.js"></script>
|
||||||
<script>mocha.setup('bdd');</script>
|
<script>mocha.setup('bdd');</script>
|
||||||
<script src="./ffmpeg.test.js"></script>
|
<script src="./ffmpeg.test.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
window.expect = chai.expect;
|
||||||
mocha.run();
|
mocha.run();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -1,62 +1,60 @@
|
|||||||
const { createFFmpeg } = FFmpeg;
|
const { createFFmpeg } = FFmpeg;
|
||||||
const ffmpeg = createFFmpeg(OPTIONS);
|
|
||||||
|
|
||||||
before(async function cb() {
|
describe('load()', () => {
|
||||||
this.timeout(0);
|
it('should throw error when not called before FS() and run()', () => {
|
||||||
await ffmpeg.load();
|
const ffmpeg = createFFmpeg(OPTIONS);
|
||||||
|
expect(() => ffmpeg.FS('readdir', 'dummy')).to.throw();
|
||||||
|
expect(() => ffmpeg.run('-h')).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw error when running load() more than once', async () => {
|
||||||
|
const ffmpeg = createFFmpeg(OPTIONS);
|
||||||
|
await ffmpeg.load();
|
||||||
|
try {
|
||||||
|
await ffmpeg.load();
|
||||||
|
} catch (e) {
|
||||||
|
expect(e).to.be.an('Error');
|
||||||
|
}
|
||||||
|
}).timeout(TIMEOUT);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('transcode()', () => {
|
describe('isLoaded()', () => {
|
||||||
describe('should transcode different format', () => {
|
it('should return true when loaded', async () => {
|
||||||
[1, 2, 4].forEach((n) => {
|
const ffmpeg = createFFmpeg(OPTIONS);
|
||||||
[
|
await ffmpeg.load();
|
||||||
{ from: 'flame.avi', to: 'flame.mp4' },
|
expect(ffmpeg.isLoaded()).to.equal(true);
|
||||||
{ from: 'flame.avi', to: 'flame.webm' },
|
}).timeout(TIMEOUT);
|
||||||
{ from: 'StarWars3.wav', to: 'StarWars3.mp3' },
|
|
||||||
].forEach(({ from, to }) => (
|
|
||||||
it(`transcode ${from} to ${to} (${n} threads)`, async () => {
|
|
||||||
await ffmpeg.write(from, `${BASE_URL}/${from}`);
|
|
||||||
await ffmpeg.transcode(from, to, `-threads ${n}`);
|
|
||||||
const data = ffmpeg.read(to);
|
|
||||||
ffmpeg.remove(to);
|
|
||||||
expect(data.length).not.to.be(0);
|
|
||||||
}).timeout(TIMEOUT)
|
|
||||||
));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('run()', () => {
|
describe('run()', () => {
|
||||||
describe('should run a command with quoted parameters at start no spaces', () => {
|
it('should not allow to run two command at the same time', async () => {
|
||||||
['flame.avi'].forEach((name) => (
|
const ffmpeg = createFFmpeg(OPTIONS);
|
||||||
it(`run ${name}`, async () => {
|
await ffmpeg.load();
|
||||||
await ffmpeg.write(name, `${BASE_URL}/${name}`);
|
ffmpeg.run('-h');
|
||||||
await ffmpeg.run(`-y -i ${name} -metadata 'title="test"' output.mp4`);
|
setTimeout(() => {
|
||||||
const data = ffmpeg.read('output.mp4');
|
try {
|
||||||
expect(data.length).to.be(META_FLAME_MP4_LENGTH_NO_SPACE);
|
ffmpeg.run('-h');
|
||||||
}).timeout(TIMEOUT)
|
} catch (e) {
|
||||||
));
|
expect(e).to.be.an(Error);
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}).timeout(TIMEOUT);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('FS()', () => {
|
||||||
|
const ffmpeg = createFFmpeg(OPTIONS);
|
||||||
|
before(async function cb() {
|
||||||
|
this.timeout(0);
|
||||||
|
await ffmpeg.load();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should run a command with quoted parameters at start and a space in between', () => {
|
it('should throw error when readdir for invalid path ', () => {
|
||||||
['flame.avi'].forEach((name) => (
|
expect(() => ffmpeg.FS('readdir', '/invalid')).to.throw(/readdir/);
|
||||||
it(`run ${name}`, async () => {
|
|
||||||
await ffmpeg.write(name, `${BASE_URL}/${name}`);
|
|
||||||
await ffmpeg.run(`-y -i ${name} -metadata 'title="my title"' output.mp4`);
|
|
||||||
const data = ffmpeg.read('output.mp4');
|
|
||||||
expect(data.length).to.be(META_FLAME_MP4_LENGTH);
|
|
||||||
}).timeout(TIMEOUT)
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
|
it('should throw error when readFile for invalid path ', () => {
|
||||||
describe('should run a command with name quoted parameters and a space in between', () => {
|
expect(() => ffmpeg.FS('readFile', '/invalid')).to.throw(/readFile/);
|
||||||
['flame.avi'].forEach((name) => (
|
});
|
||||||
it(`run ${name}`, async () => {
|
it('should throw an default error ', () => {
|
||||||
await ffmpeg.write(name, `${BASE_URL}/${name}`);
|
expect(() => ffmpeg.FS('unlink', '/invalid')).to.throw(/Oops/);
|
||||||
await ffmpeg.run(`-y -i ${name} -metadata title="my title" output.mp4`);
|
|
||||||
const data = ffmpeg.read('output.mp4');
|
|
||||||
expect(data.length).to.be(META_FLAME_MP4_LENGTH);
|
|
||||||
}).timeout(TIMEOUT)
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|