Skip to content

Support hooks in the NestJS app setup #30

Description

@jonnydgreen

Is your feature request related to a problem? Please describe.

Support more setup options in the NestJS app setup

Describe the solution you'd like

export function setupApp(
  app: INestApplication,
  logLevel: Logger.LogLevel = Logger.FATAL,
): void {
  app.enableVersioning({
    type: VersioningType.URI,
    defaultVersion: "1alpha1",
  });

  // Turn off the logger
  const logger = app.get(Logger);
  logger.level(logLevel);

  app.use(bodyParser.json({ limit: "1mb" }));

  app.useGlobalPipes(
    new ValidationPipe({
      transform: true,
      exceptionFactory: (errors: ValidationError[]) =>
        new UnprocessableEntityException(
          errors.map((e) => Object.values(e.constraints ?? {})).flat(),
        ),
    }),
  );
}

What we want:

describe("Describe", () => {
  let teardownTests: SetupTestsTeardown;
  let url: URL;

  beforeEach(async () => {
    const result = await setupTests({
      server: {
        appModule: AppModule,
        // Hook definitions here
      },
    });
    teardownTests = result.teardownTests;
    url = new URL("/v1alpha1/pathways", result.outputs.server.output.origin);
  });

  afterEach(async () => {
    await teardownTests();
  });

  // ....
});

Describe alternatives you've considered

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions