Socket
Socket
Sign inDemoInstall

@atomic-testing/core

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atomic-testing/core - npm Package Compare versions

Comparing version 0.28.0 to 0.29.0

dist/locators/LinkedCssLocator.d.ts

4

dist/errors/ItemNotFoundError.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ItemNotFoundError = exports.ItemNotFoundErrorId = void 0;
const locatorUtil_1 = require("../utils/locatorUtil");
const ErrorBase_1 = require("./ErrorBase");
exports.ItemNotFoundErrorId = 'ItemNotFoundError';
function getErrorMessage(locator) {
const cssLocator = (0, locatorUtil_1.toCssSelector)(locator);
return `Item not found. Locator: ${cssLocator}`;
return `Item not found. Locator: ${locator}`;
}

@@ -11,0 +9,0 @@ class ItemNotFoundError extends ErrorBase_1.ErrorBase {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WaitForFailureError = exports.WaitForFailureErrorId = void 0;
const locatorUtil_1 = require("../utils/locatorUtil");
const ErrorBase_1 = require("./ErrorBase");
exports.WaitForFailureErrorId = 'WaitForFailureError';
function getErrorMessage(locator, option) {
const cssLocator = (0, locatorUtil_1.toCssSelector)(locator);
const cssLocator = `${locator}`;
return `Wait for element to be ${option.condition} failed after ${option.timeoutMs}ms: ${cssLocator}`;

@@ -10,0 +9,0 @@ }

import { Optional } from '../dataTypes';
import { CssLocatorSource } from './CssLocatorSource';
import { LocatorComplexity } from './LocatorComplexity';
import { LocatorRelativePosition } from './LocatorRelativePosition';
import { LocatorType } from './LocatorType';
import { PartLocator } from './PartLocator';
export interface CssLocatorInitializer {
type: LocatorType;
relative: LocatorRelativePosition;

@@ -19,3 +20,5 @@ source: CssLocatorSource;

get source(): Optional<CssLocatorSource>;
chain(...locatorsToAppend: PartLocator[]): PartLocator;
get complexity(): LocatorComplexity;
clone(override?: Partial<CssLocatorInitializer>): CssLocator;
}

@@ -11,3 +11,2 @@ "use strict";

if (initializeValue) {
this._type = initializeValue.type || this.type;
this._relativePosition = initializeValue.relative || this.relative;

@@ -26,2 +25,12 @@ this._source = initializeValue.source || this.source;

}
chain(...locatorsToAppend) {
const baseLocator = [this];
const toAppend = locatorsToAppend.reduce((acc, locator) => {
return acc.concat(locator);
}, []);
return baseLocator.concat(toAppend);
}
get complexity() {
return 'primitive';
}
clone(override) {

@@ -28,0 +37,0 @@ var _a, _b;

@@ -5,3 +5,3 @@ export { CssLocator } from './CssLocator';

export type { LocatorType } from './LocatorType';
export type { PartLocator } from './PartLocator';
export type { CssLocatorChain, LocatorChain, PartLocator } from './PartLocator';
export { byAttribute } from './byAttribute';

@@ -8,0 +8,0 @@ export { byChecked } from './byChecked';

import { CssLocator } from './CssLocator';
export type PartLocator = CssLocator | readonly CssLocator[];
export type CssLocatorChain = CssLocator[];
export type PartLocator = CssLocator | CssLocatorChain;
/**
* @deprecated LocatorChain is deprecated, please use PartLocator instead
*/
export type LocatorChain = PartLocator;

@@ -6,1 +6,2 @@ export interface DifferenceResult<T> {

export declare function getDifference<T>(from: Iterable<T>, to: Iterable<T>): DifferenceResult<T>;
export declare function toArray<T>(item: T | readonly T[]): T[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDifference = void 0;
exports.toArray = exports.getDifference = void 0;
function getDifference(from, to) {

@@ -27,2 +27,6 @@ const fromSet = new Set(from);

}
function toArray(item) {
return Array.isArray(item) ? item : [item];
}
exports.toArray = toArray;
//# sourceMappingURL=collectionUtil.js.map

@@ -0,9 +1,24 @@

import { Interactor } from '../interactor';
import { CssLocator } from '../locators/CssLocator';
import { LocatorRelativePosition } from '../locators/LocatorRelativePosition';
import { PartLocator } from '../locators/PartLocator';
import { CssLocatorChain, PartLocator } from '../locators/PartLocator';
export declare function isChain(locator: PartLocator): locator is CssLocatorChain;
export declare function toChain(locator: PartLocator): CssLocatorChain;
export declare function append(locatorBase: PartLocator, ...locatorsToAppend: PartLocator[]): PartLocator;
export declare function findRootLocatorIndex(locator: PartLocator): number;
export declare function getEffectiveLocator(locator: PartLocator): CssLocator[];
export declare function toCssSelector(locator: PartLocator): string;
export declare function toCssSelector(locator: PartLocator, interactor: Interactor): Promise<string>;
export declare function getLocatorStatement(locator: CssLocator): string;
export declare function overrideLocatorRelativePosition(locator: PartLocator, relative: LocatorRelativePosition): PartLocator;
export interface OverrideLocatorRelativePositionOption {
shouldOverride: (locator: CssLocator, index: number) => boolean;
}
export declare const defaultOverrideLocatorRelativePositionOption: Readonly<OverrideLocatorRelativePositionOption>;
/**
* Override the supplied locator's relative position, if the supplied locator is an array of locators,
* only the first one is overridden
* @param locator
* @param relative
* @param option
* @returns
*/
export declare function overrideLocatorRelativePosition(locator: PartLocator, relative: LocatorRelativePosition, option?: Partial<Readonly<OverrideLocatorRelativePositionOption>>): PartLocator;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.overrideLocatorRelativePosition = exports.getLocatorStatement = exports.toCssSelector = exports.getEffectiveLocator = exports.findRootLocatorIndex = exports.append = void 0;
exports.overrideLocatorRelativePosition = exports.defaultOverrideLocatorRelativePositionOption = exports.getLocatorStatement = exports.toCssSelector = exports.getEffectiveLocator = exports.findRootLocatorIndex = exports.append = exports.toChain = exports.isChain = void 0;
const LocatorRelativePosition_1 = require("../locators/LocatorRelativePosition");
function isChain(locator) {
return Array.isArray(locator);
}
exports.isChain = isChain;
function toChain(locator) {
return isChain(locator) ? locator : [locator];
}
exports.toChain = toChain;
function append(locatorBase, ...locatorsToAppend) {
const baseLocator = Array.isArray(locatorBase) ? locatorBase : [locatorBase];
const baseLocator = toChain(locatorBase);
const toAppend = locatorsToAppend.reduce((acc, locator) => {

@@ -14,3 +22,3 @@ return acc.concat(locator);

function findRootLocatorIndex(locator) {
const list = Array.isArray(locator) ? locator : [locator];
const list = toChain(locator);
const length = list.length;

@@ -27,3 +35,3 @@ for (let i = length - 1; i >= 0; i--) {

function getEffectiveLocator(locator) {
const list = Array.isArray(locator) ? locator : [locator];
const list = toChain(locator);
const rootLocatorIndex = findRootLocatorIndex(list);

@@ -33,16 +41,10 @@ return rootLocatorIndex === -1 ? list : list.slice(rootLocatorIndex);

exports.getEffectiveLocator = getEffectiveLocator;
function toCssSelector(locator) {
function toCssSelector(locator, interactor) {
const effectiveLocator = getEffectiveLocator(locator);
const statements = effectiveLocator.map((loc) => {
let separator = ' ';
const statement = getLocatorStatement(loc);
if (typeof loc !== 'string') {
const l = loc;
if (l.relative === LocatorRelativePosition_1.LocatorRelativePosition.Same) {
separator = '';
}
}
const separator = loc.relative === LocatorRelativePosition_1.LocatorRelativePosition.Same ? '' : ' ';
return separator + statement;
});
return statements.join('').trim();
return Promise.resolve(statements.join('').trim());
}

@@ -54,7 +56,23 @@ exports.toCssSelector = toCssSelector;

exports.getLocatorStatement = getLocatorStatement;
function overrideLocatorRelativePosition(locator, relative) {
exports.defaultOverrideLocatorRelativePositionOption = Object.freeze({
shouldOverride: (_, index) => index === 0,
});
/**
* Override the supplied locator's relative position, if the supplied locator is an array of locators,
* only the first one is overridden
* @param locator
* @param relative
* @param option
* @returns
*/
function overrideLocatorRelativePosition(locator, relative, option = exports.defaultOverrideLocatorRelativePositionOption) {
if (Array.isArray(locator)) {
return locator.map((loc) => loc.clone({
relative,
}));
const actualOption = Object.assign(Object.assign({}, exports.defaultOverrideLocatorRelativePositionOption), option);
return locator.map((loc, index) => {
return actualOption.shouldOverride(loc, index)
? loc.clone({
relative,
})
: loc;
});
}

@@ -61,0 +79,0 @@ return locator.clone({

{
"name": "@atomic-testing/core",
"version": "0.28.0",
"version": "0.29.0",
"description": "Core library for atomic-testing",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

import { ComponentDriver } from '../drivers/ComponentDriver';
import { PartLocator } from '../locators';
import { toCssSelector } from '../utils/locatorUtil';
import { ErrorBase } from './ErrorBase';

@@ -9,4 +8,3 @@

function getErrorMessage(locator: PartLocator): string {
const cssLocator = toCssSelector(locator);
return `Item not found. Locator: ${cssLocator}`;
return `Item not found. Locator: ${locator}`;
}

@@ -13,0 +11,0 @@

import { ComponentDriver } from '../drivers/ComponentDriver';
import { WaitForOption } from '../drivers/WaitForOption';
import { PartLocator } from '../locators';
import { toCssSelector } from '../utils/locatorUtil';
import { ErrorBase } from './ErrorBase';

@@ -10,3 +9,3 @@

function getErrorMessage(locator: PartLocator, option: WaitForOption): string {
const cssLocator = toCssSelector(locator);
const cssLocator = `${locator}`;
return `Wait for element to be ${option.condition} failed after ${option.timeoutMs}ms: ${cssLocator}`;

@@ -13,0 +12,0 @@ }

import { Optional } from '../dataTypes';
import { CssLocatorSource } from './CssLocatorSource';
import { LocatorComplexity } from './LocatorComplexity';
import { LocatorRelativePosition } from './LocatorRelativePosition';
import { LocatorType } from './LocatorType';
import { PartLocator } from './PartLocator';
export interface CssLocatorInitializer {
type: LocatorType;
relative: LocatorRelativePosition;

@@ -19,3 +20,2 @@ source: CssLocatorSource;

if (initializeValue) {
this._type = initializeValue.type || this.type;
this._relativePosition = initializeValue.relative || this.relative;

@@ -38,2 +38,15 @@ this._source = initializeValue.source || this.source;

chain(...locatorsToAppend: PartLocator[]): PartLocator {
const baseLocator: CssLocator[] = [this];
const toAppend: CssLocator[] = locatorsToAppend.reduce((acc: CssLocator[], locator) => {
return acc.concat(locator);
}, []);
return baseLocator.concat(toAppend);
}
public get complexity(): LocatorComplexity {
return 'primitive';
}
clone(override?: Partial<CssLocatorInitializer>): CssLocator {

@@ -40,0 +53,0 @@ return new CssLocator(this.selector, {

@@ -5,3 +5,3 @@ export { CssLocator } from './CssLocator';

export type { LocatorType } from './LocatorType';
export type { PartLocator } from './PartLocator';
export type { CssLocatorChain, LocatorChain, PartLocator } from './PartLocator';
export { byAttribute } from './byAttribute';

@@ -8,0 +8,0 @@ export { byChecked } from './byChecked';

import { CssLocator } from './CssLocator';
export type PartLocator = CssLocator | readonly CssLocator[];
export type CssLocatorChain = CssLocator[];
export type PartLocator = CssLocator | CssLocatorChain;
/**
* @deprecated LocatorChain is deprecated, please use PartLocator instead
*/
export type LocatorChain = PartLocator;

@@ -30,1 +30,5 @@ export interface DifferenceResult<T> {

}
export function toArray<T>(item: T | readonly T[]): T[] {
return Array.isArray(item) ? item : ([item] as T[]);
}

@@ -0,8 +1,17 @@

import { Interactor } from '../interactor';
import { CssLocator } from '../locators/CssLocator';
import { LocatorRelativePosition } from '../locators/LocatorRelativePosition';
import { PartLocator } from '../locators/PartLocator';
import { CssLocatorChain, PartLocator } from '../locators/PartLocator';
export function isChain(locator: PartLocator): locator is CssLocatorChain {
return Array.isArray(locator);
}
export function toChain(locator: PartLocator): CssLocatorChain {
return isChain(locator) ? locator : [locator];
}
export function append(locatorBase: PartLocator, ...locatorsToAppend: PartLocator[]): PartLocator {
const baseLocator: CssLocator[] = Array.isArray(locatorBase) ? locatorBase : [locatorBase];
const toAppend: CssLocator[] = locatorsToAppend.reduce((acc: CssLocator[], locator) => {
const baseLocator: CssLocatorChain = toChain(locatorBase);
const toAppend: CssLocatorChain = locatorsToAppend.reduce((acc: CssLocatorChain, locator) => {
return acc.concat(locator);

@@ -15,3 +24,3 @@ }, []);

export function findRootLocatorIndex(locator: PartLocator): number {
const list = Array.isArray(locator) ? locator : [locator];
const list = toChain(locator);
const length = list.length;

@@ -29,3 +38,3 @@ for (let i = length - 1; i >= 0; i--) {

export function getEffectiveLocator(locator: PartLocator): CssLocator[] {
const list = Array.isArray(locator) ? locator : [locator];
const list = toChain(locator);
const rootLocatorIndex = findRootLocatorIndex(list);

@@ -35,18 +44,11 @@ return rootLocatorIndex === -1 ? list : list.slice(rootLocatorIndex);

export function toCssSelector(locator: PartLocator): string {
export function toCssSelector(locator: PartLocator, interactor: Interactor): Promise<string> {
const effectiveLocator = getEffectiveLocator(locator);
const statements = effectiveLocator.map((loc) => {
let separator = ' ';
const statements: string[] = effectiveLocator.map((loc) => {
const statement = getLocatorStatement(loc);
if (typeof loc !== 'string') {
const l = loc as CssLocator;
if (l.relative === LocatorRelativePosition.Same) {
separator = '';
}
}
const separator = loc.relative === LocatorRelativePosition.Same ? '' : ' ';
return separator + statement;
});
return statements.join('').trim();
return Promise.resolve(statements.join('').trim());
}

@@ -58,9 +60,36 @@

export function overrideLocatorRelativePosition(locator: PartLocator, relative: LocatorRelativePosition): PartLocator {
export interface OverrideLocatorRelativePositionOption {
shouldOverride: (locator: CssLocator, index: number) => boolean;
}
export const defaultOverrideLocatorRelativePositionOption: Readonly<OverrideLocatorRelativePositionOption> =
Object.freeze({
shouldOverride: (_: CssLocator, index: number) => index === 0,
});
/**
* Override the supplied locator's relative position, if the supplied locator is an array of locators,
* only the first one is overridden
* @param locator
* @param relative
* @param option
* @returns
*/
export function overrideLocatorRelativePosition(
locator: PartLocator,
relative: LocatorRelativePosition,
option: Partial<Readonly<OverrideLocatorRelativePositionOption>> = defaultOverrideLocatorRelativePositionOption,
): PartLocator {
if (Array.isArray(locator)) {
return (locator as readonly CssLocator[]).map((loc) =>
loc.clone({
relative,
}),
);
const actualOption: Readonly<OverrideLocatorRelativePositionOption> = {
...defaultOverrideLocatorRelativePositionOption,
...option,
};
return (locator as readonly CssLocator[]).map((loc, index) => {
return actualOption.shouldOverride(loc, index)
? loc.clone({
relative,
})
: loc;
});
}

@@ -67,0 +96,0 @@ return (locator as CssLocator).clone({

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc