From b65c426d73f59aba304eb7096496d76fdec42e99 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 13 Apr 2023 20:40:52 +0530 Subject: [PATCH] fix: load test module based on env Signed-off-by: Pranav C --- packages/nocodb-nest/src/app.module.ts | 140 +++++++++++++------------ 1 file changed, 71 insertions(+), 69 deletions(-) diff --git a/packages/nocodb-nest/src/app.module.ts b/packages/nocodb-nest/src/app.module.ts index f830280de1..a70eda1fd5 100644 --- a/packages/nocodb-nest/src/app.module.ts +++ b/packages/nocodb-nest/src/app.module.ts @@ -1,69 +1,70 @@ -import { Module, RequestMethod } from '@nestjs/common'; -import { APP_FILTER, APP_GUARD } from '@nestjs/core'; -import { ExtractJwt } from 'passport-jwt'; -import { Connection } from './connection/connection'; -import { GlobalExceptionFilter } from './filters/global-exception/global-exception.filter'; -import { GlobalGuard } from './guards/global/global.guard'; -import { GlobalMiddleware } from './middlewares/global/global.middleware'; -import { AuthModule } from './modules/auth/auth.module'; -import { ExtractProjectIdMiddleware } from './middlewares/extract-project-id/extract-project-id.middleware'; -import { AuthService } from './modules/auth/auth.service'; -import { UsersModule } from './modules/users/users.module'; -import { MetaService } from './meta/meta.service'; -import { UsersService } from './modules/users/users.service'; -import { UtilsModule } from './modules/utils/utils.module'; -import { ProjectsModule } from './modules/projects/projects.module'; -import Noco from './Noco'; -import { JwtStrategy } from './strategies/jwt.strategy'; -import { TablesModule } from './modules/tables/tables.module'; -import { ViewsModule } from './modules/views/views.module'; -import { FiltersModule } from './modules/filters/filters.module'; -import { SortsModule } from './modules/sorts/sorts.module'; -import { ColumnsModule } from './modules/columns/columns.module'; -import { ViewColumnsModule } from './modules/view-columns/view-columns.module'; -import { BasesModule } from './modules/bases/bases.module'; -import { HooksModule } from './modules/hooks/hooks.module'; -import { SharedBasesModule } from './modules/shared-bases/shared-bases.module'; -import { FormsModule } from './modules/forms/forms.module'; -import { GridsModule } from './modules/grids/grids.module'; -import { KanbansModule } from './modules/kanbans/kanbans.module'; -import { GalleriesModule } from './modules/galleries/galleries.module'; -import { FormColumnsModule } from './modules/form-columns/form-columns.module'; -import { GridColumnsModule } from './modules/grid-columns/grid-columns.module'; -import { MapsModule } from './modules/maps/maps.module'; -import { ProjectUsersModule } from './modules/project-users/project-users.module'; -import { ModelVisibilitiesModule } from './modules/model-visibilities/model-visibilities.module'; -import { HookFiltersModule } from './modules/hook-filters/hook-filters.module'; -import { ApiTokensModule } from './modules/api-tokens/api-tokens.module'; -import { AttachmentsModule } from './modules/attachments/attachments.module'; -import { OrgLcenseModule } from './modules/org-lcense/org-lcense.module'; -import { OrgTokensModule } from './modules/org-tokens/org-tokens.module'; -import { OrgUsersModule } from './modules/org-users/org-users.module'; -import { MetaDiffsModule } from './modules/meta-diffs/meta-diffs.module'; -import { AuditsModule } from './modules/audits/audits.module'; -import { DatasModule } from './modules/datas/datas.module'; -import { ApiDocsModule } from './modules/api-docs/api-docs.module'; -import { PublicMetasModule } from './modules/public-metas/public-metas.module'; -import { PublicDatasModule } from './modules/public-datas/public-datas.module'; -import { PublicDatasExportModule } from './modules/public-datas-export/public-datas-export.module'; -import { SyncModule } from './modules/sync/sync.module'; -import { ImportModule } from './modules/import/import.module'; -import { CachesModule } from './modules/caches/caches.module'; -import { TestModule } from './modules/test/test.module'; -import { PluginsModule } from './modules/plugins/plugins.module'; -import { GlobalModule } from './modules/global/global.module'; -import { LocalStrategy } from './strategies/local.strategy'; -import NcConfigFactory from './utils/NcConfigFactory'; -import NcUpgrader from './version-upgrader/NcUpgrader'; -import { ClientService } from './services/client/client.service'; -import { AuthTokenStrategy } from './strategies/authtoken.strategy/authtoken.strategy'; -import { BaseViewStrategy } from './strategies/base-view.strategy/base-view.strategy'; -import { GoogleStrategy } from './strategies/google.strategy/google.strategy'; +import { Module, RequestMethod } from '@nestjs/common' +import { APP_FILTER, APP_GUARD } from '@nestjs/core' +import { ExtractJwt } from 'passport-jwt' +import { Connection } from './connection/connection' +import { GlobalExceptionFilter } from './filters/global-exception/global-exception.filter' +import { GlobalGuard } from './guards/global/global.guard' +import { GlobalMiddleware } from './middlewares/global/global.middleware' +import { AuthModule } from './modules/auth/auth.module' +import { ExtractProjectIdMiddleware } from './middlewares/extract-project-id/extract-project-id.middleware' +import { AuthService } from './modules/auth/auth.service' +import { UsersModule } from './modules/users/users.module' +import { MetaService } from './meta/meta.service' +import { UsersService } from './modules/users/users.service' +import { UtilsModule } from './modules/utils/utils.module' +import { ProjectsModule } from './modules/projects/projects.module' +import Noco from './Noco' +import { JwtStrategy } from './strategies/jwt.strategy' +import { TablesModule } from './modules/tables/tables.module' +import { ViewsModule } from './modules/views/views.module' +import { FiltersModule } from './modules/filters/filters.module' +import { SortsModule } from './modules/sorts/sorts.module' +import { ColumnsModule } from './modules/columns/columns.module' +import { ViewColumnsModule } from './modules/view-columns/view-columns.module' +import { BasesModule } from './modules/bases/bases.module' +import { HooksModule } from './modules/hooks/hooks.module' +import { SharedBasesModule } from './modules/shared-bases/shared-bases.module' +import { FormsModule } from './modules/forms/forms.module' +import { GridsModule } from './modules/grids/grids.module' +import { KanbansModule } from './modules/kanbans/kanbans.module' +import { GalleriesModule } from './modules/galleries/galleries.module' +import { FormColumnsModule } from './modules/form-columns/form-columns.module' +import { GridColumnsModule } from './modules/grid-columns/grid-columns.module' +import { MapsModule } from './modules/maps/maps.module' +import { ProjectUsersModule } from './modules/project-users/project-users.module' +import { ModelVisibilitiesModule } from './modules/model-visibilities/model-visibilities.module' +import { HookFiltersModule } from './modules/hook-filters/hook-filters.module' +import { ApiTokensModule } from './modules/api-tokens/api-tokens.module' +import { AttachmentsModule } from './modules/attachments/attachments.module' +import { OrgLcenseModule } from './modules/org-lcense/org-lcense.module' +import { OrgTokensModule } from './modules/org-tokens/org-tokens.module' +import { OrgUsersModule } from './modules/org-users/org-users.module' +import { MetaDiffsModule } from './modules/meta-diffs/meta-diffs.module' +import { AuditsModule } from './modules/audits/audits.module' +import { DatasModule } from './modules/datas/datas.module' +import { ApiDocsModule } from './modules/api-docs/api-docs.module' +import { PublicMetasModule } from './modules/public-metas/public-metas.module' +import { PublicDatasModule } from './modules/public-datas/public-datas.module' +import { PublicDatasExportModule } from './modules/public-datas-export/public-datas-export.module' +import { SyncModule } from './modules/sync/sync.module' +import { ImportModule } from './modules/import/import.module' +import { CachesModule } from './modules/caches/caches.module' +import { TestModule } from './modules/test/test.module' +import { PluginsModule } from './modules/plugins/plugins.module' +import { GlobalModule } from './modules/global/global.module' +import { LocalStrategy } from './strategies/local.strategy' +import NcConfigFactory from './utils/NcConfigFactory' +import NcUpgrader from './version-upgrader/NcUpgrader' +import { ClientService } from './services/client/client.service' +import { AuthTokenStrategy } from './strategies/authtoken.strategy/authtoken.strategy' +import { BaseViewStrategy } from './strategies/base-view.strategy/base-view.strategy' +import { GoogleStrategy } from './strategies/google.strategy/google.strategy' import type { MiddlewareConsumer, OnApplicationBootstrap, Provider, -} from '@nestjs/common'; +} from '@nestjs/common' + /* export const JwtStrategyProvider: Provider = { @@ -127,7 +128,7 @@ export const JwtStrategyProvider: Provider = { SyncModule, ImportModule, CachesModule, - TestModule, + ...(process.env['PLAYWRIGHT_TEST'] === 'true' ? [TestModule] : []), PluginsModule, ], controllers: [], @@ -155,24 +156,25 @@ export class AppModule implements OnApplicationBootstrap { constructor( private readonly connection: Connection, private readonly metaService: MetaService, - ) {} + ) { + } // Global Middleware configure(consumer: MiddlewareConsumer) { consumer .apply(GlobalMiddleware) - .forRoutes({ path: '*', method: RequestMethod.ALL }); + .forRoutes({ path: '*', method: RequestMethod.ALL }) } // app init async onApplicationBootstrap(): Promise { - await this.connection.init(); - await this.metaService.init(); + await this.connection.init() + await this.metaService.init() // todo: remove // temporary hack - Noco._ncMeta = this.metaService; - Noco.config = this.connection.config; + Noco._ncMeta = this.metaService + Noco.config = this.connection.config // run upgrader // await NcUpgrader.upgrade({ ncMeta: Noco._ncMeta });