Skip to content

Commit

Permalink
Fix wrong used .reverse that caused the resolver order to change
Browse files Browse the repository at this point in the history
  • Loading branch information
luxzeitlos committed Feb 21, 2018
1 parent 7e9d96a commit 0343094
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/metal/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class Container {
let registrations = Object.keys(this.registry).filter((specifier) => {
return specifier.startsWith(type);
});
let resolved = this.resolvers.reverse().reduce((entries, resolver) => {
let resolved = [...this.resolvers].reverse().reduce((entries, resolver) => {
return entries.concat(resolver.availableForType(type));
}, []);
return uniq(registrations.concat(resolved)).map((specifier) => specifier.split(':')[1]);
Expand Down
18 changes: 18 additions & 0 deletions test/unit/metal/container-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,22 @@ test('availableForType() returns all registered instances of a type', async (t)
t.deepEqual(container.availableForType('foo'), ['a', 'b', 'c', 'd']);
});

test('the resolver order should not be changed by lookup methods', async (t) => {
const container: Container = t.context.subject();

const loaderMock = (name : string) => ({
retrieve: () => name,
loadRelative: () => name,
factories: new Map(),
}) as any;

container.loadBundleScope(loaderMock('l1'));
container.loadBundleScope(loaderMock('l2'));

t.deepEqual(container.lookup('foo:l1', { raw: true }), 'l1');
container.availableForType('foo');
t.deepEqual(container.lookup('foo:l1', { raw: true }), 'l1');
t.deepEqual(container.lookup('foo:l1', { raw: true }), 'l1');
});

test.todo('fallsback to `fallbacks` specifiers if original specifier is not found');

0 comments on commit 0343094

Please sign in to comment.