Skip to content

Commit

Permalink
FI-1434 feat: add links to trace.zip in HTML report
Browse files Browse the repository at this point in the history
  • Loading branch information
uid11 committed Nov 9, 2024
1 parent 321866c commit da61cba
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 54 deletions.
1 change: 1 addition & 0 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type Onlog = () => void;
export type TestRunEvent<TestMeta = TestMetaPlaceholder> = Readonly<{
logEvents: readonly LogEvent[];
onlog: Onlog;
outputDirectoryName: string;
reject: RejectTestRun;
retryIndex: number;
runId: RunId;
Expand Down
2 changes: 1 addition & 1 deletion src/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export type {
TestStaticOptions,
} from './testRun';
/** @internal */
export type {FullTestRun, Test} from './testRun';
export type {FullTestRun, RunTest, Test, TestUnit} from './testRun';
export type {MergeTuples, TupleRest} from './tuples';
export type {
CloneWithoutUndefinedProperties,
Expand Down
56 changes: 40 additions & 16 deletions src/types/testRun.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {PlaywrightTestArgs} from '@playwright/test';
import type {PlaywrightTestArgs, TestInfo} from '@playwright/test';

import type {TestRunStatus} from '../constants/internal';
import type {E2edError} from '../utils/error';
Expand All @@ -11,6 +11,25 @@ import type {TestFilePath} from './paths';
import type {StringForLogs} from './string';
import type {TestMetaPlaceholder} from './userland';

/**
* Full test run object result of userland hooks (like mainParams and runHash).
* @internal
*/
export type FullTestRun = Readonly<{mainParams: string; runHash: RunHash}> & TestRun;

/**
* Lite test run object with userland metadata.
*/
export type LiteTestRun<TestMeta = TestMetaPlaceholder> = Readonly<{
endTimeInMs: UtcTimeInMs;
mainParams: string;
runError: RunError;
runHash: RunHash;
startTimeInMs: UtcTimeInMs;
status: TestRunStatus;
}> &
TestStaticOptions<TestMeta>;

/**
* Reject test run.
*/
Expand All @@ -32,6 +51,16 @@ export type RunHash = Brand<string, 'RunHash'>;
*/
export type RunId = Brand<string, 'RunId'>;

/**
* Playwright's function for run test.
* @internal
*/
export type RunTest = (
this: void,
testController: PlaywrightTestArgs,
testInfo: TestInfo,
) => Promise<void>;

/**
* Test function itself.
*/
Expand Down Expand Up @@ -87,20 +116,15 @@ export type TestFunction<TestMeta = TestMetaPlaceholder> = (
) => void;

/**
* Lite test run object with userland metadata.
*/
export type LiteTestRun<TestMeta = TestMetaPlaceholder> = Readonly<{
endTimeInMs: UtcTimeInMs;
mainParams: string;
runError: RunError;
runHash: RunHash;
startTimeInMs: UtcTimeInMs;
status: TestRunStatus;
}> &
TestStaticOptions<TestMeta>;

/**
* Full test run object result of userland hooks (like mainParams and runHash).
* Test unit for run.
* @internal
*/
export type FullTestRun = Readonly<{mainParams: string; runHash: RunHash}> & TestRun;
export type TestUnit = Readonly<{
beforeRetryTimeout: number | undefined;
outputDirectoryName: string;
retryIndex: number;
runId: RunId;
testController: PlaywrightTestArgs;
testFn: TestFn;
testStaticOptions: TestStaticOptions;
}>;
2 changes: 2 additions & 0 deletions src/utils/events/registerEndTestRunEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const registerEndTestRunEvent = async (endTestRunEvent: EndTestRunEvent):
logEvents,
name,
options,
outputDirectoryName,
retryIndex,
runLabel,
status: originalStatus,
Expand Down Expand Up @@ -77,6 +78,7 @@ export const registerEndTestRunEvent = async (endTestRunEvent: EndTestRunEvent):
logEvents,
name,
options,
outputDirectoryName,
retryIndex,
runError,
runId,
Expand Down
20 changes: 4 additions & 16 deletions src/utils/test/beforeTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,10 @@ import {getUserlandHooks} from '../userland';

import {getTestFnAndReject} from './getTestFnAndReject';

import type {
RunId,
TestFn,
TestRunEvent,
TestStaticOptions,
UtcTimeInMs,
} from '../../types/internal';
import type {TestRunEvent, TestUnit, UtcTimeInMs} from '../../types/internal';

import {test} from '@playwright/test';

type Options = Readonly<{
beforeRetryTimeout: number | undefined;
retryIndex: number;
runId: RunId;
testFn: TestFn;
testStaticOptions: TestStaticOptions;
}>;

const additionToPlaywrightTestTimeout = 500;

/**
Expand All @@ -40,11 +26,12 @@ const additionToPlaywrightTestTimeout = 500;
*/
export const beforeTest = ({
beforeRetryTimeout,
outputDirectoryName,
retryIndex,
runId,
testFn,
testStaticOptions,
}: Options): void => {
}: TestUnit): void => {
const {options} = testStaticOptions;

setMeta(options.meta);
Expand Down Expand Up @@ -88,6 +75,7 @@ export const beforeTest = ({
...testStaticOptions,
logEvents: [],
onlog,
outputDirectoryName,
reject,
retryIndex,
runId,
Expand Down
19 changes: 19 additions & 0 deletions src/utils/test/getOutputDirectoryName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {INTERNAL_REPORTS_DIRECTORY_PATH} from '../../constants/internal';

import {assertValueIsTrue} from '../asserts';

/**
* Get output directory name of test in `internal` directory.
* @internal
*/
export const getOutputDirectoryName = (outputDirectory: string): string => {
const indexOfInternalDirectory = outputDirectory.indexOf(INTERNAL_REPORTS_DIRECTORY_PATH);

assertValueIsTrue(indexOfInternalDirectory > 0, 'indexOfInternalDirectory greater than 0', {
outputDirectory,
});

return outputDirectory.slice(
INTERNAL_REPORTS_DIRECTORY_PATH.length + indexOfInternalDirectory + 1,
);
};
25 changes: 16 additions & 9 deletions src/utils/test/getRunTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,22 @@ import {assertValueIsDefined} from '../asserts';
import {afterErrorInTest} from './afterErrorInTest';
import {afterTest} from './afterTest';
import {beforeTest} from './beforeTest';
import {getOutputDirectoryName} from './getOutputDirectoryName';
import {getShouldRunTest} from './getShouldRunTest';
import {getTestStaticOptions} from './getTestStaticOptions';
import {preparePage} from './preparePage';
import {runTestFn} from './runTestFn';
import {waitBeforeRetry} from './waitBeforeRetry';

import type {PlaywrightTestArgs, TestInfo} from '@playwright/test';

import type {Test, TestStaticOptions} from '../../types/internal';

type RunTest = (testController: PlaywrightTestArgs, testInfo: TestInfo) => Promise<void>;
import type {RunTest, Test, TestStaticOptions, TestUnit} from '../../types/internal';

/**
* Get complete run test function by the complete test options.
* @internal
*/
export const getRunTest =
(test: Test): RunTest =>
({context, page, request}: PlaywrightTestArgs, testInfo: TestInfo): Promise<void> => {
({context, page, request}, testInfo): Promise<void> => {
const runTest = async (): Promise<void> => {
const retryIndex = testInfo.retry + 1;
const runId = createRunId(test, retryIndex);
Expand All @@ -48,11 +45,21 @@ export const getRunTest =

clearPage = await preparePage(page);

beforeTest({beforeRetryTimeout, retryIndex, runId, testFn: test.testFn, testStaticOptions});

const testController = {context, page, request};

await runTestFn({beforeRetryTimeout, retryIndex, runId, testController, testStaticOptions});
const testUnit: TestUnit = {
beforeRetryTimeout,
outputDirectoryName: getOutputDirectoryName(testInfo.outputDir),
retryIndex,
runId,
testController,
testFn: test.testFn,
testStaticOptions,
};

beforeTest(testUnit);

await runTestFn(testUnit);
} catch (error) {
hasRunError = true;
unknownRunError = error;
Expand Down
14 changes: 2 additions & 12 deletions src/utils/test/runTestFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ import {getDurationWithUnits} from '../getDurationWithUnits';
import {log} from '../log';
import {getPromiseWithResolveAndReject} from '../promise';

import type {PlaywrightTestArgs} from '@playwright/test';

import type {RunId, TestStaticOptions} from '../../types/internal';
import type {TestUnit} from '../../types/internal';

const delayForTestRunPromiseResolutionAfterTestTimeoutInMs = 100;

type Options = Readonly<{
beforeRetryTimeout: number | undefined;
retryIndex: number;
runId: RunId;
testController: PlaywrightTestArgs;
testStaticOptions: TestStaticOptions;
}>;

/**
* Runs test function with reject in test run event.
* @internal
Expand All @@ -33,7 +23,7 @@ export const runTestFn = async ({
runId,
testController,
testStaticOptions,
}: Options): Promise<void> => {
}: TestUnit): Promise<void> => {
const {status, testFnWithReject} = getTestRunEvent(runId);
const testTimeout = getTestTimeout();

Expand Down

0 comments on commit da61cba

Please sign in to comment.