Test Utilities
The following built-in helpers are available directly in the test context. Many are convenience wrappers around Nodejs' fs and child_process modules, which make use of the global ROOT variable to run relative to the root of the workspace.
controlWrapper
Wraps a function in an interval to retry until it does not throw or times out.
function controlWrapper(
cb: () => any,
{ timeout = 10_000, stepSize = 250 }
): Promise<ReturnType<cb> | null>;
The callback function must throw for the control wrapper to re-try.
const cb = async () => {
const flakyFetch = await fetch('http://localhost:3123');
return flakyFetch.json();
};
const result = await controlWrapper(cb);
getBashHistory
Get the .logs/.bash_history.log file contents
function getBashHistory(): Promise<string>;
const bashHistory = await getBashHistory();
getCommandOutput
Returns the output of a command called from the given path relative to the root of the workspace.
function getCommandOutput(
command: string,
path = ''
): Promise<{ stdout: string; stderr: string } | Error>;
const { stdout, stderr } = await getCommandOutput('ls');
getCWD
Get the .logs/.cwd.log file contents
function getCWD(): Promise<string>;
const cwd = await getCWD();
getLastCommand
Get the \(n^{th}\) latest line from .logs/.bash_history.log.
function getLastCommand(n = 0): Promise<string>;
const lastCommand = await getLastCommand();
getLastCWD
Get the \(n^{th}\) latest line from .logs/.cwd.log.
function getLastCWD(n = 0): Promise<string>;
const lastCWD = await getLastCWD();
getTemp
Get the .logs/.temp.log file contents.
function getTemp(): Promise<string>;
const temp = await getTemp();
Use the output of the .temp.log file at your own risk. This file is raw input from the terminal including ANSI escape codes.
Output varies depending on emulator, terminal size, order text is typed, etc. For more info, see https://github.com/freeCodeCamp/solana-curriculum/issues/159
getTerminalOutput
Get the .logs/.terminal_out.log file contents.
function getTerminalOutput(): Promise<string>;
const terminalOutput = await getTerminalOutput();
importSansCache
Import a module side-stepping Nodejs' cache - cache-busting imports.
function importSansCache(path: string): Promise<any>;
const { exportedFile } = await importSansCache(
'learn-x-by-building-y/index.js'
);