Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(adapters): improved adapters loading logic to have clear error me…
…ssages; (#5919)
- Loading branch information
1 parent
bc9af51
commit e410779
Showing
3 changed files
with
82 additions
and
16 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
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
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,48 @@ | ||
import adapters from '../../../lib/adapters/adapters.js'; | ||
import assert from 'assert'; | ||
|
||
|
||
describe('adapters', function () { | ||
const store = {...adapters.adapters}; | ||
|
||
beforeEach(() => { | ||
Object.keys(adapters.adapters).forEach((name) => { | ||
delete adapters.adapters[name]; | ||
}); | ||
|
||
Object.assign(adapters.adapters, store); | ||
}); | ||
|
||
it('should support loading by fn handle', function () { | ||
const adapter = () => {}; | ||
assert.strictEqual(adapters.getAdapter(adapter), adapter); | ||
}); | ||
|
||
it('should support loading by name', function () { | ||
const adapter = () => {}; | ||
adapters.adapters['testadapter'] = adapter; | ||
assert.strictEqual(adapters.getAdapter('testAdapter'), adapter); | ||
}); | ||
|
||
it('should detect adapter unavailable status', function () { | ||
adapters.adapters['testadapter'] = null; | ||
assert.throws(()=> adapters.getAdapter('testAdapter'), /is not available in the build/) | ||
}); | ||
|
||
it('should detect adapter unsupported status', function () { | ||
adapters.adapters['testadapter'] = false; | ||
assert.throws(()=> adapters.getAdapter('testAdapter'), /is not supported by the environment/) | ||
}); | ||
|
||
it('should pick suitable adapter from the list', function () { | ||
const adapter = () => {}; | ||
|
||
Object.assign(adapters.adapters, { | ||
foo: false, | ||
bar: null, | ||
baz: adapter | ||
}); | ||
|
||
assert.strictEqual(adapters.getAdapter(['foo', 'bar', 'baz']), adapter); | ||
}); | ||
}); |