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 667086b commit b7ee3ea
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 73 deletions.
18 changes: 1 addition & 17 deletions test/e2e/onFCP-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,7 @@ describe('onFCP()', async function () {
it.only('does not report if the document was hidden at page load time', async function () {
if (!browserSupportsFCP) this.skip();

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});
console.log(await navigateTo('/test/fcp?hidden=1', {readyState: 'interactive'}));

await stubVisibilityChange('visible');

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

await new Promise((resolve) => {
logs.push(['foo:promise', document.readyState]);
logs.push(['foo:promise', self.wv, document.readyState]);
if (document.readyState === 'complete' || document.readyState === state) {
resolve();
} else {
Expand All @@ -41,15 +40,14 @@ export function domReadyState(state) {
});
}
});
// logs.push(self.__toSafeObject(self.__readyPromises));
if (state !== 'loading') {
self.foo2 = document.readyState;
logs.push(['foo2', document.readyState]);
logs.push(['foo2', self.wv, 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.
logs.push(['foo3', self.wv, document.readyState]);
logs.push(['vs', document.visibilityState]);

// Queue a task so this resolves after any event callbacks run.
setTimeout(() => done(logs), 0);
}, state);
}
1 change: 0 additions & 1 deletion test/utils/navigateTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export async function navigateTo(urlPath, opts) {
});
}

console.log('navigateTo', opts);
if (opts?.readyState) {
return await domReadyState(opts.readyState);
}
Expand Down
46 changes: 1 addition & 45 deletions test/views/fcp.njk
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,8 @@

<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 @@ -81,7 +38,6 @@
navigator.sendBeacon(`/collect`, JSON.stringify(__toSafeObject(fcp)));
}, {reportAllChanges: self.__reportAllChanges});
console.log('wc', self.wv = true);
self.wv = true;
</script>
{% endblock %}
1 change: 0 additions & 1 deletion test/views/layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@
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 b7ee3ea

Please sign in to comment.