Skip to content

Commit 831ca03

Browse files
committed
PRO-11324 fix: add global warnings for TestUnhandledRejection
1 parent 853f98c commit 831ca03

13 files changed

Lines changed: 97 additions & 7 deletions

src/constants/internal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export {
5353
EVENTS_DIRECTORY_PATH,
5454
EXPECTED_SCREENSHOTS_DIRECTORY_PATH,
5555
GLOBAL_ERRORS_PATH,
56+
GLOBAL_WARNINGS_PATH,
5657
INSTALLED_E2ED_DIRECTORY_PATH,
5758
INTERNAL_DIRECTORY_NAME,
5859
INTERNAL_REPORTS_DIRECTORY_PATH,

src/constants/paths.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ export const EXPECTED_SCREENSHOTS_DIRECTORY_PATH = join(
128128
*/
129129
export const GLOBAL_ERRORS_PATH = join(TMP_DIRECTORY_PATH, 'globalErrors.txt') as FilePathFromRoot;
130130

131+
/**
132+
* Relative (from root) path to file with global warnings of run.
133+
* @internal
134+
*/
135+
export const GLOBAL_WARNINGS_PATH = join(
136+
TMP_DIRECTORY_PATH,
137+
'globalWarnings.txt',
138+
) as FilePathFromRoot;
139+
131140
/**
132141
* Relative (from root) path to directory with tests screenshots.
133142
* @internal

src/types/report.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type LiteReport<
3939
FullPackConfig<CustomPackProperties, CustomReportProperties, SkipTests, TestMeta>
4040
>;
4141
summaryPackResults: string;
42+
warnings: readonly string[];
4243
}>;
4344

4445
/**
@@ -76,6 +77,7 @@ export type ReportData = Readonly<{
7677
retries: readonly Retry[];
7778
startInfo: StartInfo;
7879
summaryPackResults: string;
80+
warnings: readonly string[];
7981
}>;
8082

8183
/**

src/utils/fs/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export {readEventsFromFiles} from './readEventsFromFiles';
1515
/** @internal */
1616
export {readGlobalErrors} from './readGlobalErrors';
1717
/** @internal */
18+
export {readGlobalWarnings} from './readGlobalWarnings';
19+
/** @internal */
1820
export {readStartInfo} from './readStartInfo';
1921
/** @internal */
2022
export {removeDirectory} from './removeDirectory';
@@ -24,6 +26,8 @@ export {writeFile} from './writeFile';
2426
/** @internal */
2527
export {writeGlobalError} from './writeGlobalError';
2628
/** @internal */
29+
export {writeGlobalWarning} from './writeGlobalWarning';
30+
/** @internal */
2731
export {writeStartInfo} from './writeStartInfo';
2832
/** @internal */
2933
export {writeTestRunToJsonFile} from './writeTestRunToJsonFile';

src/utils/fs/readGlobalWarnings.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {readFile} from 'node:fs/promises';
2+
3+
import {GLOBAL_WARNINGS_PATH, READ_FILE_OPTIONS} from '../../constants/internal';
4+
5+
/**
6+
* Reads global warnings of run from directory.
7+
* @internal
8+
*/
9+
export const readGlobalWarnings = async (): Promise<readonly string[]> => {
10+
const globalWarningsJsonString = await readFile(GLOBAL_WARNINGS_PATH, READ_FILE_OPTIONS).catch(
11+
() => '',
12+
);
13+
14+
return JSON.parse(`[${globalWarningsJsonString.slice(0, -2)}]`) as string[];
15+
};

src/utils/fs/writeGlobalWarning.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {appendFile} from 'node:fs/promises';
2+
3+
import {GLOBAL_WARNINGS_PATH} from '../../constants/internal';
4+
5+
/**
6+
* Writes single global warning of run to common file.
7+
* @internal
8+
*/
9+
export const writeGlobalWarning = async (globalWarning: string): Promise<void> => {
10+
const globalWarningJsonString = JSON.stringify(globalWarning);
11+
12+
await appendFile(GLOBAL_WARNINGS_PATH, `${globalWarningJsonString},\n`);
13+
};

src/utils/getGlobalErrorHandler.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {TARGET_CLOSED_ERROR_MESSAGE, TEST_ENDED_ERROR_MESSAGE} from '../constants/internal';
22

33
import {E2edError} from './error';
4-
import {writeGlobalError} from './fs';
4+
import {writeGlobalError, writeGlobalWarning} from './fs';
55
import {writeLogsToFile} from './generalLog';
66

77
import type {GlobalErrorType} from '../types/internal';
@@ -24,7 +24,12 @@ export const getGlobalErrorHandler =
2424
return;
2525
}
2626

27-
void writeGlobalError(errorString).catch(() => {});
27+
if (type === 'TestUnhandledRejection') {
28+
void writeGlobalWarning(errorString).catch(() => {});
29+
} else {
30+
void writeGlobalError(errorString).catch(() => {});
31+
}
32+
2833
void writeLogsToFile().catch(() => {});
2934
} catch {}
3035
};

src/utils/report/collectReportData.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const collectReportData = async ({
2626
}: FullEventsData): Promise<ReportData> => {
2727
const {liteReportFileName, logFileName, reportFileName} = getFullPackConfig();
2828

29-
const errors = await getReportErrors(fullTestRuns, notIncludedInPackTests);
29+
const {errors, warnings} = await getReportErrors(fullTestRuns, notIncludedInPackTests);
3030

3131
if (!isUiMode) {
3232
assertThatTestNamesAndFilePathsAreUnique(fullTestRuns);
@@ -57,5 +57,6 @@ export const collectReportData = async ({
5757
retries,
5858
startInfo,
5959
summaryPackResults,
60+
warnings,
6061
};
6162
};

src/utils/report/getLiteReport.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const getLiteReport = (reportData: ReportData): LiteReport => {
2020
retries,
2121
startInfo,
2222
summaryPackResults,
23+
warnings,
2324
} = reportData;
2425

2526
assertValueIsNotNull(liteReportFileName, 'liteReportFileName is not null');
@@ -39,5 +40,6 @@ export const getLiteReport = (reportData: ReportData): LiteReport => {
3940
retries: liteRetries,
4041
startInfo,
4142
summaryPackResults,
43+
warnings,
4244
};
4345
};

src/utils/report/getReportErrors.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {getFullPackConfig} from '../config';
2-
import {readGlobalErrors} from '../fs';
2+
import {readGlobalErrors, readGlobalWarnings} from '../fs';
33
import {
44
collectTestFilePaths,
55
getUnsuccessfulTestFilePaths,
@@ -8,16 +8,22 @@ import {
88

99
import type {FullTestRun, TestFilePath} from '../../types/internal';
1010

11+
type Return = Readonly<{
12+
errors: readonly string[];
13+
warnings: readonly string[];
14+
}>;
15+
1116
/**
12-
* Get all report errors. General report status is failed if there is any error.
17+
* Get all report errors and warnings. General report status is failed if there is any error.
1318
* @internal
1419
*/
1520
export const getReportErrors = async (
1621
fullTestRuns: readonly FullTestRun[],
1722
notIncludedInPackTests: readonly TestFilePath[],
18-
): Promise<readonly string[]> => {
23+
): Promise<Return> => {
1924
const {testFileGlobs} = getFullPackConfig();
2025
const errors = (await readGlobalErrors()) as string[];
26+
const warnings = await readGlobalWarnings();
2127

2228
const allTestFilePaths = await collectTestFilePaths();
2329
const unsuccessfulTestFilePaths = await getUnsuccessfulTestFilePaths(
@@ -55,5 +61,5 @@ export const getReportErrors = async (
5561
);
5662
}
5763

58-
return errors;
64+
return {errors, warnings};
5965
};

0 commit comments

Comments
 (0)