Skip to content

Commit

Permalink
Update: Add test for only-errors prepare() with nothrow option
Browse files Browse the repository at this point in the history
  • Loading branch information
jmm authored and phated committed Jan 4, 2019
1 parent 4b67fcf commit 5f6c40d
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ describe('rechoir', function () {
}).to.throw;
});

it('should include errors for each module loader that was attempted if they failed to load', function () {
try {
rechoir.prepare({
'.coffee': [
'nothere',
'orhere'
]
}, testFilePath);
} catch (e) {
describe('all module loaders that were attempted failed to load', function () {
var exts = {
'.coffee': [
'nothere',
'orhere'
]
};

// Check the failure entries in the thrown or returned error object.
function check_failures (e) {
expect(e.failures).to.be.an('array');
expect(e.failures[0].error).to.be.instanceof(Error);
expect(e.failures[0].moduleName).to.equal('nothere');
Expand All @@ -69,6 +70,23 @@ describe('rechoir', function () {
expect(e.failures[1].moduleName).to.equal('orhere');
expect(e.failures[1].module).to.be.null;
}

it('should throw error listing each module loader that was attempted when nothrow = false', function () {
var err;
try {
rechoir.prepare(exts, testFilePath);
} catch (e) {
err = e;
check_failures(e);
}
expect(err).to.be.instanceof(Error);
});

it('should return error listing each module loader that was attempted when nothrow = true', function () {
check_failures(
rechoir.prepare(exts, testFilePath, null, true)
);
});
});

it('should register a module loader for the specified extension', function () {
Expand Down

0 comments on commit 5f6c40d

Please sign in to comment.