-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#117 Add unit-tests covering lazy-loading
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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".'); | ||
}); | ||
}); | ||
|
||
}); |