Skip to content

Commit

Permalink
Merge pull request #33 from joomcode/feature/add-get-modules-graph
Browse files Browse the repository at this point in the history
feat: add get modules graph
  • Loading branch information
uid11 authored Sep 21, 2023
2 parents e9ce127 + 555daf5 commit 48c3e36
Show file tree
Hide file tree
Showing 50 changed files with 429 additions and 270 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ rules:
- src/*/internal.ts
- src/bin/*.ts
- src/createLocator.ts
- src/getModulesGraph.ts
- src/globby.ts
- src/esm/testcafe.ts
- src/index.ts
- src/testcafe.ts
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ COPY ./package-lock.json .
RUN npm install --legacy-peer-deps=true --no-save --omit=dev --omit=peer && npm cache clean --force
RUN rm -rf package-lock.json ./node_modules/@types ./node_modules/.bin ./node_modules/.package-lock.json
RUN mv ./node_modules/create-locator /node_modules/create-locator
RUN mv ./node_modules/get-modules-graph /node_modules/get-modules-graph
COPY ./node_modules/typescript ./node_modules/typescript
WORKDIR /

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ If `null`, the report will not be saved.
`skipTests: SkipTests`: this setting allows you to describe a set of skipped tests in a custom form.
You can define the `SkipTests` type and `skipTests` processing rules in the hook `autotests/hooks/isTestSkipped.ts`.

`stabilizationInterval: number`: default stabilization interval for `waitForInterfaceStabilization` action.

`takeFullPageScreenshotOnError: boolean`: if `true`, then takes a screenshot of the full page
(not just the viewport) at the time of the test error, for display in the HTML report.

Expand Down
1 change: 1 addition & 0 deletions autotests/packs/allTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const pack: Pack = {
reportFileName: 'report.html',
selectorTimeout: 10_000,
skipTests,
stabilizationInterval: 500,
takeFullPageScreenshotOnError: false,
takeViewportScreenshotOnError: true,
testFileGlobs: ['./autotests/tests/**/*.ts', '!**/*.skip.ts'],
Expand Down
2 changes: 1 addition & 1 deletion autotests/skipTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {SkipTests} from './types/skipTests';
*/
export const skipTests: SkipTests = [
{
reason: 'Skip for testing skipping mechanism',
reason: 'Skip for testing skipping mechanism (with link [Google](https://google.com))',
testIds: ['4'],
unskipTaskUrl: 'https://tasktracker.com/3',
},
Expand Down
2 changes: 1 addition & 1 deletion autotests/tests/main/exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ it('exists', {meta: {testId: '1'}, testIdleTimeout: 35_000, testTimeout: 90_000}

await expect(mainPage.body.find('input').exists, 'page contains some input element').ok();

await pressKey('enter');
await pressKey('enter', {stabilizationInterval: 300});

const [requestWithQuery, successfulResponse] = await Promise.all([
waitForRequest(({url}) => url.includes(searchQuery)),
Expand Down
323 changes: 183 additions & 140 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@
"dependencies": {
"bin-v8-flags-filter": "1.2.0",
"create-locator": "0.0.17",
"get-modules-graph": "0.0.8",
"globby": "11.1.0",
"pngjs": "7.0.0",
"testcafe-without-typecheck": "3.3.0-rc.1"
},
"devDependencies": {
"@types/node": "20.5.7",
"@typescript-eslint/eslint-plugin": "6.5.0",
"@typescript-eslint/parser": "6.5.0",
"@types/node": "20.6.3",
"@typescript-eslint/eslint-plugin": "6.7.2",
"@typescript-eslint/parser": "6.7.2",
"assert-modules-support-case-insensitive-fs": "1.0.1",
"assert-package-lock-is-consistent": "1.0.0",
"eslint": "8.48.0",
"eslint": "8.49.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.28.1",
Expand All @@ -58,6 +59,8 @@
"./context": "./context/index.js",
"./createLocator": "./createLocator.js",
"./generators": "./generators/index.js",
"./getModulesGraph": "./getModulesGraph.js",
"./globby": "./globby.js",
"./selectors": "./selectors/index.js",
"./testcafe": {
"import": "./esm/testcafe.mjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const assertDistanceBetweenSelectorsLte = async (
const distance = await getDistanceBetweenSelectors(selectorA, selectorB);
const message = `distance between selectors is less than or equal to ${maxDistance}`;

log(`Assert that ${message}`, {distance, maxDistance}, LogEventType.InternalAssert);
log(`Asserts that ${message}`, {distance, maxDistance}, LogEventType.InternalAssert);

// TODO: support Smart Assertions
await expect(distance, message).lte(maxDistance);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {LogEventType} from '../../../constants/internal';
import {expect} from '../../../expect';
import {getLocatorFromSelector} from '../../../utils/locators';
import {getDescriptionFromSelector} from '../../../utils/locators';
import {log} from '../../../utils/log';
import {isSelectorEntirelyInViewport} from '../../../utils/viewport';

Expand All @@ -12,7 +12,7 @@ import type {Selector} from '../../../types/internal';
*/
export const assertSelectorEntirelyInViewport = async (selector: Selector): Promise<void> => {
const isEntirelyInViewport = await isSelectorEntirelyInViewport(selector);
const locator = getLocatorFromSelector(selector);
const locator = getDescriptionFromSelector(selector);
const message = 'selector is entirely in the viewport';

log(`Asserts that ${message}`, {locator}, LogEventType.InternalAssert);
Expand Down
4 changes: 2 additions & 2 deletions src/actions/asserts/viewport/assertSelectorInViewport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {LogEventType} from '../../../constants/internal';
import {expect} from '../../../expect';
import {getLocatorFromSelector} from '../../../utils/locators';
import {getDescriptionFromSelector} from '../../../utils/locators';
import {log} from '../../../utils/log';
import {isSelectorInViewport} from '../../../utils/viewport';

Expand All @@ -12,7 +12,7 @@ import type {Selector} from '../../../types/internal';
*/
export const assertSelectorInViewport = async (selector: Selector): Promise<void> => {
const isInViewport = await isSelectorInViewport(selector);
const locator = getLocatorFromSelector(selector);
const locator = getDescriptionFromSelector(selector);
const message = 'selector is in the viewport';

log(`Asserts that ${message}`, {locator}, LogEventType.InternalAssert);
Expand Down
4 changes: 2 additions & 2 deletions src/actions/clearUpload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {LogEventType} from '../constants/internal';
import {testController} from '../testController';
import {getLocatorFromSelector} from '../utils/locators';
import {getDescriptionFromSelector} from '../utils/locators';
import {log} from '../utils/log';

import type {Selector, TestCafeSelector} from '../types/internal';
Expand All @@ -9,7 +9,7 @@ import type {Selector, TestCafeSelector} from '../types/internal';
* Removes all file paths from the specified file upload input.
*/
export const clearUpload = (selector: Selector): Promise<void> => {
const locator = getLocatorFromSelector(selector);
const locator = getDescriptionFromSelector(selector);

log('Remove all file paths from file upload input', {locator}, LogEventType.InternalAction);

Expand Down
21 changes: 14 additions & 7 deletions src/actions/click.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import {LogEventType} from '../constants/internal';
import {testController} from '../testController';
import {getLocatorFromSelector} from '../utils/locators';
import {getDescriptionFromSelector} from '../utils/locators';
import {log} from '../utils/log';

import {waitForInterfaceStabilization} from './waitFor';

import type {Selector, TestCafeSelector} from '../types/internal';
import type {Selector, TestCafeSelector, WithStabilizationInterval} from '../types/internal';

type Options = Parameters<typeof testController.click>[1];
type Options = Parameters<typeof testController.click>[1] & WithStabilizationInterval;

/**
* Clicks an element.
*/
export const click = async (selector: Selector, options?: Options): Promise<void> => {
const locator = getLocatorFromSelector(selector);
export const click = async (
selector: Selector,
{stabilizationInterval, ...options}: Options = {},
): Promise<void> => {
const locator = getDescriptionFromSelector(selector);
const withLocator = locator ? ` with locator ${locator}` : '';

log(`Click an element${withLocator}`, {options}, LogEventType.InternalAction);
log(
`Click an element${withLocator}`,
{...options, stabilizationInterval},
LogEventType.InternalAction,
);

await testController.click(selector as TestCafeSelector, options);

await waitForInterfaceStabilization();
await waitForInterfaceStabilization(stabilizationInterval);
};
18 changes: 11 additions & 7 deletions src/actions/dispatchEvent.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import {LogEventType} from '../constants/internal';
import {testController} from '../testController';
import {getLocatorFromSelector} from '../utils/locators';
import {getDescriptionFromSelector} from '../utils/locators';
import {log} from '../utils/log';

import {waitForInterfaceStabilization} from './waitFor';

import type {Selector, TestCafeSelector} from '../types/internal';
import type {Selector, TestCafeSelector, WithStabilizationInterval} from '../types/internal';

type Options = Record<string, unknown>;
type Options = Record<string, unknown> & WithStabilizationInterval;

/**
* Dispatches an event over a specified DOM element.
*/
export const dispatchEvent = async (
selector: Selector,
eventName: string,
options?: Options,
{stabilizationInterval, ...options}: Options = {},
): Promise<void> => {
const locator = getLocatorFromSelector(selector);
const locator = getDescriptionFromSelector(selector);

log('Click an element', {locator, options}, LogEventType.InternalAction);
log(
'Dispatches an event over a specified element',
{locator, ...options, stabilizationInterval},
LogEventType.InternalAction,
);

await testController.dispatchEvent(selector as TestCafeSelector, eventName, options);

await waitForInterfaceStabilization();
await waitForInterfaceStabilization(stabilizationInterval);
};
21 changes: 14 additions & 7 deletions src/actions/doubleClick.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import {LogEventType} from '../constants/internal';
import {testController} from '../testController';
import {getLocatorFromSelector} from '../utils/locators';
import {getDescriptionFromSelector} from '../utils/locators';
import {log} from '../utils/log';

import {waitForInterfaceStabilization} from './waitFor';

import type {Selector, TestCafeSelector} from '../types/internal';
import type {Selector, TestCafeSelector, WithStabilizationInterval} from '../types/internal';

type Options = Parameters<typeof testController.doubleClick>[1];
type Options = Parameters<typeof testController.doubleClick>[1] & WithStabilizationInterval;

/**
* Double-clicks an element.
*/
export const doubleClick = async (selector: Selector, options?: Options): Promise<void> => {
const locator = getLocatorFromSelector(selector);
export const doubleClick = async (
selector: Selector,
{stabilizationInterval, ...options}: Options = {},
): Promise<void> => {
const locator = getDescriptionFromSelector(selector);
const withLocator = locator ? ` with locator ${locator}` : '';

log(`Double-click an element${withLocator}`, {options}, LogEventType.InternalAction);
log(
`Double-click an element${withLocator}`,
{...options, stabilizationInterval},
LogEventType.InternalAction,
);

await testController.doubleClick(selector as TestCafeSelector, options);

await waitForInterfaceStabilization();
await waitForInterfaceStabilization(stabilizationInterval);
};
14 changes: 7 additions & 7 deletions src/actions/drag.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {LogEventType} from '../constants/internal';
import {testController} from '../testController';
import {getLocatorFromSelector} from '../utils/locators';
import {getDescriptionFromSelector} from '../utils/locators';
import {log} from '../utils/log';

import {waitForInterfaceStabilization} from './waitFor';

import type {Selector, TestCafeSelector} from '../types/internal';
import type {Selector, TestCafeSelector, WithStabilizationInterval} from '../types/internal';

type Options = Parameters<typeof testController.drag>[3];
type Options = Parameters<typeof testController.drag>[3] & WithStabilizationInterval;

/**
* Drags an element by an offset.
Expand All @@ -16,18 +16,18 @@ export const drag = async (
selector: Selector,
dragOffsetX: number,
dragOffsetY: number,
options?: Options,
{stabilizationInterval, ...options}: Options = {},
// eslint-disable-next-line max-params
): Promise<void> => {
const locator = getLocatorFromSelector(selector);
const locator = getDescriptionFromSelector(selector);

log(
'Drag an element by an offset',
{dragOffsetX, dragOffsetY, locator, options},
{dragOffsetX, dragOffsetY, locator, ...options, stabilizationInterval},
LogEventType.InternalAction,
);

await testController.drag(selector as TestCafeSelector, dragOffsetX, dragOffsetY, options);

await waitForInterfaceStabilization();
await waitForInterfaceStabilization(stabilizationInterval);
};
16 changes: 8 additions & 8 deletions src/actions/dragToElement.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import {LogEventType} from '../constants/internal';
import {testController} from '../testController';
import {getLocatorFromSelector} from '../utils/locators';
import {getDescriptionFromSelector} from '../utils/locators';
import {log} from '../utils/log';

import {waitForInterfaceStabilization} from './waitFor';

import type {Selector, TestCafeSelector} from '../types/internal';
import type {Selector, TestCafeSelector, WithStabilizationInterval} from '../types/internal';

type Options = Parameters<typeof testController.dragToElement>[2];
type Options = Parameters<typeof testController.dragToElement>[2] & WithStabilizationInterval;

/**
* Drags an element onto another one.
*/
export const dragToElement = async (
selector: Selector,
destinationSelector: Selector,
options?: Options,
{stabilizationInterval, ...options}: Options = {},
): Promise<void> => {
const locator = getLocatorFromSelector(selector);
const destinationLocator = getLocatorFromSelector(destinationSelector);
const locator = getDescriptionFromSelector(selector);
const destinationLocator = getDescriptionFromSelector(destinationSelector);

log(
'Drag an element onto another one',
{destinationLocator, locator, options},
{destinationLocator, locator, ...options, stabilizationInterval},
LogEventType.InternalAction,
);

Expand All @@ -32,5 +32,5 @@ export const dragToElement = async (
options,
);

await waitForInterfaceStabilization();
await waitForInterfaceStabilization(stabilizationInterval);
};
4 changes: 2 additions & 2 deletions src/actions/getBrowserConsoleMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {testController} from '../testController';
import {log} from '../utils/log';

type ConsoleMessages = ReturnType<typeof testController.getBrowserConsoleMessages> extends Promise<
infer T
infer Type
>
? T
? Type
: never;

/**
Expand Down
21 changes: 14 additions & 7 deletions src/actions/hover.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import {LogEventType} from '../constants/internal';
import {testController} from '../testController';
import {getLocatorFromSelector} from '../utils/locators';
import {getDescriptionFromSelector} from '../utils/locators';
import {log} from '../utils/log';

import {waitForInterfaceStabilization} from './waitFor';

import type {Selector, TestCafeSelector} from '../types/internal';
import type {Selector, TestCafeSelector, WithStabilizationInterval} from '../types/internal';

type Options = Parameters<typeof testController.hover>[1];
type Options = Parameters<typeof testController.hover>[1] & WithStabilizationInterval;

/**
* Hovers the mouse pointer over an element.
*/
export const hover = async (selector: Selector, options?: Options): Promise<void> => {
const locator = getLocatorFromSelector(selector);
export const hover = async (
selector: Selector,
{stabilizationInterval, ...options}: Options = {},
): Promise<void> => {
const locator = getDescriptionFromSelector(selector);

log('Hover the mouse pointer over an element', {locator, options}, LogEventType.InternalAction);
log(
'Hover the mouse pointer over an element',
{locator, ...options, stabilizationInterval},
LogEventType.InternalAction,
);

await testController.hover(selector as TestCafeSelector, options);

await waitForInterfaceStabilization();
await waitForInterfaceStabilization(stabilizationInterval);
};
Loading

0 comments on commit 48c3e36

Please sign in to comment.