Skip to content

Commit 6f6c8e0

Browse files
committed
FI-1721 fix: save reports after errors in doBeforePack/doAfterPack
1 parent 35443ed commit 6f6c8e0

3 files changed

Lines changed: 35 additions & 23 deletions

File tree

src/utils/events/registerEndE2edRunEvent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ let isEndAlreadyCalled = false;
1717
* Registers end e2ed run event (for report) after closing of all tests.
1818
* @internal
1919
*/
20+
// eslint-disable-next-line max-statements
2021
export const registerEndE2edRunEvent = async (): Promise<void> => {
2122
if (isEndAlreadyCalled) {
2223
return;
@@ -47,6 +48,7 @@ export const registerEndE2edRunEvent = async (): Promise<void> => {
4748
} catch (error) {
4849
generalLog('Caught an error on run "after pack" functions', {error});
4950

51+
setReadonlyProperty(liteReport, 'exitCode', ExitCode.HasErrorsInDoAfterPackFunctions);
5052
setReadonlyProperty(reportData, 'exitCode', ExitCode.HasErrorsInDoAfterPackFunctions);
5153
}
5254

src/utils/events/registerStartE2edRunEvent.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,37 @@ export const registerStartE2edRunEvent = async (): Promise<void> => {
5353
const startInfo = getStartInfo({configCompileTimeWithUnits});
5454

5555
try {
56-
await runBeforePackFunctions(startInfo);
57-
} catch (cause) {
58-
setGlobalExitCode(ExitCode.HasErrorsInDoBeforePackFunctions);
59-
60-
throw new E2edError('Caught an error on running "before pack" functions', {cause});
61-
}
56+
try {
57+
await runBeforePackFunctions(startInfo);
58+
} catch (cause) {
59+
setGlobalExitCode(ExitCode.HasErrorsInDoBeforePackFunctions);
6260

63-
const fullPackConfig = getFullPackConfig();
61+
throw new E2edError('Caught an error on running "before pack" functions', {cause});
62+
}
6463

65-
updateConfig(fullPackConfig, startInfo);
64+
const fullPackConfig = getFullPackConfig();
6665

67-
if (errorSettingDotEnv !== undefined) {
68-
generalLog('Caught an error on setting environment variables from `variables.env` file', {
69-
errorSettingDotEnv,
70-
});
71-
}
66+
updateConfig(fullPackConfig, startInfo);
7267

73-
if (compileErrors.length !== 0) {
74-
const pathToPack = getPathToPack();
68+
if (errorSettingDotEnv !== undefined) {
69+
generalLog('Caught an error on setting environment variables from `variables.env` file', {
70+
errorSettingDotEnv,
71+
});
72+
}
7573

76-
generalLog(`Caught errors on compiling pack ${pathToPack}`, {compileErrors});
77-
}
74+
if (compileErrors.length !== 0) {
75+
const pathToPack = getPathToPack();
7876

79-
const {e2ed, runEnvironment} = startInfo;
80-
const isLocalRun = runEnvironment !== RunEnvironment.Docker;
81-
const startMessage = `Run tests ${isLocalRun ? 'local' : 'in docker'} with e2ed@${e2ed.version}`;
77+
generalLog(`Caught errors on compiling pack ${pathToPack}`, {compileErrors});
78+
}
8279

83-
generalLog(startMessage, startInfo);
80+
const {e2ed, runEnvironment} = startInfo;
81+
const isLocalRun = runEnvironment !== RunEnvironment.Docker;
82+
const startMessage = `Run tests ${isLocalRun ? 'local' : 'in docker'} with e2ed@${e2ed.version}`;
8483

85-
await writeStartInfo(startInfo);
86-
await writeLogsToFile();
84+
generalLog(startMessage, startInfo);
85+
} finally {
86+
await writeStartInfo(startInfo);
87+
await writeLogsToFile();
88+
}
8789
};

src/utils/exit/getExitCode.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ import {ExitCode, FAILED_TEST_RUN_STATUSES} from '../../constants/internal';
22

33
import {assertValueIsDefined} from '../asserts';
44

5+
import {getGlobalExitCode} from './globalExitCode';
6+
57
import type {Retry} from '../../types/internal';
68

79
/**
810
* Get e2ed exit code by `hasError` flag and array of retries.
911
* @internal
1012
*/
1113
export const getExitCode = (hasError: boolean, retries: readonly Retry[]): ExitCode => {
14+
const globalExitCode = getGlobalExitCode();
15+
16+
if (globalExitCode !== undefined) {
17+
return globalExitCode;
18+
}
19+
1220
if (hasError) {
1321
return ExitCode.HasErrors;
1422
}

0 commit comments

Comments
 (0)