-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* e2e test case: composition4 * yarn add --development history * e2e test: spa1 * Mark test failure as expected Co-authored-by: Andrew Hyndman <ahyndman@dropbox.com>
- Loading branch information
Showing
6 changed files
with
141 additions
and
0 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
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,18 @@ | ||
<head> | ||
<script src="/dist/index.min.js"></script> | ||
</head> | ||
|
||
<body> | ||
<h1 id="h1">Hello world!</h1> | ||
|
||
<script src="/analytics.js"></script> | ||
<script> | ||
const asyncScript = document.createElement('script'); | ||
asyncScript.src = '/mutation.js'; | ||
|
||
fetch('/api?delay=500') | ||
.then(() => new Promise((resolve) => window.setTimeout(resolve, 100))) | ||
.then(() => fetch('/api?delay=500')) | ||
.then(() => document.head.appendChild(asyncScript)); | ||
</script> | ||
</body> |
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 @@ | ||
import {test, expect} from '@playwright/test'; | ||
|
||
import {FUDGE} from '../../util/constants'; | ||
import {entryCountIs, getEntries} from '../../util/entries'; | ||
|
||
const PAGELOAD_DELAY = 200; | ||
const AJAX_DELAY = 500; | ||
const TIMEOUT_DELAY = 100; | ||
|
||
test.describe('TTVC', () => { | ||
test('ajax request > short timeout > ajax request > mutation', async ({page}) => { | ||
test.fail(); // requestAllIdleCallback has a bug that can be triggered by a brief idle period | ||
await page.goto(`/test/composition4?delay=${PAGELOAD_DELAY}`, { | ||
waitUntil: 'networkidle', | ||
}); | ||
|
||
await entryCountIs(page, 1); | ||
const entries = await getEntries(page); | ||
expect(entries.length).toBe(1); | ||
|
||
const expectedTtvc = PAGELOAD_DELAY + AJAX_DELAY + TIMEOUT_DELAY + AJAX_DELAY; | ||
expect(entries[0]).toBeGreaterThanOrEqual(expectedTtvc); | ||
expect(entries[0]).toBeLessThanOrEqual(expectedTtvc + FUDGE); | ||
}); | ||
}); |
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,47 @@ | ||
<head> | ||
<script src="/dist/index.min.js"></script> | ||
</head> | ||
|
||
<body> | ||
<h1 id="title"></h1> | ||
<ul id="nav"> | ||
<li><a data-goto="/home" href="#">Home</a></li> | ||
<li><a data-goto="/about" href="#">About</a></li> | ||
</ul> | ||
|
||
<script src="/analytics.js"></script> | ||
<script type="module"> | ||
import {createHashHistory} from '/node_modules/history/history.production.min.js'; | ||
const history = createHashHistory(); | ||
|
||
// render the title based on current location | ||
const render = () => { | ||
const title = document.getElementById('title'); | ||
// title.innerText = 'Loading...'; | ||
title.innerText = { | ||
'/home': 'Home', | ||
'/about': 'About', | ||
}[history.location.pathname]; | ||
}; | ||
|
||
// set initial path to /home | ||
history.push('/home'); | ||
render(); | ||
|
||
// set up link click handlers | ||
const anchors = document.querySelectorAll('a'); | ||
anchors.forEach((anchor) => { | ||
const url = anchor.dataset.goto; | ||
anchor.addEventListener('click', (event) => { | ||
event.preventDefault(0); | ||
history.push(url); | ||
}); | ||
}); | ||
|
||
// handle navigation | ||
history.listen(() => { | ||
document.documentElement.dispatchEvent(new Event('locationchange', {bubbles: true})); | ||
render(); | ||
}); | ||
</script> | ||
</body> |
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,36 @@ | ||
import {test, expect} from '@playwright/test'; | ||
|
||
import {FUDGE} from '../../util/constants'; | ||
import {entryCountIs, getEntries} from '../../util/entries'; | ||
|
||
const PAGELOAD_DELAY = 200; | ||
|
||
test.describe('TTVC', () => { | ||
test.describe('single page app: hash router + sync mutation', () => { | ||
test.beforeEach(async ({page}) => { | ||
await page.goto(`/test/spa1?delay=${PAGELOAD_DELAY}`, { | ||
waitUntil: 'networkidle', | ||
}); | ||
}); | ||
|
||
test('initial pageload', async ({page}) => { | ||
const entries = await getEntries(page); | ||
|
||
expect(entries.length).toBe(1); | ||
expect(entries[0]).toBeGreaterThanOrEqual(PAGELOAD_DELAY); | ||
expect(entries[0]).toBeLessThanOrEqual(PAGELOAD_DELAY + FUDGE); | ||
}); | ||
|
||
test('SPA navigation', async ({page}) => { | ||
test.fail(); // we need to correctly set start time on each navigation! | ||
// trigger a navigation | ||
await page.click('[data-goto="/about"]'); | ||
|
||
await entryCountIs(page, 2); | ||
const entries = await getEntries(page); | ||
|
||
expect(entries[1]).toBeGreaterThanOrEqual(0); | ||
expect(entries[1]).toBeLessThanOrEqual(0 + FUDGE); | ||
}); | ||
}); | ||
}); |
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