Skip to content

Commit

Permalink
FI-1237 fix: status of local e2ed run
Browse files Browse the repository at this point in the history
fix: remove `bin-v8-flags-filter` package
fix: respect `expect` and `global` timeouts in config
fix: error in internal `selectorCustomMethods` test
chore: update version of node in GitHub Actions
fix: add logs to `setHeadersAndNavigateToUrl` action
fix: urls of screenshots in HTML report
  • Loading branch information
uid11 committed Aug 7, 2024
1 parent 750b54c commit 64df235
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 136 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/setup-node@v4
with:
cache: npm
node-version: 20.10.0
node-version: 20.16.0
- run: npm ci
- run: npm run build
- run: npm run build:docker
Expand All @@ -22,7 +22,7 @@ jobs:
- uses: actions/setup-node@v4
with:
cache: npm
node-version: 20.10.0
node-version: 20.16.0
- run: npm ci
- run: npm run build
- run: npm run lint
Expand All @@ -34,7 +34,7 @@ jobs:
- uses: actions/setup-node@v4
with:
cache: npm
node-version: 20.10.0
node-version: 20.16.0
- run: npm ci
- run: npm run build
- run: npm run test:local
Expand Down
3 changes: 1 addition & 2 deletions autotests/packs/allTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ const browserFlags = [

const browser = isLocalRun ? 'chrome' : 'chromium';

const filterTestsIntoPack: FilterTestsIntoPack = ({filePath, options}) =>
options.meta.testId !== '13' && !filePath.endsWith('.skip.ts');
const filterTestsIntoPack: FilterTestsIntoPack = ({options}) => options.meta.testId !== '13';

const overriddenUserAgent =
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.35 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.35';
Expand Down
2 changes: 1 addition & 1 deletion autotests/tests/e2edReportExample/selectorCustomMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ test('selector custom methods', {meta: {testId: '15'}}, async () => {
await expect(
reportPage.testRunButton.nth(2).getLocatorParameter('status'),
'nested selectors also get custom methods',
).eql('passed');
).match(/broken|passed/);
});
8 changes: 1 addition & 7 deletions package-lock.json

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

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "uid11",
"license": "MIT",
"bin": {
"e2ed": "bin/localEntrypoint.js",
"e2ed": "bin/runE2edInLocalEnvironment.js",
"e2ed-init": "bin/init.js"
},
"bugs": "https://github.com/joomcode/e2ed/issues",
Expand All @@ -25,7 +25,6 @@
},
"dependencies": {
"@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"
Expand Down Expand Up @@ -92,7 +91,7 @@
"postbuild:remove": "touch ./build/node_modules/e2ed/types/index.js",
"build:copy": "npm run build:copy:bin && npm run build:copy:scripts && npm run build:copy:meta && npm run build:copy:example && npm run build:copy:tsconfig",
"build:copy:bin": "cp ./bin/dockerEntrypoint.sh ./build/node_modules/e2ed/bin",
"postbuild:copy:bin": "npm run make:executable build/node_modules/e2ed/bin/init.js build/node_modules/e2ed/bin/localEntrypoint.js build/node_modules/e2ed/bin/runE2edInDockerEnvironment.js",
"postbuild:copy:bin": "npm run make:executable build/node_modules/e2ed/bin/init.js build/node_modules/e2ed/bin/runE2edInLocalEnvironment.js build/node_modules/e2ed/bin/runE2edInDockerEnvironment.js",
"build:copy:scripts": "cp ./build/scripts/*.js ./build",
"build:copy:meta": "cp -R ./LICENSE ./logo.svg ./README.md ./styles ./build/node_modules/e2ed",
"postbuild:copy:meta": "node ./build/writePrunedPackageJson.js",
Expand All @@ -117,7 +116,7 @@
"test:docker:copy": "cp -R ./build/autotests ./build/docker/autotests && cp ./build/tsconfig.json ./build/docker",
"posttest:docker:copy": "rm -rf ./build/docker/autotests/reports && ./bin/addPackageJsonToBuildDocker.sh",
"test:docker": "(cd ./build/docker && E2ED_ORIGIN=https://google.com ./autotests/bin/runDocker.sh ./autotests/packs/allTests.ts)",
"test:local": "(cd ./build && E2ED_ORIGIN=https://google.com ./node_modules/e2ed/bin/localEntrypoint.js ./autotests/packs/allTests.ts)"
"test:local": "(cd ./build && E2ED_ORIGIN=https://google.com ./node_modules/e2ed/bin/runE2edInLocalEnvironment.js ./autotests/packs/allTests.ts)"
},
"sideEffects": false,
"types": "index.d.ts"
Expand Down
16 changes: 12 additions & 4 deletions src/actions/setHeadersAndNavigateToUrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {AsyncLocalStorage} from 'node:async_hooks';

import {LogEventType} from '../constants/internal';
import {getPage} from '../useContext';
import {log} from '../utils/log';
import {applyHeadersMapper} from '../utils/requestHooks';

import {navigateToUrl} from './navigateToUrl';
Expand All @@ -15,7 +19,7 @@ export const setHeadersAndNavigateToUrl = async (url: Url, options: MapOptions):

await page.route(
url,
async (route) => {
AsyncLocalStorage.bind(async (route) => {
if (mapResponseHeaders === undefined) {
return route.fallback();
}
Expand All @@ -25,21 +29,25 @@ export const setHeadersAndNavigateToUrl = async (url: Url, options: MapOptions):

applyHeadersMapper(headers, mapResponseHeaders);

log(`Map response headers for ${url}`, {headers}, LogEventType.InternalAction);

return route.fulfill({headers, response});
},
}),
{times: 1},
);

if (mapRequestHeaders !== undefined) {
await page.route(
url,
async (route, request) => {
AsyncLocalStorage.bind(async (route, request) => {
const headers = request.headers();

applyHeadersMapper(headers, mapRequestHeaders);

log(`Map request headers for ${url}`, {headers}, LogEventType.InternalAction);

await route.fallback({headers});
},
}),
{times: 1},
);
}
Expand Down
12 changes: 8 additions & 4 deletions src/actions/takeElementScreenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ export const takeElementScreenshot = async (
): Promise<void> => {
const description = getDescriptionFromSelector(selector);

log('Take a screenshot of the element', {description, options}, LogEventType.InternalAction);
const {path: pathToScreenshot, ...optionsWithoutPath} = options;

const {path} = options;
log(
'Take a screenshot of the element',
{description, pathToScreenshot, ...optionsWithoutPath},
LogEventType.InternalAction,
);

if (path !== undefined) {
if (pathToScreenshot !== undefined) {
// eslint-disable-next-line no-param-reassign
options.path = join(SCREENSHOTS_DIRECTORY_PATH, path);
options.path = join(SCREENSHOTS_DIRECTORY_PATH, pathToScreenshot);
}

await selector.getPlaywrightLocator().screenshot(options);
Expand Down
16 changes: 10 additions & 6 deletions src/actions/takeScreenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ type Options = Parameters<Page['screenshot']>[0];
* Takes a screenshot of the tested page.
*/
export const takeScreenshot = async (options: Options = {}): Promise<void> => {
log('Take a screenshot of the page', {...options}, LogEventType.InternalAction);
const {path: pathToScreenshot, ...optionsWithoutPath} = options;

const page = getPage();

const {path} = options;
log(
'Take a screenshot of the page',
{pathToScreenshot, ...optionsWithoutPath},
LogEventType.InternalAction,
);

if (path !== undefined) {
if (pathToScreenshot !== undefined) {
// eslint-disable-next-line no-param-reassign
options.path = join(SCREENSHOTS_DIRECTORY_PATH, path);
options.path = join(SCREENSHOTS_DIRECTORY_PATH, pathToScreenshot);
}

const page = getPage();

await page.screenshot(options);
};
13 changes: 0 additions & 13 deletions src/bin/localEntrypoint.ts

This file was deleted.

33 changes: 20 additions & 13 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ const absoluteCompiledUserlandPackPath = join(
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require
const userlandPack = require<{pack: UserlandPack}>(absoluteCompiledUserlandPackPath).pack;

const pathToTestFile = e2edEnvironment[PATH_TO_TEST_FILE_VARIABLE_NAME];

if (pathToTestFile !== undefined) {
setReadonlyProperty(userlandPack, 'testFileGlobs', [join('**', pathToTestFile)]);
}

assertUserlandPack(userlandPack);

const {
Expand Down Expand Up @@ -85,16 +91,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({
expect: {timeout: userlandPack.assertionTimeout},

fullyParallel: true,

globalTimeout: userlandPack.packTimeout,

outputDir: join(relativePathFromInstalledE2edToRoot, INTERNAL_REPORTS_DIRECTORY_PATH),

projects: [
Expand All @@ -107,11 +110,15 @@ const playwrightConfig = defineConfig({
retries: isLocalRun ? 0 : userlandPack.maxRetriesCountInDocker - 1,

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

timeout: userlandPack.testTimeout,

workers: userlandPack.concurrency,

...userlandPack.overriddenConfigFields,

use: {
actionTimeout: userlandPack.testIdleTimeout,

Expand All @@ -122,12 +129,12 @@ const playwrightConfig = defineConfig({

navigationTimeout: userlandPack.pageRequestTimeout,

trace: 'on-first-retry',
},
trace: 'retain-on-failure',

workers: userlandPack.concurrency,
viewport: {height: userlandPack.viewportHeight, width: userlandPack.viewportWidth},

...userlandPack.overriddenConfigFields,
...userlandPack.overriddenConfigFields?.use,
},
});

const config: FullPackConfig = Object.assign(playwrightConfig, userlandPack);
Expand Down
8 changes: 4 additions & 4 deletions src/configurator/runEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {RunEnvironment} from './constants';
export let runEnvironment = e2edEnvironment[RUN_ENVIRONMENT_VARIABLE_NAME] ?? RunEnvironment.Local;

/**
* `true`, if run e2ed in local environment, and `false` otherwise.
* `true`, if run e2ed in docker environment, and `false` otherwise.
*/
export let isLocalRun = runEnvironment === RunEnvironment.Local;
export let isDockerRun = runEnvironment === RunEnvironment.Docker;

/**
* `true`, if run e2ed in docker environment, and `false` otherwise.
* `true`, if run e2ed in local environment, and `false` otherwise.
*/
export let isDockerRun = runEnvironment === RunEnvironment.Docker;
export let isLocalRun = runEnvironment === RunEnvironment.Local;

/**
* Set current run environment before e2ed start.
Expand Down
21 changes: 1 addition & 20 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable import/no-default-export, import/no-unused-modules, import/unambiguous */
/* eslint-disable import/no-unused-modules, import/unambiguous */

/**
* Extends node's require function.
Expand All @@ -9,22 +9,3 @@ interface NodeRequire {
// eslint-disable-next-line @typescript-eslint/prefer-function-type
<ModuleExports = import('./utils').Any>(modulePath: string): ModuleExports;
}

/**
* Package for filtering V8 command line flags when run TestCafe via CLI.
* @internal
*/
declare module 'bin-v8-flags-filter' {
type Options = Readonly<{
forcedKillDelay?: number;
ignore?: string[];
useShutdownMessage?: boolean;
}>;

/**
* Filters out `nodejs` cli options and runs node module on `cliPath`.
*/
const v8FlagsFilter: (cliPath: string, options: Options) => void;

export default v8FlagsFilter;
}
14 changes: 13 additions & 1 deletion src/utils/events/registerStartE2edRunEvent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import {RunEnvironment} from '../../configurator';
import {EVENTS_DIRECTORY_PATH, ExitCode, TMP_DIRECTORY_PATH} from '../../constants/internal';
import {
e2edEnvironment,
EVENTS_DIRECTORY_PATH,
ExitCode,
PATH_TO_TEST_FILE_VARIABLE_NAME,
TMP_DIRECTORY_PATH,
} from '../../constants/internal';

import {getFullPackConfig, updateConfig} from '../config';
import {getPathToPack, setDotEnvValuesToEnvironment} from '../environment';
Expand Down Expand Up @@ -27,6 +33,12 @@ export const registerStartE2edRunEvent = async (): Promise<void> => {
errorSettingDotEnv = error;
});

const pathToTestFile = process.argv[2];

if (pathToTestFile !== undefined) {
e2edEnvironment[PATH_TO_TEST_FILE_VARIABLE_NAME] = pathToTestFile;
}

let compileErrors: readonly Readonly<Record<string, string>>[] = [];
let configCompileTimeWithUnits = '';

Expand Down
6 changes: 1 addition & 5 deletions src/utils/report/collectReportData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ export const collectReportData = async ({
}: FullEventsData): Promise<ReportData> => {
const {liteReportFileName, reportFileName} = getFullPackConfig();

const errors = await getReportErrors(
startInfo.runEnvironment,
fullTestRuns,
notIncludedInPackTests,
);
const errors = await getReportErrors(fullTestRuns, notIncludedInPackTests);

assertThatTestNamesAndFilePathsAreUnique(fullTestRuns);

Expand Down
Loading

0 comments on commit 64df235

Please sign in to comment.