Skip to content

Commit

Permalink
Testing for only CLS values in latest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
SETHULAKSHMI-PM committed May 20, 2024
1 parent 2c639c8 commit d1dd75e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
26 changes: 13 additions & 13 deletions lib/webVitals.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @flow

// $FlowFixMe Flow doesn't find the file. Let's ignore this for now.
import {onINP} from 'web-vitals';
import {onCLS} from 'web-vitals';
import type {PageLoadBeacon} from './types';
import {pageLoadStartTimestamp} from './timings';
import {reportCustomEvent} from './customEvents';
import vars from './vars';

interface Metric {
name: 'INP';
name: 'CLS';

value: number;
id?: string;
Expand Down Expand Up @@ -37,20 +37,20 @@ export function addWebVitals(beacon: PageLoadBeacon) {
// if (onFID) {
// onFID(onMetric, true);
// }
if (onINP) {
onINP(onMetric, true);
}
// if (onCLS) {
// onCLS(onMetricWithoutRounding, true);
// if (onINP) {
// onINP(onMetric, true);
// }

function onMetric(metric: Metric) {
beacon['t_' + metric.name.toLocaleLowerCase()] = Math.round(metric.value);
reportExtraMetrics(metric);
if (onCLS) {
onCLS(onMetricWithoutRounding, true);
}

// function onMetricWithoutRounding(metric: Metric) {
// beacon['t_' + metric.name.toLocaleLowerCase()] = metric.value;
// function onMetric(metric: Metric) {
// beacon['t_' + metric.name.toLocaleLowerCase()] = Math.round(metric.value);
// reportExtraMetrics(metric);
// }

function onMetricWithoutRounding(metric: Metric) {
beacon['t_' + metric.name.toLocaleLowerCase()] = metric.value;
reportExtraMetrics(metric);
}
}
2 changes: 1 addition & 1 deletion protractor.saucelabs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function newSaucelabsCapability(browserName, version, platform) {
browserName,
version,
platform,
name: 'Testing for only INP values',
name: 'Testing for only CLS values',
'tunnel-identifier': 'github-action-tunnel',
build: process.env.GITHUB_RUN_NUMBER
};
Expand Down
20 changes: 10 additions & 10 deletions test/e2e/12_webvitalsAsCustomEvent/webvitalsAsCustomEvent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ describe('12_webvitalsAsCustomEvent', () => {
// cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
// });

// expectOneMatching(beacons, beacon => {
// cexpect(beacon.ty).to.equal('cus');
// cexpect(beacon.ts).to.be.a('string');
// cexpect(beacon.n).to.equal('instana-webvitals-CLS');
// cexpect(beacon.l).to.be.a('string');
// cexpect(beacon.pl).to.equal(pageLoadBeacon.t);
// cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
// });

expectOneMatching(beacons, beacon => {
cexpect(beacon.ty).to.equal('cus');
cexpect(beacon.ts).to.be.a('string');
cexpect(beacon.n).to.equal('instana-webvitals-INP');
cexpect(beacon.n).to.equal('instana-webvitals-CLS');
cexpect(beacon.l).to.be.a('string');
cexpect(beacon.pl).to.equal(pageLoadBeacon.t);
cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
});

// expectOneMatching(beacons, beacon => {
// cexpect(beacon.ty).to.equal('cus');
// cexpect(beacon.ts).to.be.a('string');
// cexpect(beacon.n).to.equal('instana-webvitals-INP');
// cexpect(beacon.l).to.be.a('string');
// cexpect(beacon.pl).to.equal(pageLoadBeacon.t);
// cexpect(beacon.m_id).to.match(/^v\d+(-\d+)+$/);
// });
});
});
});
Expand Down

0 comments on commit d1dd75e

Please sign in to comment.