Refactor tests

This commit is contained in:
Jerome Wu
2020-11-03 15:37:45 +08:00
parent 265cf4c580
commit 848f8ed21e
66 changed files with 51 additions and 54 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -1,8 +1,7 @@
const TIMEOUT = 60000;
const BASE_URL = 'http://localhost:3000/tests/assets';
const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
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 META_FLAME_MP4_LENGTH = 100408;
@@ -11,7 +10,6 @@ const META_FLAME_MP4_LENGTH_NO_SPACE = 100404;
if (typeof module !== 'undefined') {
module.exports = {
TIMEOUT,
BASE_URL,
IS_BROWSER,
OPTIONS,
FLAME_MP4_LENGTH,

View File

@@ -8,12 +8,13 @@
<body>
<div id="mocha"></div>
<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="./constants.js"></script>
<script>mocha.setup('bdd');</script>
<script src="./ffmpeg.test.js"></script>
<script>
window.expect = chai.expect;
mocha.run();
</script>
</body>

View File

@@ -1,62 +1,60 @@
const { createFFmpeg } = FFmpeg;
const ffmpeg = createFFmpeg(OPTIONS);
before(async function cb() {
this.timeout(0);
await ffmpeg.load();
describe('load()', () => {
it('should throw error when not called before FS() and run()', () => {
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('should transcode different format', () => {
[1, 2, 4].forEach((n) => {
[
{ from: 'flame.avi', to: 'flame.mp4' },
{ from: 'flame.avi', to: 'flame.webm' },
{ 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('isLoaded()', () => {
it('should return true when loaded', async () => {
const ffmpeg = createFFmpeg(OPTIONS);
await ffmpeg.load();
expect(ffmpeg.isLoaded()).to.equal(true);
}).timeout(TIMEOUT);
});
describe('run()', () => {
describe('should run a command with quoted parameters at start no spaces', () => {
['flame.avi'].forEach((name) => (
it(`run ${name}`, async () => {
await ffmpeg.write(name, `${BASE_URL}/${name}`);
await ffmpeg.run(`-y -i ${name} -metadata 'title="test"' output.mp4`);
const data = ffmpeg.read('output.mp4');
expect(data.length).to.be(META_FLAME_MP4_LENGTH_NO_SPACE);
}).timeout(TIMEOUT)
));
it('should not allow to run two command at the same time', async () => {
const ffmpeg = createFFmpeg(OPTIONS);
await ffmpeg.load();
ffmpeg.run('-h');
setTimeout(() => {
try {
ffmpeg.run('-h');
} 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', () => {
['flame.avi'].forEach((name) => (
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 readdir for invalid path ', () => {
expect(() => ffmpeg.FS('readdir', '/invalid')).to.throw(/readdir/);
});
describe('should run a command with name quoted parameters and a space in between', () => {
['flame.avi'].forEach((name) => (
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 ', () => {
expect(() => ffmpeg.FS('readFile', '/invalid')).to.throw(/readFile/);
});
it('should throw an default error ', () => {
expect(() => ffmpeg.FS('unlink', '/invalid')).to.throw(/Oops/);
});
});