This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from WordPress/limit-hydration
Limit the hydration to block when client-side transitions are deactivated
- Loading branch information
Showing
19 changed files
with
542 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Playwright Tests | ||
on: pull_request | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 14 | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Build | ||
run: npm run build | ||
- name: Run Playwright tests | ||
run: npx playwright test | ||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
node_modules | ||
build | ||
vendor | ||
composer.lock | ||
composer.lock | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>toVdom - full</title> | ||
<meta itemprop="wp-client-side-transitions" content="active" /> | ||
</head> | ||
<body> | ||
<div wp-ignore> | ||
<wp-show when="state.falseValue"> | ||
<span data-testid="inside wp-ignore"> | ||
This should not be shown because we are in full mode. | ||
</span> | ||
</wp-show> | ||
</div> | ||
|
||
<script src="../build/e2e/tovdom.js"></script> | ||
<script src="../build/runtime.js"></script> | ||
<script src="../build/vendors.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { join } from 'path'; | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test.describe('toVdom - full', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('file://' + join(__dirname, 'tovdom-full.html')); | ||
}); | ||
|
||
test('it should stop when it founds wp-ignore', async ({ page }) => { | ||
const el = page.getByTestId('inside wp-ignore'); | ||
await expect(el).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>toVdom - islands</title> | ||
</head> | ||
<body> | ||
<div> | ||
<wp-show when="state.falseValue"> | ||
<span data-testid="not inside an island"> | ||
This should be shown because it is inside an island. | ||
</span> | ||
</wp-show> | ||
|
||
<div wp-island> | ||
<wp-show when="state.falseValue"> | ||
<span data-testid="inside an island"> | ||
This should not be shown because it is inside an island. | ||
</span> | ||
</wp-show> | ||
</div> | ||
|
||
<div wp-island> | ||
<div wp-ignore> | ||
<wp-show when="state.falseValue"> | ||
<span | ||
data-testid="inside an inner block of an isolated island" | ||
> | ||
This should be shown because it is inside an inner | ||
block of an isolated island. | ||
</span> | ||
</wp-show> | ||
</div> | ||
</div> | ||
|
||
<div wp-island> | ||
<div wp-island> | ||
<wp-show | ||
when="state.falseValue" | ||
data-testid="island inside another island" | ||
> | ||
<span> | ||
This should not have two template wrappers because | ||
that means we hydrated twice. | ||
</span> | ||
</wp-show> | ||
</div> | ||
</div> | ||
|
||
<div wp-island> | ||
<div> | ||
<div wp-island wp-ignore> | ||
<wp-show when="state.falseValue"> | ||
<span | ||
data-testid="island inside inner block of isolated island" | ||
> | ||
This should not be shown because even though it | ||
is inside an inner block of an isolated island, | ||
it's inside an new island. | ||
</span> | ||
</wp-show> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="../build/e2e/tovdom.js"></script> | ||
<script src="../build/runtime.js"></script> | ||
<script src="../build/vendors.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { join } from 'path'; | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test.describe('toVdom - isands', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('file://' + join(__dirname, 'tovdom-islands.html')); | ||
}); | ||
|
||
test('directives that are not inside islands should not be hydrated', async ({ | ||
page, | ||
}) => { | ||
const el = page.getByTestId('not inside an island'); | ||
await expect(el).toBeVisible(); | ||
}); | ||
|
||
test('directives that are inside islands should be hydrated', async ({ | ||
page, | ||
}) => { | ||
const el = page.getByTestId('inside an island'); | ||
await expect(el).toBeHidden(); | ||
}); | ||
|
||
test('directives that are inside inner blocks of isolated islands should not be hydrated', async ({ | ||
page, | ||
}) => { | ||
const el = page.getByTestId( | ||
'inside an inner block of an isolated island' | ||
); | ||
await expect(el).toBeVisible(); | ||
}); | ||
|
||
test('directives inside islands should not be hydrated twice', async ({ | ||
page, | ||
}) => { | ||
const el = page.getByTestId('island inside another island'); | ||
const templates = el.locator('template'); | ||
expect(await templates.count()).toEqual(1); | ||
}); | ||
|
||
test('islands inside inner blocks of isolated islands should be hydrated', async ({ | ||
page, | ||
}) => { | ||
const el = page.getByTestId( | ||
'island inside inner block of isolated island' | ||
); | ||
await expect(el).toBeHidden(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import wpx from '../src/runtime/wpx'; | ||
|
||
wpx({ | ||
state: { | ||
falseValue: false, | ||
}, | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import type { PlaywrightTestConfig } from '@playwright/test'; | ||
import { devices } from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
const config: PlaywrightTestConfig = { | ||
testDir: './e2e', | ||
/* Maximum time one test can run for. */ | ||
timeout: 30 * 1000, | ||
expect: { | ||
/** | ||
* Maximum time expect() should wait for the condition to be met. | ||
* For example in `await expect(locator).toHaveText();` | ||
*/ | ||
timeout: 5000, | ||
}, | ||
/* 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: { | ||
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ | ||
actionTimeout: 0, | ||
/* 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: { | ||
// channel: 'msedge', | ||
// }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { | ||
// channel: 'chrome', | ||
// }, | ||
// }, | ||
], | ||
|
||
/* Folder for test artifacts such as screenshots, videos, traces, etc. */ | ||
// outputDir: 'test-results/', | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// port: 3000, | ||
// }, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.