Skip to content

Commit

Permalink
fix: e2e missing package and linter (#1414)
Browse files Browse the repository at this point in the history
* fix: e2e missing package and linter

* chore: revert stackblitz to window and declare types
  • Loading branch information
patzick authored Nov 7, 2024
1 parent 30ee648 commit c762fd5
Show file tree
Hide file tree
Showing 31 changed files with 21,671 additions and 12,363 deletions.
13 changes: 13 additions & 0 deletions apps/e2e-tests/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": ["../../biome.json"],
"files": {
"ignore": ["playwright-report", "reports", "test-results"]
},
"linter": {
"rules": {
"complexity": {
"noForEach": "off"
}
}
}
}
3 changes: 1 addition & 2 deletions apps/e2e-tests/examples.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { PlaywrightTestConfig } from "@playwright/test";
import { devices } from "@playwright/test";
import find from "find-up";
export const findEnv = () => find.sync(process.env.ENV_FILE || ".env");
import { findEnv } from "./utils/helpers";

/**
* Read environment variables from file.
Expand Down
2 changes: 2 additions & 0 deletions apps/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"scripts": {
"test:e2e": "playwright test e2e",
"test:examples": "playwright test -c examples.config.ts checkCodeExamples.spec.ts",
"lint": "biome lint .",
"start": "npx http-server"
},
"devDependencies": {
"@playwright/test": "1.48.2"
},
"dependencies": {
"@faker-js/faker": "9.0.3",
"@stackblitz/sdk": "1.11.0",
"dotenv": "16.4.5",
"http-server": "14.1.1"
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/page-objects/AbstractPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from "@playwright/test";
import type { Page } from "@playwright/test";

export class AbstractPage {
readonly page: Page;
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/page-objects/CartPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";

export class CartPage {
readonly page: Page;
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/page-objects/CategoryPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";

export class CategoryPage {
readonly page: Page;
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/page-objects/CheckoutPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";

export class CheckoutPage {
readonly page: Page;
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/page-objects/HomePage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";
import { AbstractPage } from "./AbstractPage";

export class HomePage extends AbstractPage {
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/page-objects/LoginPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";

export class LoginForm {
// Define selectors
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/page-objects/MyAccountPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";

export class MyAccountPage {
readonly page: Page;
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/page-objects/ProductPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Locator, Page } from "@playwright/test";
import { expect, type Locator, type Page } from "@playwright/test";

export class ProductPage {
readonly page: Page;
Expand Down
6 changes: 3 additions & 3 deletions apps/e2e-tests/page-objects/RegisterPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";
import { faker } from "@faker-js/faker";

export class RegisterForm {
Expand Down Expand Up @@ -73,8 +73,8 @@ export class RegisterForm {

async createUser() {
await this.salutation.selectOption({ label: "Mr." });
await this.firstName.type("e2e " + faker.person.firstName());
await this.lastName.type("e2e " + faker.person.lastName());
await this.firstName.type(`e2e ${faker.person.firstName()}`);
await this.lastName.type(`e2e ${faker.person.lastName()}`);
await this.emailAdrdress.type(faker.internet.exampleEmail());
await this.password.type(faker.internet.password());
await this.street.type(faker.location.street());
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/page-objects/SearchResultPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";

export class SearchResultPage {
readonly page: Page;
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/page-objects/WishlistPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Locator, Page } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";

export class WishlistPage {
readonly page: Page;
Expand Down
3 changes: 1 addition & 2 deletions apps/e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { PlaywrightTestConfig } from "@playwright/test";
import { devices } from "@playwright/test";
import find from "find-up";
export const findEnv = () => find.sync(process.env.ENV_FILE || ".env");
import { findEnv } from "./utils/helpers";

/**
* Read environment variables from file.
Expand Down
5 changes: 2 additions & 3 deletions apps/e2e-tests/tests/addProductReview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { test, expect } from "@playwright/test";
import { HomePage } from "../page-objects/HomePage";
import { ProductPage } from "../page-objects/ProductPage";
import { LoginForm } from "../page-objects/LoginPage";
import find from "find-up";
export const findEnv = () => find.sync(process.env.ENV_FILE || ".env");
import { findEnv } from "../utils/helpers";

require("dotenv").config({ path: findEnv() });
const userEmail = process.env.USER_EMAIL || "[email protected]";
const password = process.env.PASSWORD || "shopware123";

test.describe.only("Add review", () => {
test.describe("Add review", () => {
let homePage: HomePage;
let productPage: ProductPage;
let loginform: LoginForm;
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/tests/addToCart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CartPage } from "../page-objects/CartPage";
import { WishlistPage } from "../page-objects/WishlistPage";

test.setTimeout(50000);
test.describe.parallel.only("Add product to cart / Remove from cart", () => {
test.describe.parallel("Add product to cart / Remove from cart", () => {
let homePage: HomePage;
let productPage: ProductPage;
let cartPage: CartPage;
Expand Down
3 changes: 1 addition & 2 deletions apps/e2e-tests/tests/addToWishlist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { HomePage } from "../page-objects/HomePage";
import { ProductPage } from "../page-objects/ProductPage";
import { WishlistPage } from "../page-objects/WishlistPage";

test.describe.parallel
.only("Add product to wishlist / Remove from wishlist", () => {
test.describe.parallel("Add product to wishlist / Remove from wishlist", () => {
let homePage: HomePage;
let productPage: ProductPage;
let wishlistPage: WishlistPage;
Expand Down
14 changes: 7 additions & 7 deletions apps/e2e-tests/tests/checkCategory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, expect } from "@playwright/test";
import { HomePage } from "../page-objects/HomePage";
import { CategoryPage } from "../page-objects/CategoryPage";

test.describe.only("Check category page", () => {
test.describe("Check category page", () => {
let homePage: HomePage;
let categoryPage: CategoryPage;

Expand All @@ -18,7 +18,7 @@ test.describe.only("Check category page", () => {
await homePage.openCategoryPage();
await categoryPage.selectRandomManufacturerCheckbox();

await expect(page).toHaveURL(new RegExp(".*manufacturer.*"));
await expect(page).toHaveURL(/.*manufacturer.*/);
await expect(page.getByTestId("loading")).toHaveCount(0);
expect(await page.getByTestId("product-box-img").count()).toBeGreaterThan(
0,
Expand All @@ -29,7 +29,7 @@ test.describe.only("Check category page", () => {
await homePage.openCategoryPage();
await categoryPage.selectRandomColorCheckbox();

await expect(page).toHaveURL(new RegExp(".*properties.*"));
await expect(page).toHaveURL(/.*properties.*/);
await expect(page.getByTestId("loading")).toHaveCount(0);
expect(await page.getByTestId("product-box-img").count()).toBeGreaterThan(
0,
Expand All @@ -39,7 +39,7 @@ test.describe.only("Check category page", () => {
test("Check sorting", async ({ page }) => {
await homePage.openCategoryPage();
await categoryPage.selectSortingPriceAsc();
await expect(page).toHaveURL(new RegExp(".*order=price-asc.*"));
await expect(page).toHaveURL(/.*order=price-asc.*/);
await expect(page.getByTestId("loading")).toHaveCount(0);
expect(await page.getByTestId("product-box-img").count()).toBeGreaterThan(
0,
Expand All @@ -50,11 +50,11 @@ test.describe.only("Check category page", () => {
await homePage.openCategoryPage();
await categoryPage.selectLimitOneProductPerPage();
await expect(page.getByTestId("loading")).toHaveCount(0);
await expect(page).toHaveURL(new RegExp(".*limit.*"));
await expect(page).toHaveURL(new RegExp(".*p=1.*"));
await expect(page).toHaveURL(/.*limit.*/);
await expect(page).toHaveURL(/.*p=1.*/);
await categoryPage.goToSecondPage();
await expect(page.getByTestId("loading")).toHaveCount(0);
await expect(page).toHaveURL(new RegExp(".*p=2.*"));
await expect(page).toHaveURL(/.*p=2.*/);

expect(await page.getByTestId("product-box-img").count()).toBeGreaterThan(
0,
Expand Down
6 changes: 3 additions & 3 deletions apps/e2e-tests/tests/checkCodeExamples.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";

// names of the directories that should not be tested in StackBlitz context in case of more complex setup
// in that case an example should be tested manually
Expand All @@ -22,7 +22,7 @@ fs.readdirSync(directoryPath)
.forEach((file) => {
test(`Verify ${file}`, async ({ page }) => {
const exampleName = `shopware/frontends/tree/main/examples/${file}`;
await page.goto("file://" + __dirname + "/pages/blank.html", {
await page.goto(`file://${__dirname}/pages/blank.html`, {
waitUntil: "domcontentloaded",
timeout: 0,
});
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/tests/checkForSeoUrl.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect, request } from "@playwright/test";
import { HomePage } from "../page-objects/HomePage";

test.describe.only("Check for seo-url requests", () => {
test.describe("Check for seo-url requests", () => {
let homePage: HomePage;

// Before Hook
Expand Down
2 changes: 1 addition & 1 deletion apps/e2e-tests/tests/checkProductVariants.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HomePage } from "../page-objects/HomePage";
import { ProductPage } from "../page-objects/ProductPage";
import { CartPage } from "../page-objects/CartPage";

test.describe.parallel.only("Check product variants", () => {
test.describe.parallel("Check product variants", () => {
let homePage: HomePage;
let productPage: ProductPage;
let cartPage: CartPage;
Expand Down
14 changes: 7 additions & 7 deletions apps/e2e-tests/tests/checkSearch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, expect } from "@playwright/test";
import { HomePage } from "../page-objects/HomePage";
import { SearchResultPage } from "../page-objects/SearchResultPage";

test.describe.only("Check search page", () => {
test.describe("Check search page", () => {
let homePage: HomePage;
let resultPage: SearchResultPage;

Expand All @@ -18,7 +18,7 @@ test.describe.only("Check search page", () => {
await homePage.typeSearchPhrase("sal");
await resultPage.selectRandomManufacturerCheckbox();

await expect(page).toHaveURL(new RegExp(".*manufacturer.*"));
await expect(page).toHaveURL(/.*manufacturer.*/);
await expect(page.getByTestId("loading")).toHaveCount(0);
expect(await page.getByTestId("product-box-img").count()).toBeGreaterThan(
0,
Expand All @@ -29,7 +29,7 @@ test.describe.only("Check search page", () => {
await homePage.typeSearchPhrase("sal");
await resultPage.selectRandomSelectionCheckbox();

await expect(page).toHaveURL(new RegExp(".*properties.*"));
await expect(page).toHaveURL(/.*properties.*/);
await expect(page.getByTestId("loading")).toHaveCount(0);
expect(await page.getByTestId("product-box-img").count()).toBeGreaterThan(
0,
Expand All @@ -39,7 +39,7 @@ test.describe.only("Check search page", () => {
test("Check sorting", async ({ page }) => {
await homePage.typeSearchPhrase("sal");
await resultPage.selectSortingPriceAsc();
await expect(page).toHaveURL(new RegExp(".*order=price-asc.*"));
await expect(page).toHaveURL(/.*order=price-asc.*/);
await expect(page.getByTestId("loading")).toHaveCount(0);
expect(await page.getByTestId("product-box-img").count()).toBeGreaterThan(
0,
Expand All @@ -49,11 +49,11 @@ test.describe.only("Check search page", () => {
test("Check limit and pagination", async ({ page }) => {
await homePage.typeSearchPhrase("sal");
await resultPage.selectLimitOneProductPerPage();
await expect(page).toHaveURL(new RegExp(".*limit.*"));
await expect(page).toHaveURL(new RegExp(".*p=1.*"));
await expect(page).toHaveURL(/.*limit.*/);
await expect(page).toHaveURL(/.*p=1.*/);
await expect(page.getByTestId("loading")).toHaveCount(0);
await resultPage.goToSecondPage();
await expect(page).toHaveURL(new RegExp(".*p=2.*"));
await expect(page).toHaveURL(/.*p=2.*/);
await expect(page.getByTestId("loading")).toHaveCount(0);

expect(await page.getByTestId("product-box-img").count()).toBeGreaterThan(
Expand Down
29 changes: 20 additions & 9 deletions apps/e2e-tests/tests/checkStackblitzTemplates.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { test, expect } from "@playwright/test";
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";

declare global {
interface Window {
StackBlitzSDK: {
openGithubProject: (
templateName: string,
options: { clickToLoad: boolean; newWindow: boolean; origin: string },
) => void;
};
}
}

const directoryPath = path.join(__dirname, "../../../templates/");

fs.readdirSync(directoryPath).forEach((template) => {
test(`Open ${template}`, async ({ page }) => {
test.setTimeout(200000);
const templateName = `shopware/frontends/tree/main/templates/${template}`;
await page.goto("file://" + __dirname + "/pages/blank.html", {
await page.goto(`file://${__dirname}/pages/blank.html`, {
waitUntil: "domcontentloaded",
timeout: 0,
});
Expand All @@ -25,14 +36,14 @@ fs.readdirSync(directoryPath).forEach((template) => {
]);
await page.waitForRequest(
"https://demo-frontends.shopware.store/store-api/context",
),
await expect(page).toHaveURL(
`https://stackblitz.com/github/shopware/frontends/tree/main/templates/${template}?file=README.md`,
);
);
await expect(page).toHaveURL(
`https://stackblitz.com/github/shopware/frontends/tree/main/templates/${template}?file=README.md`,
);

const consoleLogs = [];
const consoleLogs: string[] = [];
page.on("console", (msg) => {
if (msg.type() == "error") {
if (msg.type() === "error") {
console.log(msg.text());
consoleLogs.push(msg.text());
}
Expand Down
13 changes: 6 additions & 7 deletions apps/e2e-tests/tests/createOrder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import { CheckoutPage } from "../page-objects/CheckoutPage";
import { ProductPage } from "../page-objects/ProductPage";
import { CartPage } from "../page-objects/CartPage";
import { LoginForm } from "../page-objects/LoginPage";
import find from "find-up";
export const findEnv = () => find.sync(process.env.ENV_FILE || ".env");
import { faker } from "@faker-js/faker";
import { findEnv } from "../utils/helpers";

require("dotenv").config({ path: findEnv() });
const userEmail = process.env.USER_EMAIL || "[email protected]";
const password = process.env.PASSWORD || "shopware123";
test.setTimeout(50000);

test.describe.only("Create Order", () => {
test.describe("Create Order", () => {
let homePage: HomePage;
let registrationPage: RegisterForm;
let checkoutPage: CheckoutPage;
Expand All @@ -39,8 +38,8 @@ test.describe.only("Create Order", () => {
await homePage.openRegistrationPage();
await page.waitForLoadState("networkidle");
await registrationPage.fillCustomerData(
"e2e " + faker.person.firstName(),
"e2e " + faker.person.lastName(),
`e2e ${faker.person.firstName()}`,
`e2e ${faker.person.lastName()}`,
faker.internet.exampleEmail(),
faker.internet.password(),
);
Expand Down Expand Up @@ -82,8 +81,8 @@ test.describe.only("Create Order", () => {
await checkoutPage.goToCheckout();
await checkoutPage.checkNotCreateAccount();
await checkoutPage.fillGuestUserData(
"e2e " + faker.person.firstName(),
"e2e " + faker.person.lastName(),
`e2e ${faker.person.firstName()}`,
`e2e ${faker.person.lastName()}`,
faker.internet.exampleEmail(),
faker.location.street(),
faker.location.zipCode(),
Expand Down
Loading

0 comments on commit c762fd5

Please sign in to comment.