expect-webdriverio 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +29 -9
  2. package/jasmine.d.ts +0 -1
  3. package/jest.d.ts +1 -1
  4. package/lib/constants.js +4 -0
  5. package/lib/index.js +14 -6
  6. package/lib/jasmineUtils.js +7 -17
  7. package/lib/matchers/browser/toHaveTitle.js +12 -23
  8. package/lib/matchers/browser/toHaveTitleContaining.js +3 -11
  9. package/lib/matchers/browser/toHaveUrl.js +12 -23
  10. package/lib/matchers/browser/toHaveUrlContaining.js +3 -11
  11. package/lib/matchers/element/toBeClickable.js +10 -21
  12. package/lib/matchers/element/toBeDisabled.js +3 -14
  13. package/lib/matchers/element/toBeDisplayed.js +10 -21
  14. package/lib/matchers/element/toBeDisplayedInViewport.js +10 -21
  15. package/lib/matchers/element/toBeEnabled.js +3 -14
  16. package/lib/matchers/element/toBeExisting.js +14 -27
  17. package/lib/matchers/element/toBeFocused.js +3 -14
  18. package/lib/matchers/element/toBeSelected.js +6 -19
  19. package/lib/matchers/element/toHaveAttribute.js +35 -46
  20. package/lib/matchers/element/toHaveAttributeContaining.js +4 -12
  21. package/lib/matchers/element/toHaveChildren.js +27 -39
  22. package/lib/matchers/element/toHaveClass.js +47 -0
  23. package/lib/matchers/element/toHaveClassContaining.js +10 -0
  24. package/lib/matchers/element/toHaveElementProperty.js +25 -36
  25. package/lib/matchers/element/toHaveHref.js +4 -13
  26. package/lib/matchers/element/toHaveHrefContaining.js +4 -12
  27. package/lib/matchers/element/toHaveId.js +3 -12
  28. package/lib/matchers/element/toHaveStyle.js +17 -28
  29. package/lib/matchers/element/toHaveText.js +18 -29
  30. package/lib/matchers/element/toHaveTextContaining.js +3 -11
  31. package/lib/matchers/element/toHaveValue.js +3 -12
  32. package/lib/matchers/element/toHaveValueContaining.js +3 -11
  33. package/lib/matchers/elements/toBeElementsArrayOfSize.js +16 -26
  34. package/lib/matchers/mock/toBeRequested.js +3 -11
  35. package/lib/matchers/mock/toBeRequestedTimes.js +17 -32
  36. package/lib/matchers/mock/toBeRequestedWith.js +30 -39
  37. package/lib/matchers.js +62 -35
  38. package/lib/types.js +1 -0
  39. package/lib/util/elementsUtil.js +2 -7
  40. package/lib/util/executeCommand.js +3 -7
  41. package/lib/util/formatMessage.js +17 -26
  42. package/lib/util/refetchElements.js +2 -8
  43. package/lib/utils.js +41 -49
  44. package/package.json +49 -44
  45. package/types/expect-webdriverio.d.ts +23 -22
  46. package/types/jest-global.d.ts +1 -1
  47. package/types/standalone.d.ts +2 -2
  48. package/lib/addMatchers.js +0 -48
  49. package/lib/matchers/element/toHaveElementClass.js +0 -60
  50. package/lib/matchers/element/toHaveElementClassContaining.js +0 -20
  51. package/lib/matchers/mock/toBeRequestedWithResponse.js +0 -13
  52. package/lib/options.js +0 -33
  53. package/lib/util/expectAdapter.js +0 -41
  54. package/types/standalone-global.d.ts +0 -9
@@ -1,39 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeRequestedWith = exports.toBeRequestedWithFn = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- const jasmineUtils_1 = require("../../jasmineUtils");
1
+ import { waitUntil, enhanceError } from '../../utils.js';
2
+ import { equals } from '../../jasmineUtils.js';
7
3
  const STR_LIMIT = 80;
8
4
  const KEY_LIMIT = 12;
9
- function toBeRequestedWithFn(received, requestedWith = {}, options = {}) {
5
+ export async function toBeRequestedWith(received, requestedWith = {}, options = {}) {
10
6
  const isNot = this.isNot || false;
11
7
  const { expectation = 'called with', verb = 'be' } = this;
12
- return browser.call(async () => {
13
- let actual;
14
- const pass = await utils_1.waitUntil(async () => {
15
- for (const call of received.calls) {
16
- actual = call;
17
- if (methodMatcher(call.method, requestedWith.method) &&
18
- statusCodeMatcher(call.statusCode, requestedWith.statusCode) &&
19
- urlMatcher(call.url, requestedWith.url) &&
20
- headersMatcher(call.headers, requestedWith.requestHeaders) &&
21
- headersMatcher(call.responseHeaders, requestedWith.responseHeaders) &&
22
- bodyMatcher(call.postData, requestedWith.postData) &&
23
- bodyMatcher(call.body, requestedWith.response)) {
24
- return true;
25
- }
8
+ let actual;
9
+ const pass = await waitUntil(async () => {
10
+ for (const call of received.calls) {
11
+ actual = call;
12
+ if (methodMatcher(call.method, requestedWith.method) &&
13
+ statusCodeMatcher(call.statusCode, requestedWith.statusCode) &&
14
+ urlMatcher(call.url, requestedWith.url) &&
15
+ headersMatcher(call.headers, requestedWith.requestHeaders) &&
16
+ headersMatcher(call.responseHeaders, requestedWith.responseHeaders) &&
17
+ bodyMatcher(call.postData, requestedWith.postData) &&
18
+ bodyMatcher(call.body, requestedWith.response)) {
19
+ return true;
26
20
  }
27
- return false;
28
- }, isNot, { ...options, wait: isNot ? 0 : options.wait });
29
- const message = utils_1.enhanceError('mock', minifyRequestedWith(requestedWith), minifyRequestMock(actual, requestedWith) || 'was not called', this, verb, expectation, '', options);
30
- return {
31
- pass,
32
- message: () => message,
33
- };
34
- });
21
+ }
22
+ return false;
23
+ }, isNot, { ...options, wait: isNot ? 0 : options.wait });
24
+ const message = enhanceError('mock', minifyRequestedWith(requestedWith), minifyRequestMock(actual, requestedWith) || 'was not called', this, verb, expectation, '', options);
25
+ return {
26
+ pass,
27
+ message: () => message,
28
+ };
35
29
  }
36
- exports.toBeRequestedWithFn = toBeRequestedWithFn;
37
30
  const methodMatcher = (method, expected) => {
38
31
  if (typeof expected === 'undefined') {
39
32
  return true;
@@ -66,7 +59,7 @@ const urlMatcher = (url, expected) => {
66
59
  if (typeof expected === 'function') {
67
60
  return expected(url);
68
61
  }
69
- return jasmineUtils_1.equals(url, expected);
62
+ return equals(url, expected);
70
63
  };
71
64
  const headersMatcher = (headers, expected) => {
72
65
  if (typeof expected === 'undefined') {
@@ -75,7 +68,7 @@ const headersMatcher = (headers, expected) => {
75
68
  if (typeof expected === 'function') {
76
69
  return expected(headers);
77
70
  }
78
- return jasmineUtils_1.equals(headers, expected);
71
+ return equals(headers, expected);
79
72
  };
80
73
  const bodyMatcher = (body, expected) => {
81
74
  if (typeof expected === 'undefined') {
@@ -97,7 +90,7 @@ const bodyMatcher = (body, expected) => {
97
90
  return false;
98
91
  }
99
92
  }
100
- return jasmineUtils_1.equals(parsedBody, expected);
93
+ return equals(parsedBody, expected);
101
94
  };
102
95
  const isExpectedJsonLike = (expected) => {
103
96
  if (typeof expected === 'undefined') {
@@ -112,14 +105,13 @@ const isExpectedJsonLike = (expected) => {
112
105
  actualSample instanceof RegExp === false));
113
106
  };
114
107
  const isMatcher = (filter) => {
115
- var _a;
116
- return typeof ((_a = filter.__proto__) === null || _a === void 0 ? void 0 : _a.asymmetricMatch) === 'function';
108
+ return typeof filter.__proto__?.asymmetricMatch === 'function';
117
109
  };
118
110
  const tryParseBody = (jsonString, fallback = null) => {
119
111
  try {
120
112
  return typeof jsonString === 'undefined' ? fallback : JSON.parse(jsonString);
121
113
  }
122
- catch (_a) {
114
+ catch {
123
115
  return fallback;
124
116
  }
125
117
  };
@@ -212,7 +204,6 @@ const deleteUndefinedValues = (obj, baseline = obj) => {
212
204
  }
213
205
  });
214
206
  };
215
- function toBeRequestedWith(...args) {
216
- return expectAdapter_1.runExpect.call(this, toBeRequestedWithFn, args);
207
+ export function toBeRequestedWithResponse(...args) {
208
+ return toBeRequestedWith.call(this, ...args);
217
209
  }
218
- exports.toBeRequestedWith = toBeRequestedWith;
package/lib/matchers.js CHANGED
@@ -1,41 +1,68 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ import * as toHaveTitle from './matchers/browser/toHaveTitle.js';
2
+ import * as toHaveTitleContaining from './matchers/browser/toHaveTitleContaining.js';
3
+ import * as toHaveUrl from './matchers/browser/toHaveUrl.js';
4
+ import * as toHaveUrlContaining from './matchers/browser/toHaveUrlContaining.js';
5
+ import * as toBeElementsArrayOfSize from './matchers/elements/toBeElementsArrayOfSize.js';
6
+ import * as toBeClickable from './matchers/element/toBeClickable.js';
7
+ import * as toBeDisabled from './matchers/element/toBeDisabled.js';
8
+ import * as toBeDisplayed from './matchers/element/toBeDisplayed.js';
9
+ import * as toBeDisplayedInViewport from './matchers/element/toBeDisplayedInViewport.js';
10
+ import * as toBeEnabled from './matchers/element/toBeEnabled.js';
11
+ import * as toBeExisting from './matchers/element/toBeExisting.js';
12
+ import * as toBeFocused from './matchers/element/toBeFocused.js';
13
+ import * as toBeSelected from './matchers/element/toBeSelected.js';
14
+ import * as toHaveAttribute from './matchers/element/toHaveAttribute.js';
15
+ import * as toHaveAttributeContaining from './matchers/element/toHaveAttributeContaining.js';
16
+ import * as toHaveChildren from './matchers/element/toHaveChildren.js';
17
+ import * as toHaveClass from './matchers/element/toHaveClass.js';
18
+ import * as toHaveClassContaining from './matchers/element/toHaveClassContaining.js';
19
+ import * as toHaveHref from './matchers/element/toHaveHref.js';
20
+ import * as toHaveHrefContaining from './matchers/element/toHaveHrefContaining.js';
21
+ import * as toHaveId from './matchers/element/toHaveId.js';
22
+ import * as toHaveElementProperty from './matchers/element/toHaveElementProperty.js';
23
+ import * as toHaveText from './matchers/element/toHaveText.js';
24
+ import * as toHaveTextContaining from './matchers/element/toHaveTextContaining.js';
25
+ import * as toHaveValue from './matchers/element/toHaveValue.js';
26
+ import * as toHaveValueContaining from './matchers/element/toHaveValueContaining.js';
27
+ import * as toHaveStyle from './matchers/element/toHaveStyle.js';
28
+ import * as toBeRequested from './matchers/mock/toBeRequested.js';
29
+ import * as toBeRequestedTimes from './matchers/mock/toBeRequestedTimes.js';
30
+ import * as toBeRequestedWith from './matchers/mock/toBeRequestedWith.js';
3
31
  const matchers = {
4
- ...require('./matchers/browser/toHaveTitle'),
5
- ...require('./matchers/browser/toHaveTitleContaining'),
6
- ...require('./matchers/browser/toHaveUrl'),
7
- ...require('./matchers/browser/toHaveUrlContaining'),
8
- ...require('./matchers/elements/toBeElementsArrayOfSize'),
9
- ...require('./matchers/element/toBeClickable'),
10
- ...require('./matchers/element/toBeDisabled'),
11
- ...require('./matchers/element/toBeDisplayed'),
12
- ...require('./matchers/element/toBeDisplayedInViewport'),
13
- ...require('./matchers/element/toBeEnabled'),
14
- ...require('./matchers/element/toBeExisting'),
15
- ...require('./matchers/element/toBeFocused'),
16
- ...require('./matchers/element/toBeSelected'),
17
- ...require('./matchers/element/toHaveAttribute'),
18
- ...require('./matchers/element/toHaveAttributeContaining'),
19
- ...require('./matchers/element/toHaveChildren'),
20
- ...require('./matchers/element/toHaveElementClass'),
21
- ...require('./matchers/element/toHaveElementClassContaining'),
22
- ...require('./matchers/element/toHaveHref'),
23
- ...require('./matchers/element/toHaveHrefContaining'),
24
- ...require('./matchers/element/toHaveId'),
25
- ...require('./matchers/element/toHaveElementProperty'),
26
- ...require('./matchers/element/toHaveText'),
27
- ...require('./matchers/element/toHaveTextContaining'),
28
- ...require('./matchers/element/toHaveValue'),
29
- ...require('./matchers/element/toHaveValueContaining'),
30
- ...require('./matchers/element/toHaveStyle'),
31
- ...require('./matchers/mock/toBeRequested'),
32
- ...require('./matchers/mock/toBeRequestedTimes'),
33
- ...require('./matchers/mock/toBeRequestedWith'),
34
- ...require('./matchers/mock/toBeRequestedWithResponse'),
32
+ ...toHaveTitle,
33
+ ...toHaveTitleContaining,
34
+ ...toHaveUrl,
35
+ ...toHaveUrlContaining,
36
+ ...toBeElementsArrayOfSize,
37
+ ...toBeClickable,
38
+ ...toBeDisabled,
39
+ ...toBeDisplayed,
40
+ ...toBeDisplayedInViewport,
41
+ ...toBeEnabled,
42
+ ...toBeExisting,
43
+ ...toBeFocused,
44
+ ...toBeSelected,
45
+ ...toHaveAttribute,
46
+ ...toHaveAttributeContaining,
47
+ ...toHaveChildren,
48
+ ...toHaveClass,
49
+ ...toHaveClassContaining,
50
+ ...toHaveHref,
51
+ ...toHaveHrefContaining,
52
+ ...toHaveId,
53
+ ...toHaveElementProperty,
54
+ ...toHaveText,
55
+ ...toHaveTextContaining,
56
+ ...toHaveValue,
57
+ ...toHaveValueContaining,
58
+ ...toHaveStyle,
59
+ ...toBeRequested,
60
+ ...toBeRequestedTimes,
61
+ ...toBeRequestedWith,
35
62
  };
36
- Object.keys(matchers).forEach(key => {
63
+ Object.keys(matchers).forEach((key) => {
37
64
  if (key.endsWith('Fn')) {
38
65
  delete matchers[key];
39
66
  }
40
67
  });
41
- exports.default = matchers;
68
+ export default matchers;
package/lib/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateElementsArray = exports.wrapExpectedWithArray = void 0;
4
- const wrapExpectedWithArray = (el, actual, expected) => {
1
+ export const wrapExpectedWithArray = (el, actual, expected) => {
5
2
  if (Array.isArray(el) && el.length > 1 && Array.isArray(actual)) {
6
3
  expected = [expected];
7
4
  }
8
5
  return expected;
9
6
  };
10
- exports.wrapExpectedWithArray = wrapExpectedWithArray;
11
- const updateElementsArray = (success, received, refetched, full = false) => {
7
+ export const updateElementsArray = (success, received, refetched, full = false) => {
12
8
  if (!success) {
13
9
  return;
14
10
  }
@@ -25,4 +21,3 @@ const updateElementsArray = (success, received, refetched, full = false) => {
25
21
  }
26
22
  }
27
23
  };
28
- exports.updateElementsArray = updateElementsArray;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeCommand = void 0;
4
- const refetchElements_1 = require("./refetchElements");
5
- async function executeCommand(el, condition, options = {}, params = [], fullRefetch = false) {
1
+ import { refetchElements } from './refetchElements.js';
2
+ export async function executeCommand(el, condition, options = {}, params = [], fullRefetch = false) {
6
3
  const { isNot = false } = this;
7
4
  let elements;
8
5
  if (Array.isArray(el)) {
9
- elements = await refetchElements_1.refetchElements(el, options.wait, fullRefetch);
6
+ elements = await refetchElements(el, options.wait, fullRefetch);
10
7
  }
11
8
  else {
12
9
  elements = [el];
@@ -28,4 +25,3 @@ async function executeCommand(el, condition, options = {}, params = [], fullRefe
28
25
  values: values.length > 1 ? values : values[0]
29
26
  };
30
27
  }
31
- exports.executeCommand = executeCommand;
@@ -1,46 +1,40 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.numberError = exports.enhanceErrorBe = exports.enhanceError = exports.not = exports.getSelectors = exports.getSelector = void 0;
4
- const jest_matcher_utils_1 = require("jest-matcher-utils");
5
- const jasmineUtils_1 = require("../jasmineUtils");
1
+ import { printExpected, printReceived, printDiffOrStringify } from 'jest-matcher-utils';
2
+ import { equals } from '../jasmineUtils.js';
6
3
  const EXPECTED_LABEL = 'Expected';
7
4
  const RECEIVED_LABEL = 'Received';
8
5
  const NOT_SUFFIX = ' [not]';
9
6
  const NOT_EXPECTED_LABEL = EXPECTED_LABEL + NOT_SUFFIX;
10
- const getSelector = (el) => {
7
+ export const getSelector = (el) => {
11
8
  let result = typeof el.selector === 'string' ? el.selector : '<fn>';
12
9
  if (Array.isArray(el) && el.props.length > 0) {
13
10
  result += ', <props>';
14
11
  }
15
12
  return result;
16
13
  };
17
- exports.getSelector = getSelector;
18
- const getSelectors = (el) => {
14
+ export const getSelectors = (el) => {
19
15
  const selectors = [];
20
16
  let parent;
21
17
  if (Array.isArray(el)) {
22
- selectors.push(`${el.foundWith}(\`${exports.getSelector(el)}\`)`);
18
+ selectors.push(`${el.foundWith}(\`${getSelector(el)}\`)`);
23
19
  parent = el.parent;
24
20
  }
25
21
  else {
26
22
  parent = el;
27
23
  }
28
24
  while (parent && 'selector' in parent) {
29
- const selector = exports.getSelector(parent);
25
+ const selector = getSelector(parent);
30
26
  const index = parent.index ? `[${parent.index}]` : '';
31
27
  selectors.push(`${parent.index ? '$' : ''}$(\`${selector}\`)${index}`);
32
28
  parent = parent.parent;
33
29
  }
34
30
  return selectors.reverse().join('.');
35
31
  };
36
- exports.getSelectors = getSelectors;
37
- const not = (isNot) => {
32
+ export const not = (isNot) => {
38
33
  return `${isNot ? 'not ' : ''}`;
39
34
  };
40
- exports.not = not;
41
- const enhanceError = (subject, expected, actual, context, verb, expectation, arg2 = '', { message = '', containing = false }) => {
35
+ export const enhanceError = (subject, expected, actual, context, verb, expectation, arg2 = '', { message = '', containing = false }) => {
42
36
  const { isNot = false } = context;
43
- subject = typeof subject === 'string' ? subject : exports.getSelectors(subject);
37
+ subject = typeof subject === 'string' ? subject : getSelectors(subject);
44
38
  let contain = '';
45
39
  if (containing) {
46
40
  contain = ' containing';
@@ -49,12 +43,12 @@ const enhanceError = (subject, expected, actual, context, verb, expectation, arg
49
43
  verb += ' ';
50
44
  }
51
45
  let diffString;
52
- if (isNot && jasmineUtils_1.equals(actual, expected)) {
53
- diffString = `${EXPECTED_LABEL}: ${jest_matcher_utils_1.printExpected(expected)}\n` +
54
- `${RECEIVED_LABEL}: ${jest_matcher_utils_1.printReceived(actual)}`;
46
+ if (isNot && equals(actual, expected)) {
47
+ diffString = `${EXPECTED_LABEL}: ${printExpected(expected)}\n` +
48
+ `${RECEIVED_LABEL}: ${printReceived(actual)}`;
55
49
  }
56
50
  else {
57
- diffString = jest_matcher_utils_1.printDiffOrStringify(expected, actual, EXPECTED_LABEL, RECEIVED_LABEL, true);
51
+ diffString = printDiffOrStringify(expected, actual, EXPECTED_LABEL, RECEIVED_LABEL, true);
58
52
  }
59
53
  if (isNot) {
60
54
  diffString = diffString
@@ -67,15 +61,13 @@ const enhanceError = (subject, expected, actual, context, verb, expectation, arg
67
61
  if (arg2) {
68
62
  arg2 = ` ${arg2}`;
69
63
  }
70
- const msg = `${message}Expect ${subject} ${exports.not(isNot)}to ${verb}${expectation}${arg2}${contain}\n\n${diffString}`;
64
+ const msg = `${message}Expect ${subject} ${not(isNot)}to ${verb}${expectation}${arg2}${contain}\n\n${diffString}`;
71
65
  return msg;
72
66
  };
73
- exports.enhanceError = enhanceError;
74
- const enhanceErrorBe = (subject, pass, context, verb, expectation, options) => {
75
- return exports.enhanceError(subject, exports.not(context.isNot) + expectation, exports.not(!pass) + expectation, context, verb, expectation, '', options);
67
+ export const enhanceErrorBe = (subject, pass, context, verb, expectation, options) => {
68
+ return enhanceError(subject, not(context.isNot) + expectation, not(!pass) + expectation, context, verb, expectation, '', options);
76
69
  };
77
- exports.enhanceErrorBe = enhanceErrorBe;
78
- const numberError = (options = {}) => {
70
+ export const numberError = (options = {}) => {
79
71
  if (options.eq) {
80
72
  return options.eq;
81
73
  }
@@ -90,4 +82,3 @@ const numberError = (options = {}) => {
90
82
  }
91
83
  return "no params";
92
84
  };
93
- exports.numberError = numberError;
@@ -1,10 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.refetchElements = void 0;
4
- const options_1 = require("../options");
5
- const config = options_1.getConfig();
6
- const { options: DEFAULT_OPTIONS } = config;
7
- const refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = false) => {
1
+ import { DEFAULT_OPTIONS } from '../constants.js';
2
+ export const refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = false) => {
8
3
  if (elements) {
9
4
  if (wait > 0 && (elements.length === 0 || full)) {
10
5
  elements = await elements.parent[elements.foundWith](elements.selector, ...elements.props);
@@ -12,4 +7,3 @@ const refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = fal
12
7
  }
13
8
  return elements;
14
9
  };
15
- exports.refetchElements = refetchElements;
package/lib/utils.js CHANGED
@@ -1,37 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.aliasFn = exports.compareNumbers = exports.waitUntil = exports.executeCommandBe = exports.executeCommand = exports.numberError = exports.enhanceError = exports.wrapExpectedWithArray = exports.updateElementsArray = exports.compareStyle = exports.compareTextWithArray = exports.compareText = void 0;
4
- const options_1 = require("./options");
5
- const executeCommand_1 = require("./util/executeCommand");
6
- Object.defineProperty(exports, "executeCommand", { enumerable: true, get: function () { return executeCommand_1.executeCommand; } });
7
- const elementsUtil_1 = require("./util/elementsUtil");
8
- Object.defineProperty(exports, "wrapExpectedWithArray", { enumerable: true, get: function () { return elementsUtil_1.wrapExpectedWithArray; } });
9
- Object.defineProperty(exports, "updateElementsArray", { enumerable: true, get: function () { return elementsUtil_1.updateElementsArray; } });
10
- const formatMessage_1 = require("./util/formatMessage");
11
- Object.defineProperty(exports, "enhanceError", { enumerable: true, get: function () { return formatMessage_1.enhanceError; } });
12
- Object.defineProperty(exports, "numberError", { enumerable: true, get: function () { return formatMessage_1.numberError; } });
13
- const expectAdapter_1 = require("./util/expectAdapter");
14
- const config = options_1.getConfig();
15
- const { options: DEFAULT_OPTIONS } = config;
1
+ import { executeCommand } from './util/executeCommand.js';
2
+ import { wrapExpectedWithArray, updateElementsArray } from './util/elementsUtil.js';
3
+ import { enhanceError, enhanceErrorBe, numberError } from './util/formatMessage.js';
4
+ import { DEFAULT_OPTIONS } from './constants.js';
5
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
16
6
  const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait, interval = DEFAULT_OPTIONS.interval } = {}) => {
17
7
  if (wait === 0) {
18
8
  return await condition();
19
9
  }
20
10
  try {
21
11
  let error;
22
- await browser.waitUntil(async () => {
12
+ const start = Date.now();
13
+ while (true) {
14
+ if ((Date.now() - start) > wait) {
15
+ throw new Error('timeout');
16
+ }
23
17
  error = undefined;
24
18
  try {
25
- return isNot !== await condition();
19
+ const result = isNot !== await condition();
20
+ if (result) {
21
+ break;
22
+ }
23
+ await sleep(interval);
26
24
  }
27
25
  catch (err) {
28
26
  error = err;
29
- return false;
27
+ await sleep(interval);
30
28
  }
31
- }, {
32
- timeout: wait,
33
- interval
34
- });
29
+ }
35
30
  if (error) {
36
31
  throw error;
37
32
  }
@@ -41,24 +36,22 @@ const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait
41
36
  return isNot;
42
37
  }
43
38
  };
44
- exports.waitUntil = waitUntil;
45
39
  async function executeCommandBe(received, command, options) {
46
40
  const { isNot, expectation, verb = 'be' } = this;
47
41
  received = await received;
48
42
  let el = received;
49
43
  const pass = await waitUntil(async () => {
50
- const result = await executeCommand_1.executeCommand.call(this, el, async (element) => ({ result: await command(element) }), options);
44
+ const result = await executeCommand.call(this, el, async (element) => ({ result: await command(element) }), options);
51
45
  el = result.el;
52
46
  return result.success;
53
47
  }, isNot, options);
54
- elementsUtil_1.updateElementsArray(pass, received, el);
55
- const message = formatMessage_1.enhanceErrorBe(el, pass, this, verb, expectation, options);
48
+ updateElementsArray(pass, received, el);
49
+ const message = enhanceErrorBe(el, pass, this, verb, expectation, options);
56
50
  return {
57
51
  pass,
58
52
  message: () => message
59
53
  };
60
54
  }
61
- exports.executeCommandBe = executeCommandBe;
62
55
  const compareNumbers = (actual, options = {}) => {
63
56
  if (typeof options.eq === 'number') {
64
57
  return actual === options.eq;
@@ -74,8 +67,7 @@ const compareNumbers = (actual, options = {}) => {
74
67
  }
75
68
  return false;
76
69
  };
77
- exports.compareNumbers = compareNumbers;
78
- const compareText = (actual, expected, { ignoreCase = false, trim = true, containing = false }) => {
70
+ export const compareText = (actual, expected, { ignoreCase = false, trim = true, containing = false }) => {
79
71
  if (typeof actual !== 'string') {
80
72
  return {
81
73
  value: actual,
@@ -87,7 +79,15 @@ const compareText = (actual, expected, { ignoreCase = false, trim = true, contai
87
79
  }
88
80
  if (ignoreCase) {
89
81
  actual = actual.toLowerCase();
90
- expected = expected.toLowerCase();
82
+ if (!(expected instanceof RegExp)) {
83
+ expected = expected.toLowerCase();
84
+ }
85
+ }
86
+ if (expected instanceof RegExp) {
87
+ return {
88
+ value: actual,
89
+ result: !!actual.match(expected)
90
+ };
91
91
  }
92
92
  if (containing) {
93
93
  return {
@@ -100,8 +100,7 @@ const compareText = (actual, expected, { ignoreCase = false, trim = true, contai
100
100
  result: actual === expected
101
101
  };
102
102
  };
103
- exports.compareText = compareText;
104
- const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false }) => {
103
+ export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false }) => {
105
104
  if (typeof actual !== 'string') {
106
105
  return {
107
106
  value: actual,
@@ -113,22 +112,17 @@ const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim
113
112
  }
114
113
  if (ignoreCase) {
115
114
  actual = actual.toLowerCase();
116
- expectedArray = expectedArray.map(item => item.toLowerCase());
117
- }
118
- if (containing) {
119
- const textInArray = expectedArray.some((t) => actual.includes(t));
120
- return {
121
- value: actual,
122
- result: textInArray
123
- };
115
+ expectedArray = expectedArray.map(item => (item instanceof RegExp) ? item : item.toLowerCase());
124
116
  }
117
+ const textInArray = expectedArray.some((expected) => {
118
+ return expected instanceof RegExp ? !!actual.match(expected) : containing ? actual.includes(expected) : actual === expected;
119
+ });
125
120
  return {
126
121
  value: actual,
127
- result: expectedArray.includes(actual)
122
+ result: textInArray
128
123
  };
129
124
  };
130
- exports.compareTextWithArray = compareTextWithArray;
131
- const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }) => {
125
+ export const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }) => {
132
126
  let result = true;
133
127
  const actual = {};
134
128
  for (const key in style) {
@@ -151,11 +145,9 @@ const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }
151
145
  result
152
146
  };
153
147
  };
154
- exports.compareStyle = compareStyle;
155
148
  function aliasFn(fn, { verb, expectation } = {}, ...args) {
156
- const context = expectAdapter_1.getContext(this);
157
- context.verb = verb;
158
- context.expectation = expectation;
159
- return fn.apply(context, args);
149
+ this.verb = verb;
150
+ this.expectation = expectation;
151
+ return fn.apply(this, args);
160
152
  }
161
- exports.aliasFn = aliasFn;
153
+ export { updateElementsArray, wrapExpectedWithArray, enhanceError, numberError, executeCommand, executeCommandBe, waitUntil, compareNumbers, aliasFn };