Skip to content

Commit

Permalink
try fix flaky test by mock capture utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Doniaab committed Feb 26, 2025
1 parent 231840d commit cfbf280
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions alerting/src/aa-storm-alert/alert.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
jest.mock('node-fetch');
jest.mock('../utils/capture-utils', () => ({
captureScreenshotFromUrl: jest.fn(),
}));
import nodeFetch from 'node-fetch';
import {
buildEmailPayloads,
Expand All @@ -9,6 +12,7 @@ import { buildDetailedReport, buildLandfallInfo } from './test-utils';
import { WindState } from 'prism-common';
import moment from 'moment';
import { LastStates } from '../types/aa-storm-email';
import { captureScreenshotFromUrl } from '../utils/capture-utils';

describe('alert mechanism', () => {
describe('getLatestAvailableReports()', () => {
Expand Down Expand Up @@ -206,6 +210,7 @@ describe('alert mechanism', () => {
];
it.each(tests)('$description', async ({ data, shortReports }) => {
mockedFetch.mockResolvedValue({ json: () => data });
(captureScreenshotFromUrl as jest.Mock).mockResolvedValue("");

const emailPayloads = await buildEmailPayloads(
shortReports,
Expand Down
18 changes: 9 additions & 9 deletions alerting/src/aa-storm-alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import { formatDateToUTC } from '../utils/date';
// @ts-ignore
global.fetch = nodeFetch;

function fetchAllReports(): Promise<ShortReportsResponseBody | null> {
return fetch(
'https://data.earthobservation.vam.wfp.org/public-share/aa/ts/outputs/dates.json',
)
.then((data) => data.json())
.catch(() => {
console.error('Error fetching all reports');
return null;
});
async function fetchAllReports(): Promise<ShortReportsResponseBody | null> {
try {
const data = await fetch(
'https://data.earthobservation.vam.wfp.org/public-share/aa/ts/outputs/dates.json');
return await data.json();
} catch {
console.error('Error fetching all reports');
return null;
}
}

// fetch and extract the more recent short report for each reported storm
Expand Down

0 comments on commit cfbf280

Please sign in to comment.