Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
camden11 committed Jan 13, 2025
1 parent 1e8bc60 commit c8db8ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 47 deletions.
8 changes: 1 addition & 7 deletions commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ const endpointLog = async (accountId, functionPath, options) => {
}
};

await tailLogs({
accountId,
compact,
tailCall,
fetchLatest,
name: functionPath,
});
await tailLogs(accountId, functionPath, fetchLatest, tailCall, compact);
} else if (latest) {
try {
const { data } = await getLatestFunctionLog(accountId, functionPath);
Expand Down
48 changes: 13 additions & 35 deletions lib/__tests__/serverlessLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ const ACCOUNT_ID = 123;
describe('lib/serverlessLogs', () => {
describe('tailLogs()', () => {
let stdinMock;
let spinnies;

beforeEach(() => {
jest.spyOn(process, 'exit').mockImplementation(() => {});
stdinMock = mockStdIn.stdin();
spinnies = {
succeed: jest.fn(),
fail: jest.fn(),
stopAll: jest.fn(),
};
});

afterEach(() => {
Expand All @@ -33,14 +27,16 @@ describe('lib/serverlessLogs', () => {
const compact = false;
const fetchLatest = jest.fn(() => {
return Promise.resolve({
id: '1234',
executionTime: 510,
log: 'Log message',
error: null,
status: 'SUCCESS',
createdAt: 1620232011451,
memory: '70/128 MB',
duration: '53.40 ms',
data: {
id: '1234',
executionTime: 510,
log: 'Log message',
error: null,
status: 'SUCCESS',
createdAt: 1620232011451,
memory: '70/128 MB',
duration: '53.40 ms',
},
});
});
const tailCall = jest.fn(() => {
Expand All @@ -54,13 +50,7 @@ describe('lib/serverlessLogs', () => {
});
});

await tailLogs({
accountId: ACCOUNT_ID,
compact,
spinnies,
fetchLatest,
tailCall,
});
await tailLogs(ACCOUNT_ID, 'name', fetchLatest, tailCall, compact);
jest.runOnlyPendingTimers();

expect(fetchLatest).toHaveBeenCalled();
Expand Down Expand Up @@ -116,13 +106,7 @@ describe('lib/serverlessLogs', () => {
Promise.resolve({ data: latestLogResponse })
);

await tailLogs({
accountId: ACCOUNT_ID,
compact,
spinnies,
fetchLatest,
tailCall,
});
await tailLogs(ACCOUNT_ID, 'name', fetchLatest, tailCall, compact);
jest.runOnlyPendingTimers();
expect(outputLogs).toHaveBeenCalledWith(
latestLogResponse,
Expand All @@ -148,13 +132,7 @@ describe('lib/serverlessLogs', () => {
)
);

await tailLogs({
accountId: ACCOUNT_ID,
compact,
spinnies,
fetchLatest,
tailCall,
});
await tailLogs(ACCOUNT_ID, 'name', fetchLatest, tailCall, compact);
jest.runOnlyPendingTimers();
expect(tailCall).toHaveBeenCalledTimes(2);
});
Expand Down
8 changes: 3 additions & 5 deletions lib/serverlessLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function tailLogs(
accountId: number,
name: string,
fetchLatest: () => HubSpotPromise<FunctionLog>,
tailCall: (after: string) => HubSpotPromise<GetFunctionLogsResponse>,
tailCall: (after?: string) => HubSpotPromise<GetFunctionLogsResponse>,
compact = false
): Promise<void> {
let initialAfter = '';
Expand All @@ -126,7 +126,7 @@ export async function tailLogs(
}
}

async function tail(after: string): Promise<void> {
async function tail(after?: string): Promise<void> {
let latestLog: GetFunctionLogsResponse;
let nextAfter: string;
try {
Expand Down Expand Up @@ -168,9 +168,7 @@ export async function tailLogs(

handleUserInput();

if (initialAfter) {
await tail(initialAfter);
}
await tail(initialAfter);
}

export async function outputBuildLog(buildLogUrl: string): Promise<string> {
Expand Down

0 comments on commit c8db8ce

Please sign in to comment.