Skip to content

Commit

Permalink
FI-1504 fix: rename locatorId to testId everywhere
Browse files Browse the repository at this point in the history
fix: write `endTimeInMs` after pack hooks
fix: remove unnecessary options in ESLint config
chore: update `create-locator` to 0.0.27
chore: update `@types/node` and `typescript`
  • Loading branch information
uid11 committed Jan 10, 2025
1 parent d1e2d38 commit dcdd4b9
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 74 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ parserOptions:
sourceType: module
plugins: [simple-import-sort, typescript-sort-keys]
root: true
ignorePatterns: [bin/forks/*/package, build, local]
ignorePatterns: [build, local]
rules:
class-methods-use-this: off
complexity: [error, {max: 10}]
Expand Down Expand Up @@ -74,7 +74,7 @@ rules:
import/no-unassigned-import: error
import/no-unresolved:
- error
- {commonjs: true, ignore: [autotests, e2ed/testcafe]}
- {commonjs: true, ignore: [autotests]}
import/no-unused-modules:
- error
- ignoreExports:
Expand Down Expand Up @@ -109,7 +109,7 @@ rules:
- ':not(MethodDefinition, Property) > FunctionExpression'
no-return-await: off
no-shadow: off
no-underscore-dangle: [error, {allow: [_onConfigureResponse]}]
no-underscore-dangle: error
no-unused-expressions: off
no-useless-constructor: off
no-use-before-define: off
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(The MIT License)

Copyright (c) 2021-2024 SIA Joom
Copyright (c) 2021-2025 SIA Joom

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion autotests/packs/allTests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file Pack file (file with configuration of pack).
* Do not import anything (from `utils`, etc) into this file other than
* the types and values from `../configurator`, `e2ed/configurator`, `e2ed/constants`
* the types and values from `../configurator`, `e2ed/configurator`
* or other packs (because the pack is compiled separately from the tests themselves
* and has separate TypeScript scope).
*/
Expand Down
8 changes: 8 additions & 0 deletions autotests/packs/local.example.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* @file Pack for local development.
* Do not import anything (from `utils`, etc) into this file other than
* the types and values from `../configurator`, `e2ed/configurator`
* or other packs (because the pack is compiled separately from the tests themselves
* and has separate TypeScript scope).
*/

import {pack as allTestsPack} from './allTests';

import type {Pack} from 'autotests/configurator';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export class E2edReportExample extends Page<CustomPageParams> {
/**
* Button tabs in navigation bar with test retries.
*/
readonly navigationRetriesButton: Selector =
this.navigationRetries.findByLocatorId('RetryButton');
readonly navigationRetriesButton: Selector = this.navigationRetries.findByTestId('RetryButton');

/**
* Selected button tab in navigation bar with test retries.
Expand All @@ -52,7 +51,7 @@ export class E2edReportExample extends Page<CustomPageParams> {
/**
* Test run button.
*/
readonly testRunButton: Selector = this.testRunsList.findByLocatorId('TestRunButton');
readonly testRunButton: Selector = this.testRunsList.findByTestId('TestRunButton');

/**
* List of test runs of retry.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {cssSelector} from 'autotests/selectors';
import {getCssSelector} from 'autotests/selectors';

import type {Selector} from 'e2ed/types';

Expand All @@ -8,7 +8,7 @@ const testId = 'TestRunButton';
* `TestRun` button.
*/
export class TestRunButton {
static readonly parameters: string = cssSelector(testId, 'parameters');
static readonly parameters: string = getCssSelector(testId, 'parameters');

readonly selector: Selector;

Expand Down
2 changes: 1 addition & 1 deletion autotests/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {createSelector} from './createSelector';
export {htmlElementSelector} from './htmlElementSelector';
export {inputSelector} from './inputSelector';
export {cssSelector, locator, testId} from './locator';
export {getCssSelector, getTestId, locator} from './locator';
17 changes: 9 additions & 8 deletions autotests/selectors/locator.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {attributesOptions} from 'autotests/constants';
import {createTestUtils} from 'e2ed/createLocator';
import {createTestLocator} from 'e2ed/createLocator';

import {createSelector} from './createSelector';

import type {LocatorFunction} from 'create-locator';
import type {Selector} from 'e2ed/types';

/**
* Test utils, that produce `Selector`, CSS selector string and `testId` string.
* Locator kit with `locator` function, that produce `Selector`,
* and additional `getSelector` and `getTestId` functions.
*/
const utils = createTestUtils({
const locatorKit = createTestLocator({
attributesOptions,
createLocatorByCssSelector: (selector) =>
createSelector(selector.replace('data-test-runhash', 'data-runhash')),
Expand All @@ -19,14 +20,14 @@ const utils = createTestUtils({
/**
* Locator, that produce `Selector`.
*/
export const locator: LocatorFunction<Selector> = utils.locator;
export const locator: LocatorFunction<Selector> = locatorKit.locator;

/**
* Locator, that produce CSS selector string.
* Get CSS selector string.
*/
export const cssSelector: LocatorFunction<string> = utils.selector;
export const getCssSelector: LocatorFunction<string> = locatorKit.getSelector;

/**
* Locator, that produce `testId` string.
* Get `testId` string.
*/
export const testId: LocatorFunction<string> = utils.testId;
export const getTestId: LocatorFunction<string> = locatorKit.getTestId;
2 changes: 1 addition & 1 deletion autotests/tests/e2edReportExample/selectorCustomMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('selector custom methods', {meta: {testId: '15'}}, async () => {
reportPage.navigationRetriesButtonSelected.getDescription(),
'selector has apropriate description',
).eql(
'[data-testid="RetriesButtons"].findByLocatorId(RetryButton).filterByLocatorParameter(selected, true)',
'[data-testid="RetriesButtons"].findByTestId(RetryButton).filterByLocatorParameter(selected, true)',
);

await click(reportPage.navigationRetriesButton.nth(0));
Expand Down
26 changes: 13 additions & 13 deletions autotests/tests/internalTypeTests/selectors.skip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@ import {createSelector, htmlElementSelector, locator} from 'autotests/selectors'
import type {Selector} from 'e2ed/types';

// @ts-expect-error: wrong number of arguments
htmlElementSelector.findByLocatorId();
htmlElementSelector.findByTestId();
// @ts-expect-error: wrong type of arguments
htmlElementSelector.findByLocatorId(0);
htmlElementSelector.findByTestId(0);
// ok
htmlElementSelector.findByLocatorId('id') satisfies Selector;
htmlElementSelector.findByTestId('id') satisfies Selector;
// ok
htmlElementSelector.findByLocatorId('id').findByLocatorId('id2') satisfies Selector;
htmlElementSelector.findByTestId('id').findByTestId('id2') satisfies Selector;
// ok
htmlElementSelector.findByLocatorId('id').find('.test-children') satisfies Selector;
htmlElementSelector.findByTestId('id').find('.test-children') satisfies Selector;
// ok
htmlElementSelector.find('body').findByLocatorId('id') satisfies Selector;
htmlElementSelector.find('body').findByTestId('id') satisfies Selector;

// ok
createSelector('id').findByLocatorId('id').find('body').findByLocatorId('id') satisfies Selector;
createSelector('id').findByTestId('id').find('body').findByTestId('id') satisfies Selector;

// ok
locator('id').findByLocatorId('id').find('body').findByLocatorId('id') satisfies Selector;
locator('id').findByTestId('id').find('body').findByTestId('id') satisfies Selector;

// @ts-expect-error: wrong number of arguments
locator();

// ok
htmlElementSelector.filterByLocatorId('id') satisfies Selector;
htmlElementSelector.filterByTestId('id') satisfies Selector;

// ok
htmlElementSelector.filterByLocatorParameter('prop', 'value') satisfies Selector;
// ok
htmlElementSelector.findByLocatorParameter('prop', 'value') satisfies Selector;

// ok
void htmlElementSelector.getLocatorId();
void htmlElementSelector.getTestId();

// @ts-expect-error: wrong number of arguments
void htmlElementSelector.getLocatorId('id');
void htmlElementSelector.getTestId('id');

// @ts-expect-error: TODO: should be ok
void htmlElementSelector.hasLocatorId() satisfies Promise<boolean>;
void htmlElementSelector.hasTestId() satisfies Promise<boolean>;

// @ts-expect-error: wrong number of arguments
void htmlElementSelector.hasLocatorId('id');
void htmlElementSelector.hasTestId('id');

// @ts-expect-error: wrong number of arguments
void htmlElementSelector.hasLocatorParameter();
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
},
"dependencies": {
"@playwright/test": "1.49.1",
"create-locator": "0.0.25",
"create-locator": "0.0.27",
"get-modules-graph": "0.0.11",
"globby": "11.1.0"
},
"devDependencies": {
"@playwright/browser-chromium": "1.49.1",
"@types/node": "22.10.2",
"@types/node": "22.10.5",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"assert-modules-support-case-insensitive-fs": "1.0.1",
Expand All @@ -45,7 +45,7 @@
"eslint-plugin-typescript-sort-keys": "3.3.0",
"husky": "9.1.7",
"prettier": "3.4.2",
"typescript": "5.7.2"
"typescript": "5.7.3"
},
"peerDependencies": {
"@types/node": ">=20",
Expand Down
4 changes: 2 additions & 2 deletions src/constants/attributesOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {AttributesOptions} from 'create-locator';
* Attributes options for locators.
* @internal
*/
export const attributesOptions = {
export const attributesOptions: AttributesOptions = {
parameterAttributePrefix: 'data-test-',
testIdAttribute: 'data-testid',
testIdSeparator: '-',
} as const satisfies AttributesOptions;
};
2 changes: 1 addition & 1 deletion src/createLocator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line no-restricted-syntax
export * from 'create-locator';
// eslint-disable-next-line import/no-internal-modules
export {createTestUtils} from 'create-locator/createTestUtils';
export {createTestLocator} from 'create-locator/createTestLocator';
export type {PARAMETERS} from 'create-locator/oldTypes';
// eslint-disable-next-line import/no-internal-modules
export {getCssSelectorFromAttributesChain} from 'create-locator/getCssSelectorFromAttributesChain';
7 changes: 6 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ export type {
PageClassType,
PageClassTypeArgs,
} from './pages';
export type {FilePathFromRoot, TestFilePath} from './paths';
export type {
AbsolutePathToDirectory,
DirectoryPathFromRoot,
FilePathFromRoot,
TestFilePath,
} from './paths';
export type {AsyncVoid, MaybePromise, Thenable} from './promise';
export type {
AnyObject,
Expand Down
20 changes: 10 additions & 10 deletions src/types/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,36 +69,36 @@ export type Selector = ReplaceObjectSelectors<SelectorClass> &
* Custom methods that `e2ed` adds to selector.
*/
export type SelectorCustomMethods = Readonly<{
/** Creates a selector that filters a matching set by locatorId. */
filterByLocatorId: (this: SelectorClass, locatorId: string) => SelectorClass;

/** Creates a selector that filters a matching set by locator parameter. */
filterByLocatorParameter: (
this: SelectorClass,
parameter: string,
value: string,
) => SelectorClass;

/** Finds all descendants of all nodes in the matching set and filters them by locatorId. */
findByLocatorId: (this: SelectorClass, locatorId: string) => SelectorClass;
/** Creates a selector that filters a matching set by testId. */
filterByTestId: (this: SelectorClass, testId: string) => SelectorClass;

/** Finds all descendants of all nodes in the matching set and filters them by locator parameter. */
findByLocatorParameter: (this: SelectorClass, parameter: string, value: string) => SelectorClass;

/** Finds all descendants of all nodes in the matching set and filters them by testId. */
findByTestId: (this: SelectorClass, testId: string) => SelectorClass;

/** Get string description of selector if any. */
getDescription: (this: SelectorClass) => string | undefined;

/** Returns the value of the locator id. */
getLocatorId: (this: SelectorClass) => Promise<string | null>;

/** Returns the value of the locator parameter. */
getLocatorParameter: (this: SelectorClass, parameter: string) => Promise<string | null>;

/** true if the element has the locator id. */
hasLocatorId: (this: SelectorClass) => Promise<boolean>;
/** Returns the value of the test id. */
getTestId: (this: SelectorClass) => Promise<string | null>;

/** true if the element has the locator parameter. */
hasLocatorParameter: (this: SelectorClass, parameter: string) => Promise<boolean>;

/** true if the element has the test id. */
hasTestId: (this: SelectorClass) => Promise<boolean>;
}>;

/**
Expand Down
7 changes: 6 additions & 1 deletion src/utils/events/registerEndE2edRunEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {getReports} from './getReports';
import {runAfterPackFunctions} from './runAfterPackFunctions';
import {writeReports} from './writeReports';

import type {LiteReport, ReportData} from '../../types/internal';
import type {LiteReport, ReportData, UtcTimeInMs} from '../../types/internal';

let isEndAlreadyCalled = false;

Expand Down Expand Up @@ -56,6 +56,11 @@ export const registerEndE2edRunEvent = async (): Promise<void> => {
setReadonlyProperty(reportData, 'customReportProperties', customReportProperties);
}

const endTimeInMs = Date.now() as UtcTimeInMs;

setReadonlyProperty(liteReport, 'endTimeInMs', endTimeInMs);
setReadonlyProperty(reportData, 'endTimeInMs', endTimeInMs);

await writeReports({liteReport, reportData});
} catch (error) {
generalLog(
Expand Down
Loading

0 comments on commit dcdd4b9

Please sign in to comment.