function setupSpawnSyncStubReturnVals(stub, returnVals) {
	let stubChain = stub;

	for (const [i, val] of returnVals.entries()) {
		const returnVal =
			val instanceof Error ? { error: val } : { stdout: val };

		stubChain = stubChain.onCall(i).returns(returnVal);
	}

	return stubChain;
}
Sets up spawn.sync() stub calls to return values and throw errors in the order in which they are given.
@param {Function} stub The stub to set up.
@param {Array} returnVals Values to be returned by subsequent stub calls.
@returns {Function} The set up stub.