Skip to content
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
80 changes: 80 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: E2E Tests

on:
pull_request:
paths:
- "projects/project-generator/**"
push:
branches:
- main
paths:
- "projects/project-generator/**"

jobs:
e2e-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10.13.1

- name: Install dependencies
run: pnpm install

- name: Build project generator
run: pnpm --filter create-vite-apollo-fs build

- name: Generate test project
run: |
chmod +x ./projects/project-generator/dist/generator.js
./projects/project-generator/dist/generator.js --destinationPath=myProject --apiName=my-api --webUiName=my-web-ui

- name: Install dependencies in generated project
run: |
cd myProject
pnpm install

- name: Start development server in background
run: |
cd myProject
pnpm dev &
echo $! > dev_server.pid

- name: Wait for server to be ready
run: |
timeout 60 bash -c 'until curl -f http://localhost:5173; do sleep 2; done'

- name: Install Playwright browsers and dependencies
run: |
cd projects/project-generator-e2e
npx playwright install --with-deps

- name: Run E2E tests
run: |
cd projects/project-generator-e2e
npm run test

- name: Stop development server
if: always()
run: |
if [ -f myProject/dev_server.pid ]; then
kill $(cat myProject/dev_server.pid) || true
fi

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: projects/project-generator-e2e/playwright-report/
44 changes: 44 additions & 0 deletions pnpm-lock.yaml

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

Empty file.
2 changes: 1 addition & 1 deletion projects/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../tsconfig-base.json",
"extends": "../tsconfig.base.json",
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022"],
Expand Down
7 changes: 7 additions & 0 deletions projects/project-generator-e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Playwright
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
13 changes: 13 additions & 0 deletions projects/project-generator-e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "project-generator-e2e",
"version": "1.0.0",
"scripts": {
"test": "playwright test",
"show-report": "playwright show-report"
},
"devDependencies": {
"@playwright/test": "^1.54.1",
"@types/node": "^24.1.0"
},
"packageManager": "pnpm@10.13.1"
}
79 changes: 79 additions & 0 deletions projects/project-generator-e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* 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:3000',

/* 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 local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://localhost:3000',
// reuseExistingServer: !process.env.CI,
// },
});
28 changes: 28 additions & 0 deletions projects/project-generator-e2e/tests/can-add-user.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect, test } from "@playwright/test";
import { url } from "./url";

test("can add user", async ({ page }) => {
await page.goto(url);

// Check if the add user input and button are visible
const addUserInput = page.locator('input[data-testid="add-user-input"]');
const addUserButton = page.locator('button[data-testid="add-user-button"]');

await expect(addUserInput).toBeVisible();
await expect(addUserButton).toBeVisible();

// Add a new user
const newUserName = "TestUser";
await addUserInput.fill(newUserName);
await addUserButton.click();

await page.waitForTimeout(3000);

// Verify the new user is added to the list
const usersList = page.locator('ul[data-testid="users-list"]');
const newUserLocator = usersList
.locator(`li:has-text("${newUserName}")`)
.first();

await expect(newUserLocator).toBeVisible();
});
13 changes: 13 additions & 0 deletions projects/project-generator-e2e/tests/has-greetings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, test } from "@playwright/test";
import { url } from "./url";

test("hello query has one of known greetings", async ({ page }) => {
const knownGreetings = ["Hello!", "Hi there!", "Welcome!", "Good day!"];
await page.goto(url);
const helloQuery = page.locator('span[data-testid="greetings-subscription"]');
await expect(helloQuery).toBeVisible();
await page.waitForTimeout(3000);
const helloText = await helloQuery.textContent();
expect(helloText).toBeDefined();
expect(knownGreetings).toContain(helloText);
});
7 changes: 7 additions & 0 deletions projects/project-generator-e2e/tests/has-title.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, test } from "@playwright/test";
import { url } from "./url";

test("has title", async ({ page }) => {
await page.goto(url);
await expect(page).toHaveTitle("Vite + React + TS");
});
19 changes: 19 additions & 0 deletions projects/project-generator-e2e/tests/has-users.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test, { expect } from "@playwright/test";
import { url } from "./url";

test("has users", async ({ page }) => {
await page.goto(url);
const usersList = page.locator('ul[data-testid="users-list"]');
await expect(usersList).toBeVisible();

// Check if the list has at least one user
const usersCount = await usersList.locator("li").count();
expect(usersCount).toBeGreaterThan(0);

// Optionally, check for specific users
const knownUsers = ["John Doe", "Jane Smith"];
for (const user of knownUsers) {
const userLocator = usersList.locator(`li:has-text("${user}")`);
await expect(userLocator).toBeVisible();
}
});
1 change: 1 addition & 0 deletions projects/project-generator-e2e/tests/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const url = "http://localhost:5173/movies-with-actors";
17 changes: 17 additions & 0 deletions projects/project-generator-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"lib": ["ES2022"],
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"types": ["node", "@playwright/test"]
},
"include": ["tests/**/*", "playwright.config.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion projects/project-generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async function generateWebUiProject(config: ProjectConfig) {
// Add graphqlLoader() to plugins array if not present
viteConfig = viteConfig.replace(
/(plugins:\s*\[)([^\]]*)\]/,
(match: string, p1: string, p2: string) => {
(_: string, p1: string, p2: string) => {
let plugins = p2.trim().replace(/,$/, "");
if (!plugins.includes("graphqlLoader()"))
plugins += ", graphqlLoader()";
Expand Down
Loading