Skip to content

Commit

Permalink
Testing...
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwalton committed Aug 1, 2024
1 parent dc0ee2b commit 667086b
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Run server
run: npm run test:server &
- name: Run e2e tests for chrome
run: npm run test:e2e -- --browsers=chrome
run: npm run test:e2e -- --browsers=chrome --metrics=FCP
firefox-tests:
name: Run Firefox e2e tests
# Runs best on macos for CI as linux requires extra setup
Expand All @@ -48,7 +48,7 @@ jobs:
- name: Run server
run: npm run test:server &
- name: Run e2e tests for firefox
run: npm run test:e2e -- --browsers=firefox
run: npm run test:e2e -- --browsers=firefox --metrics=FCP
safari-tests:
name: Run Safari e2e tests
# Requires macos
Expand All @@ -63,4 +63,4 @@ jobs:
- name: Run server
run: npm run test:server &
- name: Run e2e tests for safari
run: npm run test:e2e -- --browsers=safari
run: npm run test:e2e -- --browsers=safari --metrics=FCP
22 changes: 19 additions & 3 deletions test/e2e/onFCP-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ assert.strictEqual = function (actual, expected, message) {

describe('onFCP()', async function () {
// Retry all tests in this suite up to 2 times.
this.retries(2);
// this.retries(2);

let browserSupportsFCP;
before(async function () {
Expand Down Expand Up @@ -131,10 +131,26 @@ describe('onFCP()', async function () {
assert.strictEqual(bfcacheRestoreBeacons.length, 0);
});

it('does not report if the document was hidden at page load time', async function () {
it.only('does not report if the document was hidden at page load time', async function () {
if (!browserSupportsFCP) this.skip();

await navigateTo('/test/fcp?hidden=1', {readyState: 'interactive'});
console.log(await navigateTo('/test/fcp?hidden=1', {readyState: 'complete'}));

// await browser.pause(1000);

const foo = await browser.execute(() => self.foo);
console.log({foo});

const foo2 = await browser.execute(() => self.foo2);
console.log({foo2});

const wv = await browser.execute(() => self.wv);

console.log({wv});
assert.equal(wv, true);

const vs = await browser.execute(() => self.document.visibilityState);
console.log({vs});

await stubVisibilityChange('visible');

Expand Down
14 changes: 12 additions & 2 deletions test/utils/domReadyState.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
*/
export function domReadyState(state) {
return browser.executeAsync(async (state, done) => {
const logs = [];
self.foo = document.readyState;
logs.push(['foo', document.readyState]);

await new Promise((resolve) => {
logs.push(['foo:promise', document.readyState]);
if (document.readyState === 'complete' || document.readyState === state) {
resolve();
} else {
Expand All @@ -36,10 +41,15 @@ export function domReadyState(state) {
});
}
});
if (state !== 'loading' && self.__readyPromises) {
// logs.push(self.__toSafeObject(self.__readyPromises));
if (state !== 'loading') {
self.foo2 = document.readyState;
logs.push(['foo2', document.readyState]);
await Promise.all(self.__readyPromises);
}
self.foo3 = document.readyState;
logs.push(['foo3', document.readyState]);
// Queue a task so this resolves after any event callback run.
setTimeout(done, 0);
setTimeout(() => done(logs), 0);
}, state);
}
3 changes: 2 additions & 1 deletion test/utils/navigateTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export async function navigateTo(urlPath, opts) {
});
}

console.log('navigateTo', opts);
if (opts?.readyState) {
await domReadyState(opts.readyState);
return await domReadyState(opts.readyState);
}
}
22 changes: 22 additions & 0 deletions test/views/blank.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script type="module">
document.addEventListener('DOMContentLoaded', () => {
console.log('DCL');
});
document.addEventListener('readystatechange', () => {
console.log('readystatechange', document.readyState);
});
</script>


<script type="module">
// import '/dist/foo.js';
// import '/dist/bar.js';
await import('/dist/foo.js');
await import('/dist/bar.js');
console.log('done');
</script>
46 changes: 46 additions & 0 deletions test/views/fcp.njk
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,51 @@

<p><a id="navigate-away" href="https://example.com">Navigate away</a></p>

<script>
(async function() {
document.addEventListener('DOMContentLoaded', () => {
console.log('DCL');
});
const state = 'interactive';
const logs = [];
self.foo = document.readyState;
logs.push(['foo', document.readyState]);
await new Promise((resolve) => {
logs.push(['foo:promise', document.readyState]);
if (document.readyState === 'complete' || document.readyState === state) {
resolve();
} else {
document.addEventListener('readystatechange', () => {
console.log('readystatechange', document.readyState);
if (
document.readyState === state ||
document.readyState === 'complete'
) {
resolve();
}
});
}
});
// logs.push(self.__toSafeObject(self.__readyPromises));
// if (state !== 'loading') {
self.foo2 = document.readyState;
logs.push(['foo2', document.readyState]);
await Promise.all(self.__readyPromises);
// }
self.foo3 = document.readyState;
logs.push(['foo3', document.readyState]);
// Queue a task so this resolves after any event callback run.
setTimeout(() => console.log(logs), 0);
})();
</script>

<script type="module">
console.log('before __testImport');
const {onFCP} = await __testImport('{{ modulePath }}');
console.log('after __testImport');
onFCP((fcp) => {
// Log for easier manual testing.
Expand All @@ -37,5 +80,8 @@
// Test sending the metric to an analytics endpoint.
navigator.sendBeacon(`/collect`, JSON.stringify(__toSafeObject(fcp)));
}, {reportAllChanges: self.__reportAllChanges});
console.log('wc', self.wv = true);
</script>
{% endblock %}
1 change: 1 addition & 0 deletions test/views/layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
const importPromise = import(modulePath);
self.__readyPromises.push(importPromise);
console.log('self.__readyPromises.push(importPromise)', self.__readyPromises.length);
return await importPromise;
};
Expand Down

0 comments on commit 667086b

Please sign in to comment.