Skip to content

Commit

Permalink
feat(E2E): Introducing maven dotcms-e2e-node module to host Node.js E…
Browse files Browse the repository at this point in the history
…2E tests invocation from maven.

Refs: #29845
  • Loading branch information
victoralfaro-dotcms committed Sep 13, 2024
1 parent ecf701c commit 04af673
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 2 deletions.
2 changes: 2 additions & 0 deletions e2e/dotcms-e2e-node/frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CI=false
BASE_URL=http://localhost:8080
1 change: 1 addition & 0 deletions e2e/dotcms-e2e-node/frontend/.env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CI=true
1 change: 1 addition & 0 deletions e2e/dotcms-e2e-node/frontend/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BASE_URL=http://localhost:4200
5 changes: 5 additions & 0 deletions e2e/dotcms-e2e-node/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
2 changes: 2 additions & 0 deletions e2e/dotcms-e2e-node/frontend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

console.log('Node.js E2E Tests');
15 changes: 15 additions & 0 deletions e2e/dotcms-e2e-node/frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "frontend",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@playwright/test": "^1.47.0",
"@types/node": "^22.5.4",
"dotenv": "^16.4.5"
},
"scripts": {
"start-local": "CURRENT_ENV=local yarn playwright test",
"start-ci": "CURRENT_ENV=ci yarn playwright test"
}
}
68 changes: 68 additions & 0 deletions e2e/dotcms-e2e-node/frontend/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import dotenv from 'dotenv';
import * as path from "node:path";
import { defineConfig, devices } from '@playwright/test';

const resolveEnvs = () => {
const envFiles = ['.env'];

if (process.env.CURRENT_ENV === 'local') {
envFiles.push('.env.local');
} else if (process.env.CURRENT_ENV === 'ci') {
envFiles.push('.env.ci');
}

envFiles.forEach((file) => {
dotenv.config({
path: path.resolve(__dirname, file),
override: true
});
});
};

resolveEnvs();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: process.env.BASE_URL,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
],
webServer: {
command: 'nx serve dotcms-ui',
cwd: '../../../core-web',
url: process.env.BASE_URL + '/dotAdmin',
reuseExistingServer: !!process.env.CI,
}
});
8 changes: 8 additions & 0 deletions e2e/dotcms-e2e-node/frontend/tests/welcome.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('/dotAdmin');

// Expect h3 to contain a substring.
expect(await page.locator('h3').textContent()).toContain('Welcome!');
});
46 changes: 46 additions & 0 deletions e2e/dotcms-e2e-node/frontend/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@playwright/test@^1.47.0":
version "1.47.0"
resolved "https://registry.npmjs.org/@playwright/test/-/test-1.47.0.tgz#69fc55b10754147cc20021afbfa05747d4961bf0"
integrity sha512-SgAdlSwYVpToI4e/IH19IHHWvoijAYH5hu2MWSXptRypLSnzj51PcGD+rsOXFayde4P9ZLi+loXVwArg6IUkCA==
dependencies:
playwright "1.47.0"

"@types/node@^22.5.4":
version "22.5.4"
resolved "https://registry.npmjs.org/@types/node/-/node-22.5.4.tgz#83f7d1f65bc2ed223bdbf57c7884f1d5a4fa84e8"
integrity sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg==
dependencies:
undici-types "~6.19.2"

dotenv@^16.4.5:
version "16.4.5"
resolved "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

[email protected]:
version "2.3.2"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

[email protected]:
version "1.47.0"
resolved "https://registry.npmjs.org/playwright-core/-/playwright-core-1.47.0.tgz#b54ec060fd83e5c2e46b63986b5ebb5e96ace427"
integrity sha512-1DyHT8OqkcfCkYUD9zzUTfg7EfTd+6a8MkD/NWOvjo0u/SCNd5YmY/lJwFvUZOxJbWNds+ei7ic2+R/cRz/PDg==

[email protected]:
version "1.47.0"
resolved "https://registry.npmjs.org/playwright/-/playwright-1.47.0.tgz#fb9b028883fad11362f9ff63ce7ba44bda0bf626"
integrity sha512-jOWiRq2pdNAX/mwLiwFYnPHpEZ4rM+fRSQpRHwEwZlP2PUANvL3+aJOF/bvISMhFD30rqMxUB4RJx9aQbfh4Ww==
dependencies:
playwright-core "1.47.0"
optionalDependencies:
fsevents "2.3.2"

undici-types@~6.19.2:
version "6.19.8"
resolved "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"
integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==
182 changes: 182 additions & 0 deletions e2e/dotcms-e2e-node/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.dotcms</groupId>
<artifactId>dotcms-nodejs-parent</artifactId>
<version>${revision}${sha1}${changelist}</version>
<relativePath>../../nodejs-parent/pom.xml</relativePath>
</parent>

<packaging>jar</packaging>
<artifactId>dotcms-e2e-node</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skip.npm.install>false</skip.npm.install>
<yarn.install.cmd>install --frozen-lockfile</yarn.install.cmd>
<playwright.install.cmd>global add playwright</playwright.install.cmd>
<e2e.test.skip>true</e2e.test.skip>
<e2e.test.env>local</e2e.test.env>
<e2e.test.cmd>run start-${e2e.test.env}</e2e.test.cmd>
<tomcat.port>8080</tomcat.port>
<e2e.server.url>http://localhost:${tomcat.port}</e2e.server.url>
<wiremock.api.key>${ext.wiremock.api.key}</wiremock.api.key>
<docker.image.wiremock>${ext.docker.image.wiremock}</docker.image.wiremock>
<docker.wm.volume>./src/test/resources</docker.wm.volume>
<docker.wm.volume.internal>/home/wiremock</docker.wm.volume.internal>
</properties>

<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<goals>
<goal>yarn</goal>
</goals>
<!-- optional: the default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<skip>${skip.npm.install}</skip>
<arguments>${yarn.install.cmd}</arguments>
</configuration>
</execution>
<execution>
<id>install-playwrigth</id>
<goals>
<goal>yarn</goal>
</goals>
<!-- optional: the default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<skip>${skip.npm.install}</skip>
<arguments>${playwright.install.cmd}</arguments>
</configuration>
</execution>
<execution>
<id>run node script</id>
<!-- Adjust the phase as per your requirement -->
<goals>
<goal>yarn</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<workingDirectory>./frontend</workingDirectory>
<skip>${e2e.test.skip}</skip>
<arguments>${e2e.test.cmd}</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skipTests>${e2e.test.skip}</skipTests>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>none</phase>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<showLogs>true</showLogs>
<follow>true</follow>
<skip>${e2e.test.skip}</skip>
<imagesMap>
<wiremock>
<name>${docker.image.wiremock}</name>
<run>
<ports>
<port>wiremock.port:8080</port>
</ports>
<volumes>
<bind>
<volume>${docker.wm.volume}:${docker.wm.volume.internal}</volume>
</bind>
</volumes>
<log>
<prefix>[WireMock]</prefix>
<color>green</color>
</log>
</run>
</wiremock>
<dotcms>
<run>
<env>
<CATALINA_OPTS>-XX:+PrintFlagsFinal</CATALINA_OPTS>
<DB_MAX_TOTAL>15</DB_MAX_TOTAL>
<DOT_INDEX_POLICY_SINGLE_CONTENT>FORCE</DOT_INDEX_POLICY_SINGLE_CONTENT>
<DOT_ASYNC_REINDEX_COMMIT_LISTENERS>false</DOT_ASYNC_REINDEX_COMMIT_LISTENERS>
<DOT_ASYNC_COMMIT_LISTENERS>false</DOT_ASYNC_COMMIT_LISTENERS>
<DOT_CACHE_GRAPHQLQUERYCACHE_SECONDS>600</DOT_CACHE_GRAPHQLQUERYCACHE_SECONDS>
<JVM_ENDPOINT_TEST_PASS>obfuscate_me</JVM_ENDPOINT_TEST_PASS>
<DOT_ENABLE_SCRIPTING>true</DOT_ENABLE_SCRIPTING>
<DOT_ANNOUNCEMENTS_BASE_URL>http://localhost:8080</DOT_ANNOUNCEMENTS_BASE_URL>
<DOT_ALLOW_ACCESS_TO_PRIVATE_SUBNETS>true</DOT_ALLOW_ACCESS_TO_PRIVATE_SUBNETS>
<DOT_DOTCMS_DEV_MODE>true</DOT_DOTCMS_DEV_MODE>
<DOT_AI_API_URL>http://wm:8080/c</DOT_AI_API_URL>
<DOT_AI_IMAGE_API_URL>http://wm:8080/i</DOT_AI_IMAGE_API_URL>
<DOT_AI_EMBEDDINGS_API_URL>http://wm:8080/e</DOT_AI_EMBEDDINGS_API_URL>
<DOT_AI_MODELS_API_URL>http://wm:8080/m</DOT_AI_MODELS_API_URL>
<DOT_AI_DEBUG_LOGGER>true</DOT_AI_DEBUG_LOGGER>
</env>
<links combine.children="append">
<link>wiremock:wm</link>
</links>
</run>
</dotcms>
</imagesMap>
</configuration>
<executions>
<execution>
<id>cleanup-at-start</id>
<goals>
<goal>stop</goal>
<goal>volume-remove</goal>
</goals>
<phase>pre-integration-test</phase>
</execution>
<execution>
<id>start</id>
<goals>
<goal>start</goal>
</goals>
<phase>pre-integration-test</phase>
</execution>
<execution>
<id>stop</id>
<goals>
<goal>stop</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
</profiles>

</project>
2 changes: 1 addition & 1 deletion e2e/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<modules>
<module>dotcms-e2e-java</module>
<!-- <module>dotcms-e2e-node</module>-->
<module>dotcms-e2e-node</module>
</modules>

</project>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<module>dotcms-postman</module>
<module>reports</module>
<module>e2e/dotcms-e2e-java</module>
<!-- <module>e2e/dotcms-e2e-node</module>-->
<module>e2e/dotcms-e2e-node</module>
</modules>
<repositories>
<repository>
Expand Down

0 comments on commit 04af673

Please sign in to comment.