From c0a5420e8b723d167685dc5470c6a735ee05d7e8 Mon Sep 17 00:00:00 2001 From: Andrea Barbasso <´andrea.barbasso@4science.com´> Date: Thu, 8 May 2025 12:20:10 +0200 Subject: [PATCH] [DURACOM-309] add prod-e2e build script and use it for e2e tests --- .github/workflows/build.yml | 2 +- angular.json | 61 ++++++++++++++++++- package.json | 2 + .../shared/cookies/browser-orejime.service.ts | 2 +- src/assets/i18n/en.json5 | 2 +- src/assets/i18n/it.json5 | 4 +- src/config/build-config.interface.ts | 1 + src/environments/.gitignore | 1 + .../environment.production-e2e.ts | 10 +++ 9 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 src/environments/environment.production-e2e.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e13d8f75d7..04c5996740 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,7 +102,7 @@ jobs: run: npm run check-circ-deps - name: Run build - run: npm run build:prod + run: npm run build:prod-e2e - name: Run specs (unit tests) run: npm run test:headless diff --git a/angular.json b/angular.json index 4b95be5512..37e53376b1 100644 --- a/angular.json +++ b/angular.json @@ -105,6 +105,37 @@ "maximumError": "300kb" } ] + }, + "production-e2e": { + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.production-e2e.ts" + }, + { + "replace": "src/config/store/devtools.ts", + "with": "src/config/store/devtools.prod.ts" + } + ], + "optimization": true, + "outputHashing": "all", + "namedChunks": false, + "aot": true, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": true, + "budgets": [ + { + "type": "initial", + "maximumWarning": "3mb", + "maximumError": "5mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "200kb", + "maximumError": "300kb" + } + ] } } }, @@ -120,6 +151,9 @@ }, "production": { "buildTarget": "dspace-angular:build:production" + }, + "production-e2e": { + "buildTarget": "dspace-angular:build:production-e2e" } } }, @@ -181,6 +215,9 @@ "configurations": { "production": { "devServerTarget": "dspace-angular:serve:production" + }, + "production-e2e": { + "devServerTarget": "dspace-angular:serve:production-e2e" } } }, @@ -215,6 +252,20 @@ "with": "src/config/store/devtools.prod.ts" } ] + }, + "production-e2e": { + "sourceMap": false, + "optimization": true, + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.production-e2e.ts" + }, + { + "replace": "src/config/store/devtools.ts", + "with": "src/config/store/devtools.prod.ts" + } + ] } } }, @@ -229,6 +280,10 @@ "production": { "buildTarget": "dspace-angular:build:production", "serverTarget": "dspace-angular:server:production" + }, + "production-e2e": { + "buildTarget": "dspace-angular:build:production-e2e", + "serverTarget": "dspace-angular:server:production-e2e" } } }, @@ -242,7 +297,8 @@ ] }, "configurations": { - "production": {} + "production": {}, + "production-e2e": {} } }, "cypress-run": { @@ -253,6 +309,9 @@ "configurations": { "production": { "devServerTarget": "dspace-angular:serve:production" + }, + "production-e2e": { + "devServerTarget": "dspace-angular:serve:production-e2e" } } }, diff --git a/package.json b/package.json index 13ba71ee88..a9a6206afc 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,9 @@ "build": "ng build --configuration development", "build:stats": "ng build --stats-json", "build:prod": "cross-env NODE_ENV=production npm run build:ssr", + "build:prod-e2e": "cross-env NODE_ENV=production npm run build:ssr-e2e", "build:ssr": "ng build --configuration production && ng run dspace-angular:server:production", + "build:ssr-e2e": "ng build --configuration production-e2e && ng run dspace-angular:server:production-e2e", "build:lint": "rimraf 'lint/dist/**/*.js' 'lint/dist/**/*.js.map' && tsc -b lint/tsconfig.json", "test": "ng test --source-map=true --watch=false --configuration test", "test:watch": "nodemon --exec \"ng test --source-map=true --watch=true --configuration test\"", diff --git a/src/app/shared/cookies/browser-orejime.service.ts b/src/app/shared/cookies/browser-orejime.service.ts index 1691d39a87..895624cf79 100644 --- a/src/app/shared/cookies/browser-orejime.service.ts +++ b/src/app/shared/cookies/browser-orejime.service.ts @@ -191,7 +191,7 @@ export class BrowserOrejimeService extends OrejimeService { */ this.translateConfiguration(); - if (this._window?.nativeWindow?.Cypress) { + if (environment.isE2E) { this.orejimeConfig.apps = []; } else { this.orejimeConfig.apps = this.filterConfigApps(appsToHide); diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index b8bbc9ee02..10e1df8751 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1639,7 +1639,7 @@ "cookies.consent.app.title.correlation-id": "Correlation ID", - "cookies.consent.app.description.correlation-id": "Allow us to track your session for debugging purposes", + "cookies.consent.app.description.correlation-id": "Allow us to track your session in backend logs for support/debugging purposes", "cookies.consent.app.title.preferences": "Preferences", diff --git a/src/assets/i18n/it.json5 b/src/assets/i18n/it.json5 index 434749a538..ca799a1a91 100644 --- a/src/assets/i18n/it.json5 +++ b/src/assets/i18n/it.json5 @@ -2669,8 +2669,8 @@ // "cookies.consent.app.title.correlation-id": "Correlation ID", "cookies.consent.app.title.correlation-id": "ID di correlazione", - // "cookies.consent.app.description.correlation-id": "Allow us to track your session for debugging purposes", - "cookies.consent.app.description.correlation-id": "Consentici di tracciare la tua sessione per scopi di debug", + // "cookies.consent.app.description.correlation-id": "Allow us to track your session in backend logs for support/debugging purposes", + "cookies.consent.app.description.correlation-id": "Ci consente di monitorare la sessione nei log di backend per supporto/debug", // "cookies.consent.app.title.preferences": "Preferences", "cookies.consent.app.title.preferences": "Preferenze", diff --git a/src/config/build-config.interface.ts b/src/config/build-config.interface.ts index 9501ae5e28..712f0f673b 100644 --- a/src/config/build-config.interface.ts +++ b/src/config/build-config.interface.ts @@ -3,4 +3,5 @@ import { SSRConfig } from './ssr-config.interface'; export interface BuildConfig extends AppConfig { ssr: SSRConfig; + isE2E?: boolean; } diff --git a/src/environments/.gitignore b/src/environments/.gitignore index 03f1bde6f9..a44fe84c68 100644 --- a/src/environments/.gitignore +++ b/src/environments/.gitignore @@ -1,5 +1,6 @@ environment.*.ts !environment.production.ts +!environment.production-e2e.ts !environment.test.ts !environment.ts diff --git a/src/environments/environment.production-e2e.ts b/src/environments/environment.production-e2e.ts new file mode 100644 index 0000000000..71952570c6 --- /dev/null +++ b/src/environments/environment.production-e2e.ts @@ -0,0 +1,10 @@ +import { BuildConfig } from '../config/build-config.interface'; +import { environment as prodEnvironment } from './environment.production'; + +export const environment: Partial = Object.assign( + {}, + prodEnvironment, + { + isE2E: true, + }, +);