expect-webdriverio 6.0.9 → 6.1.0-alpha.0

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.
package/lib/constants.js CHANGED
@@ -1,21 +1,31 @@
1
- export const DEFAULT_FEATURE_FLAGS = {
2
- useToHaveTextStrictMultiElementsCompareStrategy: false
3
- };
4
- export const DEFAULT_OPTIONS = {
5
- wait: 2000,
6
- interval: 100,
7
- beforeAssertion: async () => { },
8
- afterAssertion: async () => { },
9
- featureFlags: DEFAULT_FEATURE_FLAGS
10
- };
11
- export const DEFAULT_OPTIONS_TO_BE_DISPLAYED = {
12
- ...DEFAULT_OPTIONS,
13
- withinViewport: false,
14
- contentVisibilityAuto: true,
15
- opacityProperty: true,
16
- visibilityProperty: true
17
- };
18
- export const defaultOptionsList = [
19
- DEFAULT_OPTIONS,
20
- DEFAULT_OPTIONS_TO_BE_DISPLAYED
21
- ];
1
+ import { getGlobalSingleton } from './util/globalSingleton.js';
2
+ function createSharedConstants() {
3
+ const DEFAULT_FEATURE_FLAGS = {
4
+ useToHaveTextStrictMultiElementsCompareStrategy: false
5
+ };
6
+ const DEFAULT_OPTIONS = {
7
+ wait: 2000,
8
+ interval: 100,
9
+ beforeAssertion: async () => { },
10
+ afterAssertion: async () => { },
11
+ featureFlags: DEFAULT_FEATURE_FLAGS
12
+ };
13
+ const DEFAULT_OPTIONS_TO_BE_DISPLAYED = {
14
+ ...DEFAULT_OPTIONS,
15
+ withinViewport: false,
16
+ contentVisibilityAuto: true,
17
+ opacityProperty: true,
18
+ visibilityProperty: true
19
+ };
20
+ return {
21
+ DEFAULT_FEATURE_FLAGS,
22
+ DEFAULT_OPTIONS,
23
+ DEFAULT_OPTIONS_TO_BE_DISPLAYED,
24
+ defaultOptionsList: [DEFAULT_OPTIONS, DEFAULT_OPTIONS_TO_BE_DISPLAYED]
25
+ };
26
+ }
27
+ const shared = getGlobalSingleton('constants', createSharedConstants);
28
+ export const DEFAULT_FEATURE_FLAGS = shared.DEFAULT_FEATURE_FLAGS;
29
+ export const DEFAULT_OPTIONS = shared.DEFAULT_OPTIONS;
30
+ export const DEFAULT_OPTIONS_TO_BE_DISPLAYED = shared.DEFAULT_OPTIONS_TO_BE_DISPLAYED;
31
+ export const defaultOptionsList = shared.defaultOptionsList;
package/lib/index.js CHANGED
@@ -4,41 +4,52 @@ import { DEFAULT_OPTIONS, defaultOptionsList } from './constants.js';
4
4
  import createSoftExpect from './softExpect.js';
5
5
  import { SoftAssertService } from './softAssert.js';
6
6
  import { oneOf } from './matchers/asymmetrics/oneOf.js';
7
- export const wdioCustomMatchers = {};
8
- export const matchers = new Map();
9
- const extend = expectLib.extend;
10
- expectLib.extend = (extendedMatchers) => {
11
- if (!extendedMatchers || typeof extendedMatchers !== 'object') {
12
- return;
13
- }
14
- Object.entries(extendedMatchers).forEach(([name, matcher]) => {
15
- wdioCustomMatchers[name] = matcher;
16
- matchers.set(name, matcher);
7
+ import { getGlobalSingleton } from './util/globalSingleton.js';
8
+ function createSharedExpectSetup() {
9
+ const wdioCustomMatchers = {};
10
+ const matchers = new Map();
11
+ const extend = expectLib.extend;
12
+ expectLib.extend = (extendedMatchers) => {
13
+ if (!extendedMatchers || typeof extendedMatchers !== 'object') {
14
+ return;
15
+ }
16
+ Object.entries(extendedMatchers).forEach(([name, matcher]) => {
17
+ wdioCustomMatchers[name] = matcher;
18
+ matchers.set(name, matcher);
19
+ });
20
+ return extend(extendedMatchers);
21
+ };
22
+ const filteredWdioMatchers = {};
23
+ Object.entries(wdioMatchers).forEach(([matcher, value]) => {
24
+ if (typeof value === 'function') {
25
+ filteredWdioMatchers[matcher] = value;
26
+ }
17
27
  });
18
- return extend(extendedMatchers);
19
- };
20
- const filteredWdioMatchers = {};
21
- Object.entries(wdioMatchers).forEach(([matcher, value]) => {
22
- if (typeof value === 'function') {
23
- filteredWdioMatchers[matcher] = value;
24
- }
25
- });
26
- const wdioExpect = expectLib;
27
- wdioExpect.extend(filteredWdioMatchers);
28
- wdioExpect.oneOf = oneOf;
29
- Object.defineProperty(wdioExpect, 'soft', {
30
- value: (actual) => createSoftExpect(actual)
31
- });
32
- Object.defineProperty(wdioExpect, 'getSoftFailures', {
33
- value: (testId) => SoftAssertService.getInstance().getFailures(testId)
34
- });
35
- Object.defineProperty(wdioExpect, 'assertSoftFailures', {
36
- value: (testId) => SoftAssertService.getInstance().assertNoFailures(testId)
37
- });
38
- Object.defineProperty(wdioExpect, 'clearSoftFailures', {
39
- value: (testId) => SoftAssertService.getInstance().clearFailures(testId)
40
- });
41
- export const expect = wdioExpect;
28
+ const wdioExpect = expectLib;
29
+ wdioExpect.extend(filteredWdioMatchers);
30
+ wdioExpect.oneOf = oneOf;
31
+ Object.defineProperty(wdioExpect, 'soft', {
32
+ configurable: true,
33
+ value: (actual) => createSoftExpect(actual)
34
+ });
35
+ Object.defineProperty(wdioExpect, 'getSoftFailures', {
36
+ configurable: true,
37
+ value: (testId) => SoftAssertService.getInstance().getFailures(testId)
38
+ });
39
+ Object.defineProperty(wdioExpect, 'assertSoftFailures', {
40
+ configurable: true,
41
+ value: (testId) => SoftAssertService.getInstance().assertNoFailures(testId)
42
+ });
43
+ Object.defineProperty(wdioExpect, 'clearSoftFailures', {
44
+ configurable: true,
45
+ value: (testId) => SoftAssertService.getInstance().clearFailures(testId)
46
+ });
47
+ return { wdioExpect, wdioCustomMatchers, matchers };
48
+ }
49
+ const sharedExpectSetup = getGlobalSingleton('expect', createSharedExpectSetup);
50
+ export const wdioCustomMatchers = sharedExpectSetup.wdioCustomMatchers;
51
+ export const matchers = sharedExpectSetup.matchers;
52
+ export const expect = sharedExpectSetup.wdioExpect;
42
53
  export const getDefaultOptions = () => DEFAULT_OPTIONS;
43
54
  export const setDefaultOptions = (options) => {
44
55
  Object.entries(options).forEach(([key, value]) => {
@@ -1,6 +1,6 @@
1
1
  import { waitUntil, enhanceError, compareText } from '../../utils.js';
2
2
  import { DEFAULT_OPTIONS } from '../../constants.js';
3
- import { expect } from '../../index.js';
3
+ import { expect } from 'expect';
4
4
  export async function toHaveLocalStorageItem(browser, key, expectedValue, options = DEFAULT_OPTIONS) {
5
5
  const { expectation = 'localStorage item', verb = 'have', isNot, matcherName = 'toHaveLocalStorageItem' } = this;
6
6
  await options.beforeAssertion?.({
@@ -1,7 +1,7 @@
1
1
  import { DEFAULT_OPTIONS } from '../../constants.js';
2
2
  import { executeCommandWithStrategy } from '../../util/executeCommand.js';
3
3
  import { compareText, enhanceError, isAsymmetricMatcher, waitUntil, wrapExpectedWithArray } from '../../utils.js';
4
- import { expect as wdioExpect } from '../../index.js';
4
+ import { expect } from 'expect';
5
5
  import { buildWdioAsymmetricMatchersWithOptions } from '../asymmetrics/asymmetricsUtils.js';
6
6
  import { isOneOfMatcher } from '../asymmetrics/oneOf.js';
7
7
  async function conditionAttributeValueMatchWithExpected(el, attribute, expectedValue, options) {
@@ -51,7 +51,7 @@ export async function toHaveAttribute(received, attribute, value, options = DEFA
51
51
  if (paramsCount > 2) {
52
52
  console.warn('Using undefined or null as value for toHaveAttribute is deprecated and will be removed in v6.0.0. Please omit the third argument entirely or use toHaveAttribute(el, attribute, wdioExpect.anything(), options).');
53
53
  }
54
- expectedValue = wdioExpect.anything();
54
+ expectedValue = expect.anything();
55
55
  }
56
56
  else {
57
57
  expectedValue = value;
@@ -1,6 +1,6 @@
1
1
  import { DEFAULT_OPTIONS } from '../../constants.js';
2
2
  import { executeCommandWithStrategy } from '../../util/executeCommand.js';
3
- import { expect as wdioExpect } from '../../index.js';
3
+ import { expect } from 'expect';
4
4
  import { compareText, enhanceError, isAsymmetricMatcher, waitUntil, wrapExpectedWithArray } from '../../utils.js';
5
5
  import { buildWdioAsymmetricMatchersWithOptions } from '../asymmetrics/asymmetricsUtils.js';
6
6
  import { isOneOfMatcher } from '../asymmetrics/oneOf.js';
@@ -25,7 +25,7 @@ export async function toHaveElementProperty(received, property, value, options =
25
25
  if (paramsCount > 2) {
26
26
  console.warn('Using undefined or null as value for toHaveElementProperty is deprecated and will be removed in v6.0.0. Please omit the third argument entirely or use toHaveElementProperty(el, property, object.anything(), options).');
27
27
  }
28
- value = wdioExpect.anything();
28
+ value = expect.anything();
29
29
  }
30
30
  await options.beforeAssertion?.({
31
31
  matcherName,
package/lib/snapshot.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { expect } from '@wdio/globals';
2
2
  import { SnapshotClient } from '@vitest/snapshot';
3
3
  import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
4
- let service;
4
+ import { getGlobalSingleton } from './util/globalSingleton.js';
5
5
  class WebdriverIOSnapshotEnvironment extends NodeSnapshotEnvironment {
6
6
  #resolveSnapshotPath;
7
7
  constructor(resolveSnapshotPath) {
@@ -84,9 +84,6 @@ export class SnapshotService {
84
84
  }
85
85
  }
86
86
  static initiate(options) {
87
- if (!service) {
88
- service = new SnapshotService(options);
89
- }
90
- return service;
87
+ return getGlobalSingleton('snapshotService', () => new SnapshotService(options));
91
88
  }
92
89
  }
package/lib/softAssert.js CHANGED
@@ -1,14 +1,11 @@
1
+ import { getGlobalSingleton } from './util/globalSingleton.js';
1
2
  export class SoftAssertService {
2
- static instance;
3
3
  static GLOBAL_TEST_ID = '__global_soft_assert_context__';
4
4
  failureMap = new Map();
5
5
  currentTest = null;
6
6
  constructor() { }
7
7
  static getInstance() {
8
- if (!SoftAssertService.instance) {
9
- SoftAssertService.instance = new SoftAssertService();
10
- }
11
- return SoftAssertService.instance;
8
+ return getGlobalSingleton('softAssertService', () => new SoftAssertService());
12
9
  }
13
10
  setCurrentTest(testId, testName, testFile) {
14
11
  this.currentTest = { id: testId, name: testName, file: testFile };
@@ -1 +1 @@
1
- {"root":["../src/constants.ts","../src/index.ts","../src/jasmineUtils.ts","../src/matchers.ts","../src/snapshot.ts","../src/softAssert.ts","../src/softAssertService.ts","../src/softExpect.ts","../src/types.ts","../src/utils.ts","../src/api/index.ts","../src/matchers/snapshot.ts","../src/matchers/asymmetrics/asymmetricsUtils.ts","../src/matchers/asymmetrics/oneOf.ts","../src/matchers/browser/toHaveClipboardText.ts","../src/matchers/browser/toHaveLocalStorageItem.ts","../src/matchers/browser/toHaveTitle.ts","../src/matchers/browser/toHaveUrl.ts","../src/matchers/element/toBeClickable.ts","../src/matchers/element/toBeDisabled.ts","../src/matchers/element/toBeDisplayed.ts","../src/matchers/element/toBeDisplayedInViewport.ts","../src/matchers/element/toBeEnabled.ts","../src/matchers/element/toBeExisting.ts","../src/matchers/element/toBeFocused.ts","../src/matchers/element/toBeSelected.ts","../src/matchers/element/toHaveAttribute.ts","../src/matchers/element/toHaveChildren.ts","../src/matchers/element/toHaveComputedLabel.ts","../src/matchers/element/toHaveComputedRole.ts","../src/matchers/element/toHaveElementClass.ts","../src/matchers/element/toHaveElementProperty.ts","../src/matchers/element/toHaveHTML.ts","../src/matchers/element/toHaveHeight.ts","../src/matchers/element/toHaveHref.ts","../src/matchers/element/toHaveId.ts","../src/matchers/element/toHaveSize.ts","../src/matchers/element/toHaveStyle.ts","../src/matchers/element/toHaveText.ts","../src/matchers/element/toHaveValue.ts","../src/matchers/element/toHaveWidth.ts","../src/matchers/elements/toBeElementsArrayOfSize.ts","../src/matchers/mock/toBeRequested.ts","../src/matchers/mock/toBeRequestedTimes.ts","../src/matchers/mock/toBeRequestedWith.ts","../src/matchers/modifiers/some.ts","../src/util/commandOptionsUtils.ts","../src/util/elementsUtil.ts","../src/util/executeCommand.ts","../src/util/formatMessage.ts","../src/util/numberOptionsUtil.ts","../src/util/refetchElements.ts","../src/util/stringUtil.ts","../src/util/waitUntil.ts"],"version":"5.9.3"}
1
+ {"root":["../src/constants.ts","../src/index.ts","../src/jasmineUtils.ts","../src/matchers.ts","../src/snapshot.ts","../src/softAssert.ts","../src/softAssertService.ts","../src/softExpect.ts","../src/types.ts","../src/utils.ts","../src/api/index.ts","../src/matchers/snapshot.ts","../src/matchers/asymmetrics/asymmetricsUtils.ts","../src/matchers/asymmetrics/oneOf.ts","../src/matchers/browser/toHaveClipboardText.ts","../src/matchers/browser/toHaveLocalStorageItem.ts","../src/matchers/browser/toHaveTitle.ts","../src/matchers/browser/toHaveUrl.ts","../src/matchers/element/toBeClickable.ts","../src/matchers/element/toBeDisabled.ts","../src/matchers/element/toBeDisplayed.ts","../src/matchers/element/toBeDisplayedInViewport.ts","../src/matchers/element/toBeEnabled.ts","../src/matchers/element/toBeExisting.ts","../src/matchers/element/toBeFocused.ts","../src/matchers/element/toBeSelected.ts","../src/matchers/element/toHaveAttribute.ts","../src/matchers/element/toHaveChildren.ts","../src/matchers/element/toHaveComputedLabel.ts","../src/matchers/element/toHaveComputedRole.ts","../src/matchers/element/toHaveElementClass.ts","../src/matchers/element/toHaveElementProperty.ts","../src/matchers/element/toHaveHTML.ts","../src/matchers/element/toHaveHeight.ts","../src/matchers/element/toHaveHref.ts","../src/matchers/element/toHaveId.ts","../src/matchers/element/toHaveSize.ts","../src/matchers/element/toHaveStyle.ts","../src/matchers/element/toHaveText.ts","../src/matchers/element/toHaveValue.ts","../src/matchers/element/toHaveWidth.ts","../src/matchers/elements/toBeElementsArrayOfSize.ts","../src/matchers/mock/toBeRequested.ts","../src/matchers/mock/toBeRequestedTimes.ts","../src/matchers/mock/toBeRequestedWith.ts","../src/matchers/modifiers/some.ts","../src/util/commandOptionsUtils.ts","../src/util/elementsUtil.ts","../src/util/executeCommand.ts","../src/util/formatMessage.ts","../src/util/globalSingleton.ts","../src/util/numberOptionsUtil.ts","../src/util/refetchElements.ts","../src/util/stringUtil.ts","../src/util/waitUntil.ts"],"version":"5.9.3"}
@@ -0,0 +1,8 @@
1
+ import { createRequire } from 'node:module';
2
+ const { version } = createRequire(import.meta.url)('../../package.json');
3
+ const packageMajorVersion = version.split('.')[0];
4
+ export function getGlobalSingleton(key, create) {
5
+ const globalKey = Symbol.for(`expect-webdriverio.${key}@${packageMajorVersion}`);
6
+ const globalScope = globalThis;
7
+ return (globalScope[globalKey] ??= create());
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "6.0.9",
3
+ "version": "6.1.0-alpha.0",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -86,7 +86,7 @@
86
86
  "playgrounds:snapshots:update": "cd playgrounds && npm run snapshots:update"
87
87
  },
88
88
  "dependencies": {
89
- "@vitest/snapshot": "^4.1.10",
89
+ "@vitest/snapshot": "^4.1.11",
90
90
  "deep-eql": "^5.0.2",
91
91
  "expect": "^30.4.1",
92
92
  "jest-matcher-utils": "^30.4.1"
@@ -99,10 +99,10 @@
99
99
  "@types/jest": "^30.0.0",
100
100
  "@types/mocha": "^10.0.10",
101
101
  "@types/node": "^24.13.3",
102
- "@vitest/coverage-v8": "^4.1.10",
102
+ "@vitest/coverage-v8": "^4.1.11",
103
103
  "@vitest/eslint-plugin": "^1.6.27",
104
104
  "@wdio/eslint": "^0.1.3",
105
- "@wdio/types": "^9.31.1",
105
+ "@wdio/types": "^9.32.0",
106
106
  "eslint": "^9.39.5",
107
107
  "husky": "^9.1.7",
108
108
  "npm-run-all2": "^9.0.3",
@@ -110,8 +110,8 @@
110
110
  "rimraf": "^6.1.3",
111
111
  "strip-ansi": "^7.2.0",
112
112
  "typescript": "^5.9.3",
113
- "vitest": "^4.1.10",
114
- "webdriverio": "^9.30.1"
113
+ "vitest": "^4.1.11",
114
+ "webdriverio": "^9.32.0"
115
115
  },
116
116
  "peerDependencies": {
117
117
  "@wdio/globals": "^9.0.0",
@@ -22,6 +22,7 @@ type ExpectLibExpectationResult = import('expect').ExpectationResult
22
22
  type ExpectLibMatcherContext = import('expect').MatcherContext
23
23
  type MatchersObject = Parameters<typeof import('expect').expect.extend>[0]
24
24
  type ExpectLibAnything = ReturnType<typeof expect.any> | ReturnType<typeof expect.anything>
25
+ type WdioGetHTMLOptions = NonNullable<Parameters<WebdriverIO.Element['getHTML']>[0]>
25
26
 
26
27
  // Extracted from the expect library, this is the type of the matcher function used in the expect library.
27
28
  type RawMatcherFn<Context extends ExpectLibMatcherContext = ExpectLibMatcherContext> = {
@@ -1102,12 +1103,7 @@ declare namespace ExpectWebdriverIO {
1102
1103
  message?: string
1103
1104
  }
1104
1105
 
1105
- interface HTMLOptions extends StringOptions {
1106
- /**
1107
- * return the HTML with the selector tag included
1108
- */
1109
- includeSelectorTag?: boolean
1110
- }
1106
+ interface HTMLOptions extends StringOptions, WdioGetHTMLOptions {}
1111
1107
 
1112
1108
  interface StringOptions extends CommandOptions {
1113
1109
  /**