Skip to content

Commit

Permalink
chore: speed up e2e tests
Browse files Browse the repository at this point in the history
Previously:
- test packages are split by features
- yet they all depend on drupal or gatsby app
- so we run most of the tests anyway - as soon as any package change that the app depends on

Now:
- test packages are split by apps
- we spend less time on spinning up gatsby
  • Loading branch information
Leksat committed Oct 16, 2023
1 parent fbfbcdf commit 6e81cee
Show file tree
Hide file tree
Showing 61 changed files with 190 additions and 3,549 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ jobs:
- name: Run unit tests
run: pnpm test:unit

- name: Install Playwright browsers
run: cd packages/tests/_template && pnpm playwright install chromium

- name: Run integration tests
run: pnpm test:integration

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ jobs:
if: startsWith(github.head_ref, 'test-all/') == true
run: pnpm test:unit:all

- name: Install Playwright browsers
run: cd packages/tests/_template && pnpm playwright install chromium

- name: Run integration tests
if: startsWith(github.head_ref, 'test-all/') == false
run: pnpm test:integration
Expand Down
6 changes: 0 additions & 6 deletions .idea/jsLibraryMappings.xml

This file was deleted.

3 changes: 3 additions & 0 deletions apps/silverback-drupal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"dependencies": {
"@-amazeelabs/silverback-cli": "workspace:*",
"@-amazeelabs/silverback_gatsby": "workspace:*",
"@-amazeelabs/silverback_gutenberg": "workspace:*",
"@-amazeelabs/silverback_iframe": "workspace:*",
"@-amazeelabs/silverback_iframe_theme": "workspace:*",
"@-silverback-drupal-config/webform": "workspace:*",
"@-silverback-drupal/gutenberg_custom_blocks": "workspace:*"
},
Expand Down
57 changes: 2 additions & 55 deletions packages/npm/@amazeelabs/silverback-playwright/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
devices,
expect,
PlaywrightTestArgs,
PlaywrightTestConfig,
} from '@playwright/test';
import { expect, PlaywrightTestArgs } from '@playwright/test';
import { execSync } from 'child_process';

export const gatsby = {
Expand Down Expand Up @@ -81,11 +76,10 @@ export const waitForGatsby = async () => {
clearTimeout(timeout);
};

export const resetState = async () => {
export const resetDrupalState = async () => {
execSync(
'pnpm run --filter "@-amazeelabs/silverback-drupal" snapshot-restore',
);
await waitForGatsby();
};

export const drupalLogin = async (
Expand All @@ -104,50 +98,3 @@ export const drupalLogin = async (
export const drupalLogout = async (page: PlaywrightTestArgs['page']) => {
await page.goto(drupal.baseUrl + '/user/logout');
};

export const playwrightConfigDefaults: PlaywrightTestConfig = {
testDir: './specs',
webServer: [
{
command:
'pnpm run --filter "@-amazeelabs/silverback-drupal" start > /tmp/drupal.log 2>&1',
port: 8888,
reuseExistingServer: !process.env.CI,
},
{
command:
'pnpm run --filter "@-amazeelabs/silverback-gatsby" start > /tmp/gatsby.log 2>&1',
port: 8000,
reuseExistingServer: !process.env.CI,
},
],
fullyParallel: true,
forbidOnly: !!process.env.CI,
maxFailures: 1,
retries: process.env.CI ? 1 : 0,
use: {
trace: 'on-first-retry',
},
reporter: 'list',
projects: [
{
name: 'setup',
testMatch: /setup\.ts/,
},
{
name: 'chromium',
testMatch: /\.*.spec\.ts/,
use: { ...devices['Desktop Chrome'] },
dependencies: ['setup'],
},
],
// Initial gatsby build can take long.
timeout: 90_000,
};

export const playwrightConfigMutatingDefaults: PlaywrightTestConfig = {
...playwrightConfigDefaults,
testDir: './specs-mutating',
fullyParallel: false,
workers: 1,
};
26 changes: 0 additions & 26 deletions packages/tests/_template/CHANGELOG.md

This file was deleted.

26 changes: 0 additions & 26 deletions packages/tests/_template/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/tests/_template/playwright.config.mutating.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/tests/_template/playwright.config.ts

This file was deleted.

20 changes: 0 additions & 20 deletions packages/tests/_template/specs-mutating/example.spec.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/tests/_template/specs/example.spec.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/tests/_template/specs/setup.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"name": "@-amazeelabs/silverback-iframe-tests",
"name": "@-amazeelabs/silverback-drupal-tests",
"version": "1.1.79",
"description": "e2e tests for Silverback Iframe solution.",
"author": "Amazee Labs",
"license": "MIT",
"private": true,
"devDependencies": {
"@-amazeelabs/silverback_iframe": "workspace:*",
"@-amazeelabs/silverback_iframe_theme": "workspace:*",
"@-silverback-drupal-config/webform": "workspace:*",
"@-amazeelabs/silverback-drupal": "workspace:*",
"@amazeelabs/eslint-config": "1.4.43",
"@amazeelabs/prettier-config": "1.1.3",
"@amazeelabs/silverback-iframe": "workspace:*",
Expand All @@ -21,10 +19,10 @@
},
"scripts": {
"test:static": "tsc --noEmit && eslint \"**/*.{ts,tsx,js,jsx}\" --ignore-path=\"./.gitignore\" --fix",
"test:integration": "pnpm test:readonly && pnpm test:mutating",
"test:integration": "playwright install chromium && pnpm test:readonly && pnpm test:mutating",
"test:readonly": "playwright test --pass-with-no-tests",
"test:mutating": "playwright test --pass-with-no-tests -c playwright.config.mutating.ts",
"dev": "DEBUG=pw:api pnpm test:readonly --ui",
"dev:readonly": "DEBUG=pw:api pnpm test:readonly --ui",
"dev:mutating": "DEBUG=pw:api pnpm test:mutating --ui"
}
}
10 changes: 10 additions & 0 deletions packages/tests/silverback-drupal/playwright.config.mutating.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from '@playwright/test';

import { config } from './playwright.config';

export default defineConfig({
...config,
testDir: './specs-mutating',
fullyParallel: false,
workers: 1,
});
37 changes: 37 additions & 0 deletions packages/tests/silverback-drupal/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { defineConfig, devices, PlaywrightTestConfig } from '@playwright/test';

export const config: PlaywrightTestConfig = {
testDir: './specs',
webServer: [
{
command:
'pnpm run --filter "@-amazeelabs/silverback-drupal" start > /tmp/drupal.log 2>&1',
port: 8888,
reuseExistingServer: !process.env.CI,
},
],
fullyParallel: true,
forbidOnly: !!process.env.CI,
maxFailures: 1,
retries: process.env.CI ? 1 : 0,
use: {
trace: 'on-first-retry',
},
reporter: 'list',
projects: [
{
name: 'setup',
testMatch: /setup\.ts/,
},
{
name: 'chromium',
testMatch: /\.*.spec\.ts/,
use: { ...devices['Desktop Chrome'] },
dependencies: ['setup'],
},
],
// Initial gatsby build can take long.
timeout: 90_000,
};

export default defineConfig(config);
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
drupal,
drupalLogin,
resetState,
resetDrupalState,
} from '@amazeelabs/silverback-playwright';
import { expect, test } from '@playwright/test';

test.beforeAll(async () => {
await resetState();
await resetDrupalState();
});

test('test gutenberg media entity usage', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
drupal,
drupalLogin,
resetState,
resetDrupalState,
} from '@amazeelabs/silverback-playwright';
import { expect, test } from '@playwright/test';
import { platform } from 'os';

test.beforeAll(async () => {
await resetState();
await resetDrupalState();
});

test('linkit content sorting', async ({ page }) => {
Expand Down Expand Up @@ -188,3 +188,20 @@ test('linkit translations', async ({ page }) => {
page.locator('.block-editor-link-control__search-item-title'),
).not.toHaveText('English page');
});

test('test url autocomplete keyboard selection', async ({ page }) => {
await drupalLogin(page);
await page.goto(`${drupal.baseUrl}/en/node/add/gutenberg_page`);

await page.click('[data-type="core/paragraph"]');
await page.click('button[aria-label="Toggle block inserter"]');
await page.click(':text-is("Teaser")');
await page.fill('[placeholder="Search or type url"]', 'page');
await page.waitForSelector('.block-editor-link-control__search-item');
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
//await page.waitForSelector('.block-editor-link-control__search-item-title');
await expect(
page.locator('.block-editor-link-control__search-item-title'),
).toHaveAttribute('href', /^\//);
});
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/tests/silverback-gatsby-directives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"scripts": {
"serve": "pnpm run --filter @-amazeelabs/silverback-gatsby-directives serve",
"test:integration": "playwright test"
"test:integration": "playwright install chromium && playwright test"
}
}
7 changes: 4 additions & 3 deletions packages/tests/silverback-gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"license": "MIT",
"private": true,
"devDependencies": {
"@-amazeelabs/silverback_gatsby": "workspace:*",
"@-amazeelabs/silverback-drupal": "workspace:*",
"@-amazeelabs/silverback-gatsby": "workspace:*",
"@amazeelabs/eslint-config": "1.4.43",
"@amazeelabs/gatsby-source-silverback": "workspace:*",
"@amazeelabs/prettier-config": "1.1.3",
Expand All @@ -19,10 +20,10 @@
},
"scripts": {
"test:static": "tsc --noEmit && eslint \"**/*.{ts,tsx,js,jsx}\" --ignore-path=\"./.gitignore\" --fix",
"test:integration": "pnpm test:readonly && pnpm test:mutating",
"test:integration": "playwright install chromium && pnpm test:readonly && pnpm test:mutating",
"test:readonly": "playwright test --pass-with-no-tests",
"test:mutating": "playwright test --pass-with-no-tests -c playwright.config.mutating.ts",
"dev": "DEBUG=pw:api pnpm test:readonly --ui",
"dev:readonly": "DEBUG=pw:api pnpm test:readonly --ui",
"dev:mutating": "DEBUG=pw:api pnpm test:mutating --ui"
}
}
10 changes: 8 additions & 2 deletions packages/tests/silverback-gatsby/playwright.config.mutating.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { playwrightConfigMutatingDefaults } from '@amazeelabs/silverback-playwright';
import { defineConfig } from '@playwright/test';

export default defineConfig(playwrightConfigMutatingDefaults);
import { config } from './playwright.config';

export default defineConfig({
...config,
testDir: './specs-mutating',
fullyParallel: false,
workers: 1,
});
Loading

0 comments on commit 6e81cee

Please sign in to comment.