Skip to content

Commit

Permalink
Merge pull request #10072 from micalevisk/fix/issue-9893
Browse files Browse the repository at this point in the history
fix(core): when debug-repl has duplicated providers
  • Loading branch information
kamilmysliwiec authored Aug 11, 2022
2 parents d8b1a3a + 4261a20 commit 583e52b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
8 changes: 4 additions & 4 deletions integration/repl/e2e/repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ${PROMPT}`,
${PROMPT}`);

outputText = '';
server.emit('line', 'get(UsersRepository)');
server.emit('line', 'get("UsersRepository")');

expect(outputText).to.equal(`UsersRepository {}
${PROMPT}`);
Expand Down Expand Up @@ -81,7 +81,7 @@ ${PROMPT}`,
${PROMPT}`);

outputText = '';
server.emit('line', '$(UsersRepository)');
server.emit('line', '$("UsersRepository")');

expect(outputText).to.equal(`UsersRepository {}
${PROMPT}`);
Expand All @@ -104,7 +104,7 @@ UsersModule:
◻ UsersController
- providers:
◻ UsersService
◻ UsersRepository
"UsersRepository"
${PROMPT}`,
);
Expand All @@ -118,7 +118,7 @@ ${PROMPT}`,
outputText += text;
return true;
});
server.emit('line', 'methods(UsersRepository)');
server.emit('line', 'methods("UsersRepository")');

expect(outputText).to.equal(
`
Expand Down
21 changes: 12 additions & 9 deletions packages/core/repl/repl-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,24 @@ export class ReplContext {
const stringifiedToken = this.stringifyToken(token);
if (
stringifiedToken === ApplicationConfig.name ||
stringifiedToken === moduleRef.metatype.name ||
this.globalScope[stringifiedToken]
stringifiedToken === moduleRef.metatype.name
) {
return;
}
// For in REPL auto-complete functionality
Object.defineProperty(this.globalScope, stringifiedToken, {
value: token,
configurable: false,
enumerable: true,
});

if (!this.globalScope[stringifiedToken]) {
// For in REPL auto-complete functionality
Object.defineProperty(this.globalScope, stringifiedToken, {
value: token,
configurable: false,
enumerable: true,
});
}

if (stringifiedToken === ModuleRef.name) {
return;
}

moduleDebugEntry[stringifiedToken] = token;
});

Expand All @@ -109,7 +112,7 @@ export class ReplContext {
? typeof token === 'function'
? token.name
: token?.toString()
: token;
: `"${token}"`;
}

private addNativeFunction(
Expand Down
13 changes: 13 additions & 0 deletions packages/core/test/repl/native-functions/debug-repl-fn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ describe('DebugReplFn', () => {
container.addController(class ControllerA {}, aModuleRef.token);
container.addProvider(class ProviderA1 {}, aModuleRef.token);
container.addProvider(class ProviderA2 {}, aModuleRef.token);
container.addProvider(class SharedProvider {}, aModuleRef.token);
container.addProvider(
{ provide: 'StringToken', useValue: 123 },
aModuleRef.token,
);

container.addProvider(class ProviderB1 {}, bModuleRef.token);
container.addProvider(class ProviderB2 {}, bModuleRef.token);
container.addProvider(class SharedProvider {}, bModuleRef.token);

mockApp = {
container,
Expand Down Expand Up @@ -68,10 +74,13 @@ ModuleA:
- providers:
◻ ProviderA1
◻ ProviderA2
◻ SharedProvider
◻ "StringToken"
ModuleB:
- providers:
◻ ProviderB1
◻ ProviderB2
◻ SharedProvider
`);
});
Expand All @@ -93,6 +102,8 @@ ModuleA:
- providers:
◻ ProviderA1
◻ ProviderA2
◻ SharedProvider
◻ "StringToken"
`);
});
Expand All @@ -114,6 +125,8 @@ ModuleA:
- providers:
◻ ProviderA1
◻ ProviderA2
◻ SharedProvider
◻ "StringToken"
`);
});
Expand Down

0 comments on commit 583e52b

Please sign in to comment.