Skip to content

Commit

Permalink
#117 Add unit-tests covering lazy-loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Jul 17, 2018
1 parent 45c41f6 commit b212cac
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/test-lazy-loading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as mm from '../src';
import * as path from "path";
import {assert} from "chai";
import {Promise} from "es6-promise";

describe("Lazy loading of format parser (ITokenParser", () => {

it("be able to override the loading method", () => {

const filePath = path.join(__dirname, "samples", "1971 - 003 - Sweet - Co-Co - CannaPower.mp2");

return mm.parseFile(filePath, {duration: true, native: true, loadParser: moduleName => {
assert.strictEqual(moduleName, 'mpeg');
const parserModule = require('../src/' + moduleName);
return Promise.resolve(new parserModule.default());
}
});
});

it("should throw an error if the parser cannot be loaded", () => {

const filePath = path.join(__dirname, "samples", "1971 - 003 - Sweet - Co-Co - CannaPower.mp2");

return mm.parseFile(filePath, {duration: true, native: true, loadParser: moduleName => {
assert.strictEqual(moduleName, 'mpeg');
return Promise.resolve(undefined);
}
}).then(() => {
assert.fail('Should throw an error');
}).catch(err => {
assert.strictEqual(err.message, 'options.loadParser failed to resolve module "mpeg".');
});
});

});

0 comments on commit b212cac

Please sign in to comment.