Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/add basic e2e test to test publishing #758

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/springwolf-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ jobs:
- name: Run build, check, analyzeDependencies on example
run: ./gradlew -p ${{ env.example }} build

- name: Run e2e tests
run: ./gradlew -p springwolf-examples/e2e npm_run_test
env:
SPRINGWOLF_EXAMPLE: ${{ matrix.plugin }}
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report-${{ matrix.plugin }}
path: springwolf-examples/e2e/playwright-report/
retention-days: 14

- name: Publish docker image
if: github.ref == 'refs/heads/master'
run: ./gradlew -p ${{ env.example }} dockerBuildImage dockerPushImage
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include(
'springwolf-plugins:springwolf-kafka-plugin',
'springwolf-plugins:springwolf-sns-plugin',
'springwolf-plugins:springwolf-sqs-plugin',
'springwolf-examples:e2e',
'springwolf-examples:springwolf-amqp-example',
'springwolf-examples:springwolf-cloud-stream-example',
'springwolf-examples:springwolf-jms-example',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class MessageDto {
private final Map<String, String> headers;

@Builder.Default
private final String payload = EMPTY;
private final String payloadType = String.class.getCanonicalName();

@Builder.Default
private final String payloadType = String.class.getCanonicalName();
private final String payload = EMPTY;
}
5 changes: 5 additions & 0 deletions springwolf-examples/e2e/.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/
31 changes: 31 additions & 0 deletions springwolf-examples/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# End-to-End tests for Springwolf

The end-to-end tests cover test cases that cannot be verified using junitk/jest unit/integration/system tests.
Typical examples are click interactions through `springwolf-ui`.

## Usage

This project uses [playwright](https://playwright.dev).

To install the dependencies, run `npm install` (or `../../gradlew npmInstall`)

To use the playwright ui, run
```bash
npm run start
```

For ci/cd or cli environments, use `../../gradlew npm_run_test` or
```bash
npm run test
```

### Example project
The end-to-end tests are run against one example project, which is automatically started using docker.

To test against the non-default project, specify the environment variable `SPRINGWOLF_EXAMPLE`
For example:
```bash
SPRINGWOLF_EXAMPLE=kafka npm run start
```

_Note: The example is re-used between tests. When switching example projects, the docker containers need to be stopped._
44 changes: 44 additions & 0 deletions springwolf-examples/e2e/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id 'java'
id 'com.github.node-gradle.node' version '7.0.2'
}

node {
version = '18.16.1'
npmVersion = '9.5.1'
download = true
}

npm_run_test {
dependsOn spotlessCheck

inputs.files fileTree("tests")
inputs.files fileTree("util")
inputs.file 'playwright.config.ts'
inputs.file 'package.json'
inputs.file 'package-lock.json'
}

spotless {
encoding 'UTF-8'

def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'
def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'

format 'styling', {
target 'tests/**/*.ts', 'tests/**/*.js', 'util/**/*.ts', 'util/**/*.js'

prettier()
.npmExecutable("${tasks.named('npmSetup').get().npmDir.get()}${npmExec}")
.nodeExecutable("${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}")

licenseHeader("/* SPDX-License-Identifier: Apache-2.0 */", "import|export|.* \\{")

trimTrailingWhitespace()
endWithNewline()
}
}

tasks.named('spotlessStyling').configure {
it.dependsOn('nodeSetup', 'npmSetup')
}
92 changes: 92 additions & 0 deletions springwolf-examples/e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions springwolf-examples/e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "e2e",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "playwright test --ui",
"test": "playwright test",
"postinstall": "npx playwright install --with-deps chromium"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.44.0",
"@types/node": "^20.12.11"
}
}
79 changes: 79 additions & 0 deletions springwolf-examples/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from '@playwright/test';
import { getExampleProject } from './util/example';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* 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: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:8080/springwolf/asyncapi-ui.html',

/* 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'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your loal dev server before starting the tests */
webServer: {
cwd: '../springwolf-' + getExampleProject() + '-example',
command: 'docker compose up',
url: 'http://127.0.0.1:8080/springwolf/docs.json',
reuseExistingServer: !process.env.CI,
},
});
23 changes: 23 additions & 0 deletions springwolf-examples/e2e/tests/application-log.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* SPDX-License-Identifier: Apache-2.0 */
import { test, expect } from "@playwright/test";
import {
monitorDockerLogs,
MonitorDockerLogsResponse,
verifyNoErrorLogs,
} from "../util/external_process";

let dockerLogs: MonitorDockerLogsResponse;
test.beforeAll(async () => {
dockerLogs = monitorDockerLogs();
});
test.afterAll(async () => {
console.debug("---\nProcessMessages---\n", dockerLogs.messages.join("\n"));
});

test("no error nor warn log messages in logs", async ({ page }) => {
// Ensure that logs are available by calling the docs endpoint
await page.goto("");

verifyNoErrorLogs(dockerLogs);
expect(dockerLogs.errors).toHaveLength(0);
});
32 changes: 32 additions & 0 deletions springwolf-examples/e2e/tests/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: Apache-2.0 */
import { test, expect } from "@playwright/test";
import { locateChannelItems } from "../util/page_object";
import { getExampleAsyncApi } from "../util/example";

test.beforeEach(async ({ page }) => {
await page.goto("");
});

test("has title", async ({ page }) => {
await expect(page).toHaveTitle(/Springwolf/);
});

test("can click download and get original asyncapi.json in new tab", async ({
page,
}) => {
const newPagePromise = page.waitForEvent("popup");

await page.click("text=Download AsyncAPI file");
await page.waitForTimeout(500);

const newPage = await newPagePromise;
const content = await newPage.textContent("body pre");
const asyncApiJson = JSON.parse(content!!);

expect(asyncApiJson.info.title).toContain("Springwolf example project");
expect(asyncApiJson).toStrictEqual(getExampleAsyncApi());
});

test("has channels and channel item", async ({ page }) => {
expect(await locateChannelItems(page).count()).toBeGreaterThan(0);
});
Loading