Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ export type Branded<T, B> = T & Brand<B>;
* values which are branded by construction (really just an elaborate
* way to write 'as').
*/
/* c8 ignore next 3 */
/* c8 ignore start */
export function createBranded<A extends Branded<any, any>>(value: TypeUnderlyingBrand<A>): A {
return value as A;
}
/* c8 ignore stop */

type TypeUnderlyingBrand<A> = A extends Branded<infer T, any> ? T : never;
3 changes: 2 additions & 1 deletion packages/aws-cdk/lib/api/logs/logs-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ export class CloudWatchLogEventMonitor {
private async tick(): Promise<void> {
// 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());
Expand Down
15 changes: 10 additions & 5 deletions packages/aws-cdk/lib/api/util/rwlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,6 +146,7 @@ export class RWLock {
return ret;
}
}
/* c8 ignore stop */

/**
* An acquired lock
Expand All @@ -164,7 +165,7 @@ export interface IWriterLock extends ILock {
convertToReaderLock(): Promise<ILock>;
}

/* istanbul ignore next: code paths are unpredictable */
/* c8 ignore start */ // code paths are unpredictable
async function readFileIfExists(filename: string): Promise<string | undefined> {
try {
return await fs.readFile(filename, { encoding: 'utf-8' });
Expand All @@ -175,17 +176,19 @@ async function readFileIfExists(filename: string): Promise<string | undefined> {
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<void> {
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);
Expand All @@ -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);
Expand All @@ -206,3 +210,4 @@ function processExists(pid: number) {
return false;
}
}
/* c8 ignore stop */
3 changes: 2 additions & 1 deletion packages/aws-cdk/lib/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -610,3 +610,4 @@ export function cli(args: string[] = process.argv.slice(2)) {
process.exitCode = 1;
});
}
/* c8 ignore stop */
2 changes: 2 additions & 0 deletions packages/aws-cdk/lib/cli/pretty-print-error.ts
Original file line number Diff line number Diff line change
@@ -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));
Expand Down Expand Up @@ -34,3 +35,4 @@ function ensureError(value: unknown): Error {
const error = new Error(`An unexpected error was thrown: ${stringified}`);
return error;
}
/* c8 ignore stop */
3 changes: 2 additions & 1 deletion packages/aws-cdk/lib/cli/util/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
const { stdout, stderr } = await exec('npm view aws-cdk version', { timeout: 3000 });
if (stderr && stderr.trim().length > 0) {
Expand All @@ -19,3 +19,4 @@ export async function getLatestVersionFromNpm(): Promise<string> {

return latestVersion;
}
/* c8 ignore stop */
3 changes: 2 additions & 1 deletion packages/aws-cdk/lib/cli/version.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -130,3 +130,4 @@ export async function displayVersionMessage(currentVersion = versionNumber(), ve
debug(`Could not run version check - ${err.message}`);
}
}
/* c8 ignore stop */
3 changes: 2 additions & 1 deletion packages/aws-cdk/lib/commands/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ export async function contextHandler(options: ContextOptions): Promise<number> {
} 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);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/aws-cdk/lib/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,11 @@ async function loadInitVersions(): Promise<Versions> {
'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;
Expand Down