Add comprehensive unit tests for DiscoveryService which previously
had no test coverage despite being a public API.
Test coverage includes:
- createDecorator() static method with unique key generation
- getProviders() with metadataKey and include options filtering
- getControllers() with module-based filtering
- getMetadataByDecorator() with method and class metadata
- getModules() protected method with include filtering
- Edge cases: empty modules, undefined instances, null checks
Total: 30+ test cases covering all public methods and edge cases.
When forwardRef provider fails to load in a non-static context
(REQUEST/TRANSIENT scope, the error was silently swallowed because the
promise was fire-and-forget without catch handler
This fix add catch handler that propagate the error through
ettlementSignal, ensuring proper error handling and preventing unhandled
promise rejection
Improve test coverage for discoverable-meta-host-collection.ts
from 38.46% to 100% by adding comprehensive unit tests for:
- addClassMetaHostLink
- insertByMetaKey
- getProvidersByMetaKey / getControllersByMetaKey
- inspectProvider / inspectController
- useValue and useFactory provider scenarios
When resolving multiple default-scoped providers registered under the same
token using `moduleRef.resolve(token, undefined, { each: true })`, the method
was returning the same instance repeated N times instead of all distinct
provider instances.
The issue was in `resolvePerContext` where for static dependency trees it
called `this.get()` which always returned the last registered provider,
ignoring the specific `instanceLink` being processed. Now it returns
`wrapperRef.instance` directly from each instance link.
Closes#15979
Treat non-static dependency trees as scoped in get(); instruct consumers to use resolve().\n\nAdds focused tests under NestApplicationContext spec to cover implicit request scope via enhancers.\n\nCloses #15836.
Adds support for returning Promise<Observable<MessageEvent>> from SSE
handlers, enabling async validation before sending HTTP headers.
This allows developers to:
- Perform async validation before establishing SSE connection
- Return custom HTTP status codes (404, 401, etc.)
- Set headers based on async data
- Implement proper resource validation patterns
Implementation details:
- RouterResponseController.sse() now accepts Promise<Observable>
- Custom status codes extracted from response.statusCode
- SseStream.pipe() accepts optional statusCode parameter
- Full backward compatibility maintained
Fixes#12260
Fix race condition in class dependency resolution, which could otherwise
lead to undefined or null injection. This is a followup to #15405 that
fixes another case of this bug that was not taken care of in the
previous PR. In this case specifically, the staticity of the dependency
tree could be checked before all dependencies are loaded and the param /
property Barrier is passed, resulting in a potentially wrong evaluation
of the `isTreeStatic` property of the `InstanceWrapper`.
Closes#4873