Skip to content

Commit

Permalink
refactor: pick only one option attribute for test module
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jan 20, 2025
2 parents 0996b7d + 65cfe0c commit 0545020
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 9 additions & 3 deletions packages/testing/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { ModuleMetadata } from '@nestjs/common/interfaces/modules/module-metadata.interface';
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
import { TestingModuleBuilder } from './testing-module.builder';
import {
TestingModuleBuilder,
TestingModuleOptions,
} from './testing-module.builder';

export class Test {
private static readonly metadataScanner = new MetadataScanner();

public static createTestingModule(metadata: ModuleMetadata) {
return new TestingModuleBuilder(this.metadataScanner, metadata);
public static createTestingModule(
metadata: ModuleMetadata,
options?: TestingModuleOptions,
) {
return new TestingModuleBuilder(this.metadataScanner, metadata, options);
}
}
12 changes: 11 additions & 1 deletion packages/testing/testing-module.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ import { TestingInjector } from './testing-injector';
import { TestingInstanceLoader } from './testing-instance-loader';
import { TestingModule } from './testing-module';

/**
* @publicApi
*/
export type TestingModuleOptions = Pick<
NestApplicationContextOptions,
'moduleIdGeneratorAlgorithm'
>;

/**
* @publicApi
*/
export class TestingModuleBuilder {
private readonly applicationConfig = new ApplicationConfig();
private readonly container = new NestContainer(this.applicationConfig);
private readonly container: NestContainer;
private readonly overloadsMap = new Map();
private readonly moduleOverloadsMap = new Map<
ModuleDefinition,
Expand All @@ -41,7 +49,9 @@ export class TestingModuleBuilder {
constructor(
private readonly metadataScanner: MetadataScanner,
metadata: ModuleMetadata,
options?: TestingModuleOptions,
) {
this.container = new NestContainer(this.applicationConfig, options);
this.module = this.createModule(metadata);
}

Expand Down

0 comments on commit 0545020

Please sign in to comment.