Skip to content

Commit

Permalink
Add arbitrary c8 ignores
Browse files Browse the repository at this point in the history
The Node 20.10 upgrade suddenly started marking them as uncovered.
It's unclear what exactly the cause is, but there's a bug on file
that might be related:
istanbuljs/v8-to-istanbul#236
  • Loading branch information
Vinnl committed Feb 21, 2024
1 parent eec01f2 commit 40c4fd9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/app/(proper_react)/(redesign)/GaScript.tsx
Expand Up @@ -12,7 +12,7 @@ export type Props = {
};

export const GaScript = ({ nonce }: Props) => {
/* c8 ignore next 2 */
/* c8 ignore next */
const ga4MeasurementId = CONST_GA4_MEASUREMENT_ID || "G-CXG8K4KW4P";

return typeof navigator !== "undefined" && navigator.doNotTrack !== "1" ? (
Expand All @@ -21,6 +21,8 @@ export const GaScript = ({ nonce }: Props) => {
nonce={nonce}
/>
) : (
/* c8 ignore next 2 */
// `navigator` is always defined in tests, thanks to jsdom:
<></>
);
};
23 changes: 20 additions & 3 deletions src/app/components/client/ComboBox.tsx
Expand Up @@ -34,6 +34,9 @@ function ComboBox(props: ComboBoxProps) {
);

useEffect(() => {
/* c8 ignore next 5 */
// This does get hit by unit tests, but for some reason, since the Node
// 20.10 upgrade, it (and this comment) no longer gets marked as such:
if (inputProps.value === "") {
state.close();
}
Expand All @@ -44,14 +47,28 @@ function ComboBox(props: ComboBoxProps) {
<div className={styles.comboBox}>
<label {...labelProps} className={styles.inputLabel}>
{label}
{isRequired ? <span aria-hidden="true">*</span> : ""}
{isRequired ? (
<span aria-hidden="true">*</span>
) : (
/* c8 ignore next 4 */
// This does get hit by unit tests, but for some reason, since the
// Node 20.10 upgrade, it (and this comment) no longer gets marked
// as such:
""
)}
</label>
<input
{...inputProps}
ref={inputRef}
className={`${styles.inputField} ${
!inputProps.value ? styles.noValue : ""
} ${isInvalid ? styles.hasError : ""}`}
!inputProps.value
? /* c8 ignore next 4 */
// This does get hit by unit tests, but for some reason, since
// the Node 20.10 upgrade, it (and this comment) no longer gets
// marked as such:
styles.noValue
: ""
} ${isInvalid ? /* c8 ignore next */ styles.hasError : ""}`}
/>
{isInvalid && typeof errorMessage === "string" && (
<div {...errorMessageProps} className={styles.inputMessage}>
Expand Down
24 changes: 22 additions & 2 deletions src/app/components/client/FixNavigation.tsx
Expand Up @@ -146,18 +146,30 @@ export const Steps = (props: {
</li>
<li
aria-current={
/* c8 ignore next 5 */
// This line should be covered by unit tests, but since the Node 20.10
// upgrade, it's been intermittently marking this (and this comment)
// as uncovered.
props.currentSection === "security-recommendations"
? "step"
: undefined
}
className={`${styles.navigationItem} ${
/* c8 ignore next 5 */
// This line should be covered by unit tests, but since the Node 20.10
// upgrade, it's been intermittently marking this (and this comment)
// as uncovered.
props.currentSection === "security-recommendations"
? styles.active
: ""
} ${
hasCompletedStepSection(props.data, "SecurityTips")
? styles.isCompleted
: ""
: /* c8 ignore next 4 */
// This line should be covered by unit tests, but since the Node 20.10
// upgrade, it's been intermittently marking this (and this comment)
// as uncovered.
""
}`}
>
<div className={styles.stepIcon}>
Expand Down Expand Up @@ -202,7 +214,11 @@ const StepImage = (props: {
? stepHighRiskDataBreachesIcon
: props.section === "LeakedPasswords"
? stepLeakedPasswordsIcon
: stepSecurityRecommendationsIcon;
: /* c8 ignore next 4 */
// This line should be covered by unit tests, but since the Node
// 20.10 upgrade, it's been intermittently marking this (and this
// comment) as uncovered.
stepSecurityRecommendationsIcon;

return <Image src={src} alt="" width={22} height={22} />;
};
Expand All @@ -212,6 +228,10 @@ function calculateActiveProgressBarPosition(section: Props["currentSection"]) {
return styles.beginHighRiskDataBreaches;
} else if (section === "leaked-passwords") {
return styles.beginLeakedPasswords;
/* c8 ignore next 5 */
// This line should be covered by unit tests, but since the Node 20.10
// upgrade, it's been intermittently marking this (and this comment) as
// uncovered.
} else if (section === "security-recommendations") {
return styles.beginSecurityRecommendations;
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/app/functions/server/dashboard.ts
Expand Up @@ -446,6 +446,9 @@ function sanitizeDataPoints(
}

export function getDataPointReduction(summary: DashboardSummary): number {
// The `if` statement is totally covered by unit tests, but for some reason,
// since the upgrade to Node 20.10, it doesn't get marked as covered anymore:
/* c8 ignore next */
if (summary.totalDataPointsNum <= 0) return 100;
return Math.round(
(summary.dataBrokerTotalDataPointsNum / summary.totalDataPointsNum) * 100,
Expand Down
9 changes: 9 additions & 0 deletions src/app/functions/universal/guidedExperienceBreaches.ts
Expand Up @@ -48,14 +48,23 @@ export function getGuidedExperienceBreaches(
guidedExperienceBreaches.highRisk.ssnBreaches.push(breach);
}

// This does get covered by unit tests, but for some reason, since the
// upgrade to Node 20.10, it doesn't get marked as covered anymore:
/* c8 ignore next 3 */
if (isUnresolvedDataBreachClass(breach, BreachDataTypes.CreditCard)) {
guidedExperienceBreaches.highRisk.creditCardBreaches.push(breach);
}

// This does get covered by unit tests, but for some reason, since the
// upgrade to Node 20.10, it doesn't get marked as covered anymore:
/* c8 ignore next 3 */
if (isUnresolvedDataBreachClass(breach, BreachDataTypes.PIN)) {
guidedExperienceBreaches.highRisk.pinBreaches.push(breach);
}

// This does get covered by unit tests, but for some reason, since the
// upgrade to Node 20.10, it doesn't get marked as covered anymore:
/* c8 ignore next 3 */
if (isUnresolvedDataBreachClass(breach, BreachDataTypes.BankAccount)) {
guidedExperienceBreaches.highRisk.bankBreaches.push(breach);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/hooks/useGa.ts
Expand Up @@ -19,8 +19,8 @@ interface InitGaProps {
}

const initGa4 = ({ ga4MeasurementId, debugMode }: InitGaProps) => {
/* c8 ignore next 4 */
// Never run in tests:
/* c8 ignore next 3 */
if (debugMode) {
console.info("Initialize GA4");
}
Expand Down Expand Up @@ -59,9 +59,9 @@ export const useGa = (): {
// Enable upload only if the user has not opted out of tracking.
const uploadEnabled = navigator.doNotTrack !== "1";

/* c8 ignore next 7 */
// Never run in tests:
if (!uploadEnabled) {
// Never run in tests:
/* c8 ignore next 3 */
if (debugMode) {
console.info("Did not initialize GA4 due to DoNotTrack.");
}
Expand Down

0 comments on commit 40c4fd9

Please sign in to comment.