Home / Class/ SpyCommandExecutor Class — astro Architecture

SpyCommandExecutor Class — astro Architecture

Architecture documentation for the SpyCommandExecutor class in utils.js from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  4015699c_a2bd_40eb_480e_25e604ae67ec["SpyCommandExecutor"]
  dc38b823_10e6_0080_9a8c_08dc7cc3e0eb["utils.js"]
  4015699c_a2bd_40eb_480e_25e604ae67ec -->|defined in| dc38b823_10e6_0080_9a8c_08dc7cc3e0eb
  004e7db8_20e1_b5ed_de41_c5fb22f0bb6d["constructor()"]
  4015699c_a2bd_40eb_480e_25e604ae67ec -->|method| 004e7db8_20e1_b5ed_de41_c5fb22f0bb6d
  01b11c4a_89a1_9fa5_c48a_b0ff1c409005["execute()"]
  4015699c_a2bd_40eb_480e_25e604ae67ec -->|method| 01b11c4a_89a1_9fa5_c48a_b0ff1c409005
  f4c18329_7a77_dacd_62c2_0019e074e410["inputs()"]
  4015699c_a2bd_40eb_480e_25e604ae67ec -->|method| f4c18329_7a77_dacd_62c2_0019e074e410

Relationship Graph

Source Code

packages/astro/test/units/cli/utils.js lines 129–164

export class SpyCommandExecutor {
	/** @type {Array<{ command: string; args: Array<string> | undefined; input: string | undefined }>} */
	#inputs = [];
	/** @type {boolean} */
	#fail;

	/**
	 *
	 * @param {object} options
	 * @param {boolean} [options.fail=false] Forces execute() to throw an error. This is useful to test error handling
	 */
	constructor({ fail = false } = {}) {
		this.#fail = fail;
	}

	/**
	 *
	 * @param {string} command
	 * @param {Array<string> | undefined} args
	 * @param {CommandExecutorOptions | undefined} options
	 * @returns
	 */
	async execute(command, args, options) {
		this.#inputs.push({ command, args, input: options?.input });
		if (this.#fail) {
			throw new Error('Command execution failed');
		}
		return {
			stdout: '',
		};
	}

	get inputs() {
		return this.#inputs;
	}
}

Frequently Asked Questions

What is the SpyCommandExecutor class?
SpyCommandExecutor is a class in the astro codebase, defined in packages/astro/test/units/cli/utils.js.
Where is SpyCommandExecutor defined?
SpyCommandExecutor is defined in packages/astro/test/units/cli/utils.js at line 129.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free