From 165f0c8d7210ca8975145820f88822d875377c8d Mon Sep 17 00:00:00 2001 From: Apoorva Srinivas Appadoo Date: Tue, 13 Jun 2023 18:21:57 +0200 Subject: [PATCH] feat: generate project Ref: #383 --- apps/front-end/back-office-e2e/project.json | 14 +++++ .../front-end/cross-office-e2e/.eslintrc.json | 22 +++++++ .../cross-office-e2e/playwright.config.ts | 21 +++++++ apps/front-end/cross-office-e2e/project.json | 38 +++++++++++ .../cross-office-e2e/src/app.spec.ts | 7 +++ .../src/support/global-setup.ts | 63 +++++++++++++++++++ .../src/support/global-teardown.ts | 33 ++++++++++ .../cross-office-e2e/tsconfig.e2e.json | 10 +++ apps/front-end/cross-office-e2e/tsconfig.json | 10 +++ 9 files changed, 218 insertions(+) create mode 100644 apps/front-end/cross-office-e2e/.eslintrc.json create mode 100644 apps/front-end/cross-office-e2e/playwright.config.ts create mode 100644 apps/front-end/cross-office-e2e/project.json create mode 100644 apps/front-end/cross-office-e2e/src/app.spec.ts create mode 100644 apps/front-end/cross-office-e2e/src/support/global-setup.ts create mode 100644 apps/front-end/cross-office-e2e/src/support/global-teardown.ts create mode 100644 apps/front-end/cross-office-e2e/tsconfig.e2e.json create mode 100644 apps/front-end/cross-office-e2e/tsconfig.json diff --git a/apps/front-end/back-office-e2e/project.json b/apps/front-end/back-office-e2e/project.json index 8518f877..4b376293 100644 --- a/apps/front-end/back-office-e2e/project.json +++ b/apps/front-end/back-office-e2e/project.json @@ -4,6 +4,20 @@ "sourceRoot": "apps/front-end/back-office-e2e/src", "projectType": "application", "targets": { + "front-end-serve": { + "executor": "@angular-devkit/architect:allOf", + "options": { + "targets": [ + { + "target": "front-end-back-office:serve" + }, + { + "target": "front-end-front-office:serve" + } + ] + } + }, + "e2e": { "executor": "@mands/nx-playwright:playwright-executor", "options": { diff --git a/apps/front-end/cross-office-e2e/.eslintrc.json b/apps/front-end/cross-office-e2e/.eslintrc.json new file mode 100644 index 00000000..888b4cdc --- /dev/null +++ b/apps/front-end/cross-office-e2e/.eslintrc.json @@ -0,0 +1,22 @@ +{ + "extends": ["../../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": { + "jest/no-done-callback": "off" + } + }, + { + "files": ["*.ts", "*.tsx"], + "rules": { + "jest/no-done-callback": "off" + } + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/apps/front-end/cross-office-e2e/playwright.config.ts b/apps/front-end/cross-office-e2e/playwright.config.ts new file mode 100644 index 00000000..5278c4dd --- /dev/null +++ b/apps/front-end/cross-office-e2e/playwright.config.ts @@ -0,0 +1,21 @@ +import type { PlaywrightTestConfig } from '@playwright/test'; + +import { baseConfig } from '../../../playwright.config.base'; + +const config: PlaywrightTestConfig = { + ...baseConfig, + globalSetup: require.resolve( + 'apps/front-end/cross-office-e2e/src/support/global-setup.ts' + ), + globalTeardown: require.resolve( + 'apps/front-end/cross-office-e2e/src/support/global-teardown.ts' + ), + use: { + ...baseConfig.use, + ignoreHTTPSErrors: true, + video: 'on-first-retry', + screenshot: 'only-on-failure', + }, +}; + +export default config; diff --git a/apps/front-end/cross-office-e2e/project.json b/apps/front-end/cross-office-e2e/project.json new file mode 100644 index 00000000..4ad0bafd --- /dev/null +++ b/apps/front-end/cross-office-e2e/project.json @@ -0,0 +1,38 @@ +{ + "name": "front-end-cross-office-e2e", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "apps/front-end/cross-office-e2e/src", + "projectType": "application", + "targets": { + "e2e": { + "executor": "@mands/nx-playwright:playwright-executor", + "options": { + "e2eFolder": "apps/front-end/cross-office-e2e", + "packageRunner": "pnpm" + }, + "configurations": { + "production": {} + } + }, + "ts-check": { + "executor": "nx:run-commands", + "options": { + "commands": [ + { + "command": "tsc --build --force --verbose apps/undefined-e2e/tsconfig.json" + } + ] + } + }, + "lint": { + "executor": "@nrwl/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": [ + "apps/front-end/cross-office-e2e/**/*.{ts,tsx,js,jsx}" + ] + } + } + }, + "tags": [] +} diff --git a/apps/front-end/cross-office-e2e/src/app.spec.ts b/apps/front-end/cross-office-e2e/src/app.spec.ts new file mode 100644 index 00000000..49889ac3 --- /dev/null +++ b/apps/front-end/cross-office-e2e/src/app.spec.ts @@ -0,0 +1,7 @@ +import { expect, test } from '@playwright/test'; + +test('should start page', async ({ page }) => { + await page.goto('/'); + + expect(true).toBeTruthy(); +}); diff --git a/apps/front-end/cross-office-e2e/src/support/global-setup.ts b/apps/front-end/cross-office-e2e/src/support/global-setup.ts new file mode 100644 index 00000000..eaca5e31 --- /dev/null +++ b/apps/front-end/cross-office-e2e/src/support/global-setup.ts @@ -0,0 +1,63 @@ +/* eslint-disable */ +import axios from 'axios'; +import { subProcess, subProcessSync } from 'subspawn'; +import { environment, protocol } from '@webonjour/shared/environments'; + +var __TEARDOWN_MESSAGE__: string; + +module.exports = async function () { + // Start services that the app needs to run (e.g. database, docker-compose, etc.). + console.log('\nSetting up...\n'); + + let executor = 'docker-compose'; + + // Check if docker compose is installed + try { + subProcessSync('docker-compose --version', true); + } catch (e) { + executor = 'podman-compose'; + try { + subProcessSync('podman-compose --version', true); + } catch (e) { + executor = 'docker compose'; + try { + subProcessSync('docker compose --version', true); + } catch (e) { + console.log('Please install docker-compose or podman-compose'); + process.exit(1); + } + } + } + + subProcessSync(`${executor} -f docker-compose.yml up -d`, true); + // wait for the database to start + for (let i = 0; i < 200; i++) { + try { + // subProcessSync("npx prisma migrate dev deploy", true); + subProcessSync('npx prisma migrate reset --force', true); + subProcessSync('npx prisma generate', true); + break; + } catch (e) { + console.log('Waiting for database to start...'); + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + } + subProcess('API', 'npx nx serve backend-api', true); + + axios.defaults.baseURL = `${protocol(environment.api.secure)}://${ + environment.api.domain + }`; + console.log('axios.defaults.baseURL', axios.defaults.baseURL); + // wait for the server to start + for (let i = 0; i < 200; i++) { + try { + await axios.get(`/health`); + break; + } catch (e) { + console.log('Waiting for server to start...'); + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + } + // Hint: Use `globalThis` to pass variables to global teardown. + globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n'; +}; diff --git a/apps/front-end/cross-office-e2e/src/support/global-teardown.ts b/apps/front-end/cross-office-e2e/src/support/global-teardown.ts new file mode 100644 index 00000000..b17afdc2 --- /dev/null +++ b/apps/front-end/cross-office-e2e/src/support/global-teardown.ts @@ -0,0 +1,33 @@ +/* eslint-disable */ + +import { killSubProcesses, subProcessSync } from 'subspawn'; + +module.exports = async function () { + // Put clean up logic here (e.g. stopping services, docker-compose, etc.). + // Hint: `globalThis` is shared between setup and teardown. + // stop the server + + let executor = 'docker-compose'; + + // Check if docker compose is installed + try { + subProcessSync('docker-compose --version', true); + } catch (e) { + executor = 'podman-compose'; + try { + subProcessSync('podman-compose --version', true); + } catch (e) { + executor = 'docker compose'; + try { + subProcessSync('docker compose --version', true); + } catch (e) { + console.log('Please install docker-compose or podman-compose'); + process.exit(1); + } + } + } + + killSubProcesses('API'); + subProcessSync(`${executor} -f docker-compose.yml down`, true); + console.log(globalThis.__TEARDOWN_MESSAGE__); +}; diff --git a/apps/front-end/cross-office-e2e/tsconfig.e2e.json b/apps/front-end/cross-office-e2e/tsconfig.e2e.json new file mode 100644 index 00000000..3c28aa02 --- /dev/null +++ b/apps/front-end/cross-office-e2e/tsconfig.e2e.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "sourceMap": false, + "outDir": "../../../dist/out-tsc", + "allowJs": true, + "types": ["jest", "node"] + }, + "include": ["**/*.ts", "**/*.js"] +} diff --git a/apps/front-end/cross-office-e2e/tsconfig.json b/apps/front-end/cross-office-e2e/tsconfig.json new file mode 100644 index 00000000..fbc6e9be --- /dev/null +++ b/apps/front-end/cross-office-e2e/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig.base.json", + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.e2e.json" + } + ] +}