Skip to content

Commit

Permalink
Merge pull request #84 from joomcode/fix/test-file-path-checks
Browse files Browse the repository at this point in the history
fix: global status of e2ed run
  • Loading branch information
uid11 authored Aug 6, 2024
2 parents e06aad3 + bcd814c commit 6b6d886
Show file tree
Hide file tree
Showing 24 changed files with 249 additions and 143 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/playwright:v1.45.1-noble
FROM mcr.microsoft.com/playwright:v1.46.0-noble

COPY ./build/node_modules/e2ed /node_modules/e2ed

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ The functions accept a start info object, and can return new full pack config,
which in this case will be included in the start info object, and will be used for running pack.
Each function can thus access the results of the previous function.

`enableChromeDevToolsProtocol: boolean`: enables [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/)
for browser control in tests (instead of `testcafe-hammerhead`).
In CDP mode, tests disable Service Workers (if they are used on the page).

`enableHeadlessMode: boolean`: enables headless mode (if browser supports such mode).

`enableLiveMode: boolean`: enables live mode for test development (only for locally running).
Expand Down Expand Up @@ -319,8 +315,10 @@ If the mapping returns `undefined`, the log entry is not skipped, but is printed
`your-project/autotests/bin/runDocker.sh` (until the test passes).
For example, if it is equal to three, the test will be run no more than three times.

`overriddenConfigFields: PlaywrightTestConfig | null`: if not `null`, then this value will override
fields of internal Playwright config.

`overriddenUserAgent: string | null`: if not `null`, then this value will override the browser's user agent in tests.
This override only works when `enableChromeDevToolsProtocol` is `true`.

`packTimeout: number`: timeout (in millisecond) for the entire pack of tests (tasks).
If the test pack takes longer than this timeout, the pack will fail with the appropriate error.
Expand Down
8 changes: 4 additions & 4 deletions autotests/actions/setPageCookiesAndNavigateToUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const setPageCookiesAndNavigateToUrl = async (
pageCookies: readonly Cookie[],
): Promise<void> => {
const mapResponseHeaders = (headers: StringHeaders): StringHeaders => {
let cookiesArray: SetCookieHeaderString[] = [];
const setCookies = getHeaderValue(headers, 'set-cookie');

if (setCookies !== undefined) {
cookiesArray.push(setCookies as SetCookieHeaderString);
}
let cookiesArray = (setCookies ?? '')
.split('\n')
.map((line) => line.trim())
.filter(Boolean) as SetCookieHeaderString[];

for (const cookie of pageCookies) {
cookiesArray = replaceSetCookie(cookiesArray, cookie);
Expand Down
2 changes: 1 addition & 1 deletion autotests/packs/allTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const pack: Pack = {
customPackProperties: {internalPackRunId: 0, name: 'allTests'},
doAfterPack,
doBeforePack,
enableChromeDevToolsProtocol: true,
enableHeadlessMode: true,
enableLiveMode: false,
enableMobileDeviceMode: false,
Expand All @@ -66,6 +65,7 @@ export const pack: Pack = {
mapLogPayloadInLogFile,
mapLogPayloadInReport,
maxRetriesCountInDocker: 3,
overriddenConfigFields: null,
overriddenUserAgent,
packTimeout: packTimeoutInMinutes * msInMinute,
pageRequestTimeout: 30_000,
Expand Down
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"url": "git+https://github.com/joomcode/e2ed.git"
},
"dependencies": {
"@playwright/test": "1.45.3",
"@playwright/test": "1.46.0",
"bin-v8-flags-filter": "1.2.0",
"create-locator": "0.0.23",
"get-modules-graph": "0.0.9",
"globby": "11.1.0"
},
"devDependencies": {
"@playwright/browser-chromium": "1.45.3",
"@playwright/browser-chromium": "1.46.0",
"@types/node": "22.1.0",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
Expand Down
81 changes: 39 additions & 42 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,42 @@ Modules in the dependency graph should only import the modules above them:
1. `types`
2. `constants`
3. `configurator`
4. `testcafe`
5. `esm`
6. `generators`
7. `utils/browser`
8. `utils/getDurationWithUnits`
9. `utils/setReadonlyProperty`
10. `utils/selectors`
11. `utils/paths`
12. `utils/valueToString`
13. `utils/error`
14. `utils/asserts`
15. `utils/testCafe`
16. `utils/runLabel`
17. `utils/clone`
18. `utils/notIncludedInPackTests`
19. `utils/userland`
20. `utils/fn`
21. `utils/environment`
22. `utils/packCompiler`
23. `testcaferc`
24. `utils/config`
25. `utils/generalLog`
26. `utils/exit`
27. `utils/promise`
28. `utils/resourceUsage`
29. `utils/fs`
30. `utils/tests`
31. `utils/disconnectedBrowsers`
32. `utils/end`
33. `utils/pack`
34. `selectors`
35. `Route`
36. `ApiRoute`
37. `PageRoute`
38. `testController`
39. `useContext`
40. `context`
41. `utils/log`
42. `utils/waitForEvents`
43. `utils/expect`
44. `expect`
45. ...
4. `generators`
5. `utils/browser`
6. `utils/getDurationWithUnits`
7. `utils/setReadonlyProperty`
8. `utils/selectors`
9. `utils/paths`
10. `utils/valueToString`
11. `utils/error`
12. `utils/asserts`
13. `utils/runLabel`
14. `utils/clone`
15. `utils/notIncludedInPackTests`
16. `utils/userland`
17. `utils/fn`
18. `utils/environment`
19. `utils/packCompiler`
20. `config`
21. `utils/config`
22. `utils/generalLog`
23. `utils/testFilePaths`
24. `utils/exit`
25. `utils/promise`
26. `utils/resourceUsage`
27. `utils/fs`
28. `utils/tests`
29. `utils/end`
30. `utils/pack`
31. `selectors`
32. `Route`
33. `ApiRoute`
34. `PageRoute`
35. `testController`
36. `useContext`
37. `context`
38. `utils/log`
39. `utils/waitForEvents`
40. `utils/expect`
41. `expect`
42. ...
15 changes: 13 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import {
ABSOLUTE_PATH_TO_INSTALLED_E2ED_DIRECTORY,
ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY,
COMPILED_USERLAND_CONFIG_DIRECTORY,
e2edEnvironment,
INTERNAL_REPORTS_DIRECTORY_PATH,
isDebug,
PATH_TO_TEST_FILE_VARIABLE_NAME,
TESTS_DIRECTORY_PATH,
} from './constants/internal';
import {assertValueIsTrue} from './utils/asserts';
Expand All @@ -21,7 +23,7 @@ import {setCustomInspectOnFunction} from './utils/fn';
import {setReadonlyProperty} from './utils/setReadonlyProperty';
import {isLocalRun} from './configurator';

import type {FullPackConfig, UserlandPack} from './types/internal';
import type {FullPackConfig, Mutable, UserlandPack} from './types/internal';

import {defineConfig, devices} from '@playwright/test';

Expand Down Expand Up @@ -83,6 +85,13 @@ if (isDebug) {
setReadonlyProperty(userlandPack, 'testTimeout', maxTimeoutInMs);
}

const pathToTestFile = e2edEnvironment[PATH_TO_TEST_FILE_VARIABLE_NAME];

const testMatch =
pathToTestFile === undefined
? (userlandPack.testFileGlobs as Mutable<typeof userlandPack.testFileGlobs>)
: join('**', pathToTestFile);

const playwrightConfig = defineConfig({
fullyParallel: true,

Expand All @@ -99,7 +108,7 @@ const playwrightConfig = defineConfig({

testDir: join(relativePathFromInstalledE2edToRoot, TESTS_DIRECTORY_PATH),
testIgnore: '**/*.skip.ts',
testMatch: userlandPack.testFileGlobs as (typeof userlandPack.testFileGlobs)[number][],
testMatch,

timeout: userlandPack.testTimeout,

Expand All @@ -117,6 +126,8 @@ const playwrightConfig = defineConfig({
},

workers: userlandPack.concurrency,

...userlandPack.overriddenConfigFields,
});

const config: FullPackConfig = Object.assign(playwrightConfig, userlandPack);
Expand Down
6 changes: 6 additions & 0 deletions src/constants/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export const isDebug = Boolean(e2edEnvironment.E2ED_DEBUG);
*/
export const PATH_TO_PACK_VARIABLE_NAME = '__INTERNAL_E2ED_PATH_TO_PACK';

/**
* Name of e2ed environment variable with path to one test file.
* @internal
*/
export const PATH_TO_TEST_FILE_VARIABLE_NAME = '__INTERNAL_E2ED_PATH_TO_TEST_FILE';

/**
* Name of e2ed environment variable with run environment.
* @internal
Expand Down
1 change: 1 addition & 0 deletions src/constants/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {isDebug, RunEnvironment} from './environment';
export {
e2edEnvironment,
PATH_TO_PACK_VARIABLE_NAME,
PATH_TO_TEST_FILE_VARIABLE_NAME,
RUN_ENVIRONMENT_VARIABLE_NAME,
RUN_LABEL_VARIABLE_NAME,
START_TIME_IN_MS_VARIABLE_NAME,
Expand Down
14 changes: 7 additions & 7 deletions src/types/config/ownE2edConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {PlaywrightTestConfig} from '@playwright/test';

import type {FullMocksConfig} from '../fullMocks';
import type {MapBackendResponseToLog, MapLogPayload, MapLogPayloadInReport} from '../log';
import type {MaybePromise} from '../promise';
Expand Down Expand Up @@ -46,12 +48,6 @@ export type OwnE2edConfig<
liteReport: LiteReport<CustomPackProperties, CustomReportProperties, SkipTests, TestMeta>,
) => MaybePromise<CustomReportProperties | Void>)[];

/**
* Enables Chrome DevTools Protocol for browser control in tests (instead of `testcafe-hammerhead`).
* {@link https://chromedevtools.github.io/devtools-protocol/}
*/
enableChromeDevToolsProtocol: boolean;

/**
* Enables headless mode (if browser supports such mode).
*/
Expand Down Expand Up @@ -149,9 +145,13 @@ export type OwnE2edConfig<
*/
maxRetriesCountInDocker: number;

/**
* If not `null`, then this value will override fields of internal Playwright config.
*/
overriddenConfigFields: PlaywrightTestConfig | null;

/**
* If not `null`, then this value will override the browser's user agent in tests.
* This override only works when `enableChromeDevToolsProtocol` is `true`.
*/
overriddenUserAgent: string | null;

Expand Down
2 changes: 2 additions & 0 deletions src/types/environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {RunEnvironment} from '../configurator';
import type {
PATH_TO_PACK_VARIABLE_NAME,
PATH_TO_TEST_FILE_VARIABLE_NAME,
RUN_ENVIRONMENT_VARIABLE_NAME,
RUN_LABEL_VARIABLE_NAME,
START_TIME_IN_MS_VARIABLE_NAME,
Expand All @@ -19,6 +20,7 @@ export type E2edEnvironment = {
['E2ED_PATH_TO_TS_CONFIG_OF_PROJECT_FROM_ROOT']?: string;
['E2ED_TERMINATION_SIGNAL']?: NodeJS.Signals;
[PATH_TO_PACK_VARIABLE_NAME]?: string;
[PATH_TO_TEST_FILE_VARIABLE_NAME]?: string;
['PWD']?: string;
['PWDEBUG']?: 'console';
[RUN_ENVIRONMENT_VARIABLE_NAME]?: RunEnvironment;
Expand Down
20 changes: 0 additions & 20 deletions src/utils/collectTestFilePaths.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils/generalLog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export {writeLogsToFile} from './logFile';
export {logStartE2edError} from './logStartE2edError';
export {removeStyleFromString} from './removeStyleFromString';
/** @internal */
export {getSuccessfulTestRuns} from './successfulTestRunCount';
export {getSuccessfulTestFilePaths} from './successfulTestRuns';
/** @internal */
export {truncateArrayForLogs} from './truncateArrayForLogs';
Loading

0 comments on commit 6b6d886

Please sign in to comment.