From 6a2d76460cfd7ac26ef87a2dc4713ffb71c449d8 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Thu, 3 Apr 2025 20:33:57 +0100 Subject: [PATCH] chore(coverage): migrate from istanbul to c8 ignore comments Replace all instances of istanbul ignore comments with c8 ignore syntax across multiple files in the codebase. This change maintains the same code coverage exclusions while updating to the newer c8 coverage tool format. The changes include: - Converting single-line ignores to c8 ignore start/stop blocks - Updating existing ignore comments to maintain their original purpose - Preserving the explanatory comments for why certain sections are ignored --- .../tmp-toolkit-helpers/src/util/directories.ts | 3 ++- .../tmp-toolkit-helpers/src/util/type-brands.ts | 3 ++- packages/aws-cdk/lib/api/logs/logs-monitor.ts | 3 ++- packages/aws-cdk/lib/api/util/rwlock.ts | 15 ++++++++++----- packages/aws-cdk/lib/cli/cli.ts | 3 ++- packages/aws-cdk/lib/cli/pretty-print-error.ts | 2 ++ packages/aws-cdk/lib/cli/util/npm.ts | 3 ++- packages/aws-cdk/lib/cli/version.ts | 3 ++- packages/aws-cdk/lib/commands/context.ts | 3 ++- packages/aws-cdk/lib/commands/init/init.ts | 3 ++- 10 files changed, 28 insertions(+), 13 deletions(-) diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/src/util/directories.ts b/packages/@aws-cdk/tmp-toolkit-helpers/src/util/directories.ts index 7ae5b2b9b..beb93e8a9 100644 --- a/packages/@aws-cdk/tmp-toolkit-helpers/src/util/directories.ts +++ b/packages/@aws-cdk/tmp-toolkit-helpers/src/util/directories.ts @@ -20,10 +20,11 @@ export function cdkHomeDir() { try { let userInfoHome: string | undefined = os.userInfo().homedir; // Node returns this if the user doesn't have a home directory - /* istanbul ignore if: will not happen in normal setups */ + /* c8 ignore start */ // will not happen in normal setups if (userInfoHome == '/var/empty') { userInfoHome = undefined; } + /* c8 ignore stop */ home = path.join((userInfoHome ?? os.homedir()).trim(), '.cdk'); } catch { } diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/src/util/type-brands.ts b/packages/@aws-cdk/tmp-toolkit-helpers/src/util/type-brands.ts index d6d6c7672..9040eae71 100644 --- a/packages/@aws-cdk/tmp-toolkit-helpers/src/util/type-brands.ts +++ b/packages/@aws-cdk/tmp-toolkit-helpers/src/util/type-brands.ts @@ -37,9 +37,10 @@ export type Branded = T & Brand; * values which are branded by construction (really just an elaborate * way to write 'as'). */ -/* c8 ignore next 3 */ +/* c8 ignore start */ export function createBranded>(value: TypeUnderlyingBrand): A { return value as A; } +/* c8 ignore stop */ type TypeUnderlyingBrand = A extends Branded ? T : never; diff --git a/packages/aws-cdk/lib/api/logs/logs-monitor.ts b/packages/aws-cdk/lib/api/logs/logs-monitor.ts index 91d220eec..376c7e0e1 100644 --- a/packages/aws-cdk/lib/api/logs/logs-monitor.ts +++ b/packages/aws-cdk/lib/api/logs/logs-monitor.ts @@ -146,10 +146,11 @@ export class CloudWatchLogEventMonitor { private async tick(): Promise { // excluding from codecoverage because this // doesn't always run (depends on timing) - /* c8 ignore next */ + /* c8 ignore start */ if (!this.monitorId) { return; } + /* c8 ignore stop */ try { const events = flatten(await this.readNewEvents()); diff --git a/packages/aws-cdk/lib/api/util/rwlock.ts b/packages/aws-cdk/lib/api/util/rwlock.ts index fdb1d2e2d..ffbb91f56 100644 --- a/packages/aws-cdk/lib/api/util/rwlock.ts +++ b/packages/aws-cdk/lib/api/util/rwlock.ts @@ -12,7 +12,7 @@ import { ToolkitError } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api'; * This class is not 100% race safe, but in practice it should be a lot * better than the 0 protection we have today. */ -/* istanbul ignore next: code paths are unpredictable */ +/* c8 ignore start */ // code paths are unpredictable export class RWLock { private readonly pidString: string; private readonly writerFile: string; @@ -146,6 +146,7 @@ export class RWLock { return ret; } } +/* c8 ignore stop */ /** * An acquired lock @@ -164,7 +165,7 @@ export interface IWriterLock extends ILock { convertToReaderLock(): Promise; } -/* istanbul ignore next: code paths are unpredictable */ +/* c8 ignore start */ // code paths are unpredictable async function readFileIfExists(filename: string): Promise { try { return await fs.readFile(filename, { encoding: 'utf-8' }); @@ -175,17 +176,19 @@ async function readFileIfExists(filename: string): Promise { throw e; } } +/* c8 ignore stop */ let tmpCounter = 0; -/* istanbul ignore next: code paths are unpredictable */ +/* c8 ignore start */ // code paths are unpredictable async function writeFileAtomic(filename: string, contents: string): Promise { await fs.mkdir(path.dirname(filename), { recursive: true }); const tmpFile = `${filename}.${process.pid}_${++tmpCounter}`; await fs.writeFile(tmpFile, contents, { encoding: 'utf-8' }); await fs.rename(tmpFile, filename); } +/* c8 ignore stop */ -/* istanbul ignore next: code paths are unpredictable */ +/* c8 ignore start */ // code paths are unpredictable async function deleteFile(filename: string) { try { await fs.unlink(filename); @@ -196,8 +199,9 @@ async function deleteFile(filename: string) { throw e; } } +/* c8 ignore stop */ -/* istanbul ignore next: code paths are unpredictable */ +/* c8 ignore start */ // code paths are unpredictable function processExists(pid: number) { try { process.kill(pid, 0); @@ -206,3 +210,4 @@ function processExists(pid: number) { return false; } } +/* c8 ignore stop */ diff --git a/packages/aws-cdk/lib/cli/cli.ts b/packages/aws-cdk/lib/cli/cli.ts index a78803549..8219a4fd7 100644 --- a/packages/aws-cdk/lib/cli/cli.ts +++ b/packages/aws-cdk/lib/cli/cli.ts @@ -595,7 +595,7 @@ function determineHotswapMode(hotswap?: boolean, hotswapFallback?: boolean, watc return hotswapMode; } -/* istanbul ignore next: we never call this in unit tests */ +/* c8 ignore start */ // we never call this in unit tests export function cli(args: string[] = process.argv.slice(2)) { exec(args) .then(async (value) => { @@ -610,3 +610,4 @@ export function cli(args: string[] = process.argv.slice(2)) { process.exitCode = 1; }); } +/* c8 ignore stop */ diff --git a/packages/aws-cdk/lib/cli/pretty-print-error.ts b/packages/aws-cdk/lib/cli/pretty-print-error.ts index 954e381c6..8cf44211f 100644 --- a/packages/aws-cdk/lib/cli/pretty-print-error.ts +++ b/packages/aws-cdk/lib/cli/pretty-print-error.ts @@ -1,6 +1,7 @@ /* eslint-disable no-console */ import * as chalk from 'chalk'; +/* c8 ignore start */ export function prettyPrintError(error: unknown, debug = false) { const err = ensureError(error); console.error(chalk.red(err.message)); @@ -34,3 +35,4 @@ function ensureError(value: unknown): Error { const error = new Error(`An unexpected error was thrown: ${stringified}`); return error; } +/* c8 ignore stop */ diff --git a/packages/aws-cdk/lib/cli/util/npm.ts b/packages/aws-cdk/lib/cli/util/npm.ts index b4bd194d4..02887503d 100644 --- a/packages/aws-cdk/lib/cli/util/npm.ts +++ b/packages/aws-cdk/lib/cli/util/npm.ts @@ -6,7 +6,7 @@ import { debug } from '../../logging'; const exec = promisify(_exec); -/* istanbul ignore next: not called during unit tests */ +/* c8 ignore start */ // not called during unit tests export async function getLatestVersionFromNpm(): Promise { const { stdout, stderr } = await exec('npm view aws-cdk version', { timeout: 3000 }); if (stderr && stderr.trim().length > 0) { @@ -19,3 +19,4 @@ export async function getLatestVersionFromNpm(): Promise { return latestVersion; } +/* c8 ignore stop */ diff --git a/packages/aws-cdk/lib/cli/version.ts b/packages/aws-cdk/lib/cli/version.ts index 656fb9ae6..66e65a397 100644 --- a/packages/aws-cdk/lib/cli/version.ts +++ b/packages/aws-cdk/lib/cli/version.ts @@ -1,4 +1,4 @@ -/* istanbul ignore file */ +/* c8 ignore start */ import * as path from 'path'; import * as chalk from 'chalk'; import * as fs from 'fs-extra'; @@ -130,3 +130,4 @@ export async function displayVersionMessage(currentVersion = versionNumber(), ve debug(`Could not run version check - ${err.message}`); } } +/* c8 ignore stop */ diff --git a/packages/aws-cdk/lib/commands/context.ts b/packages/aws-cdk/lib/commands/context.ts index 1d40ad9d5..73613a5d3 100644 --- a/packages/aws-cdk/lib/commands/context.ts +++ b/packages/aws-cdk/lib/commands/context.ts @@ -56,9 +56,10 @@ export async function contextHandler(options: ContextOptions): Promise { } else { // List -- support '--json' flag if (options.json) { - /* istanbul ignore next */ + /* c8 ignore start */ const contextValues = options.context.all; result(JSON.stringify(contextValues, undefined, 2)); + /* c8 ignore stop */ } else { listContext(options.context); } diff --git a/packages/aws-cdk/lib/commands/init/init.ts b/packages/aws-cdk/lib/commands/init/init.ts index 7da8915ff..263405376 100644 --- a/packages/aws-cdk/lib/commands/init/init.ts +++ b/packages/aws-cdk/lib/commands/init/init.ts @@ -509,10 +509,11 @@ async function loadInitVersions(): Promise { 'aws-cdk': versionNumber(), }; for (const [key, value] of Object.entries(ret)) { - /* istanbul ignore next */ + /* c8 ignore start */ if (!value) { throw new ToolkitError(`Missing init version from ${initVersionFile}: ${key}`); } + /* c8 ignore stop */ } return ret;