expect-webdriverio 5.6.6 → 5.6.8
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/softExpect.js +22 -20
- package/lib/util/formatMessage.js +22 -22
- package/lib/utils.js +2 -2
- package/package.json +24 -25
package/lib/softExpect.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { expect
|
|
1
|
+
import { expect } from './index.js';
|
|
2
2
|
import { SoftAssertService } from './softAssert.js';
|
|
3
|
+
const isPossibleMatcher = (propName) => propName.startsWith('to') && propName.length > 2;
|
|
3
4
|
const createSoftExpect = (actual) => {
|
|
4
5
|
const softService = SoftAssertService.getInstance();
|
|
5
6
|
return new Proxy({}, {
|
|
@@ -11,7 +12,7 @@ const createSoftExpect = (actual) => {
|
|
|
11
12
|
if (propName === 'resolves' || propName === 'rejects') {
|
|
12
13
|
return createSoftChainProxy(actual, propName, softService);
|
|
13
14
|
}
|
|
14
|
-
if (
|
|
15
|
+
if (isPossibleMatcher(propName)) {
|
|
15
16
|
return createSoftMatcher(actual, propName, softService);
|
|
16
17
|
}
|
|
17
18
|
return undefined;
|
|
@@ -20,28 +21,22 @@ const createSoftExpect = (actual) => {
|
|
|
20
21
|
};
|
|
21
22
|
const createSoftNotProxy = (actual, softService) => {
|
|
22
23
|
return new Proxy({}, {
|
|
23
|
-
get(
|
|
24
|
+
get(_target, prop) {
|
|
24
25
|
const propName = String(prop);
|
|
25
|
-
|
|
26
|
-
return createSoftMatcher(actual, propName, softService, 'not');
|
|
27
|
-
}
|
|
28
|
-
return undefined;
|
|
26
|
+
return isPossibleMatcher(propName) ? createSoftMatcher(actual, propName, softService, 'not') : undefined;
|
|
29
27
|
}
|
|
30
28
|
});
|
|
31
29
|
};
|
|
32
30
|
const createSoftChainProxy = (actual, chainType, softService) => {
|
|
33
31
|
return new Proxy({}, {
|
|
34
|
-
get(
|
|
32
|
+
get(_target, prop) {
|
|
35
33
|
const propName = String(prop);
|
|
36
|
-
|
|
37
|
-
return createSoftMatcher(actual, propName, softService, chainType);
|
|
38
|
-
}
|
|
39
|
-
return undefined;
|
|
34
|
+
return isPossibleMatcher(propName) ? createSoftMatcher(actual, propName, softService, chainType) : undefined;
|
|
40
35
|
}
|
|
41
36
|
});
|
|
42
37
|
};
|
|
43
38
|
const createSoftMatcher = (actual, matcherName, softService, prefix) => {
|
|
44
|
-
return
|
|
39
|
+
return (...args) => {
|
|
45
40
|
try {
|
|
46
41
|
let expectChain = expect(actual);
|
|
47
42
|
if (prefix === 'not') {
|
|
@@ -53,16 +48,23 @@ const createSoftMatcher = (actual, matcherName, softService, prefix) => {
|
|
|
53
48
|
else if (prefix === 'rejects') {
|
|
54
49
|
expectChain = expectChain.rejects;
|
|
55
50
|
}
|
|
56
|
-
|
|
51
|
+
const assertionResult = expectChain[matcherName](...args);
|
|
52
|
+
if (assertionResult instanceof Promise) {
|
|
53
|
+
return assertionResult.catch((error) => handlingMatcherFailure(prefix, matcherName, softService, error));
|
|
54
|
+
}
|
|
55
|
+
return assertionResult;
|
|
57
56
|
}
|
|
58
57
|
catch (error) {
|
|
59
|
-
|
|
60
|
-
softService.addFailure(error, fullMatcherName);
|
|
61
|
-
return {
|
|
62
|
-
pass: true,
|
|
63
|
-
message: () => `Soft assertion failed: ${fullMatcherName}`
|
|
64
|
-
};
|
|
58
|
+
return handlingMatcherFailure(prefix, matcherName, softService, error);
|
|
65
59
|
}
|
|
66
60
|
};
|
|
67
61
|
};
|
|
62
|
+
function handlingMatcherFailure(prefix, matcherName, softService, error) {
|
|
63
|
+
const fullMatcherName = prefix ? `${prefix}.${matcherName}` : matcherName;
|
|
64
|
+
softService.addFailure(error, fullMatcherName);
|
|
65
|
+
return {
|
|
66
|
+
pass: true,
|
|
67
|
+
message: () => `Soft assertion failed: ${fullMatcherName}`
|
|
68
|
+
};
|
|
69
|
+
}
|
|
68
70
|
export default createSoftExpect;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { printDiffOrStringify, printExpected, printReceived } from 'jest-matcher-utils';
|
|
2
2
|
import { equals } from '../jasmineUtils.js';
|
|
3
3
|
import { isElementArray } from './elementsUtil.js';
|
|
4
|
-
const EXPECTED_LABEL = 'Expected';
|
|
5
|
-
const RECEIVED_LABEL = 'Received';
|
|
6
|
-
const NOT_SUFFIX = ' [not]';
|
|
7
|
-
const NOT_EXPECTED_LABEL = EXPECTED_LABEL + NOT_SUFFIX;
|
|
8
4
|
export const getSelector = (el) => {
|
|
9
5
|
let result = typeof el.selector === 'string' ? el.selector : '<fn>';
|
|
10
6
|
if (Array.isArray(el) && el.props.length > 0) {
|
|
@@ -30,11 +26,9 @@ export const getSelectors = (el) => {
|
|
|
30
26
|
}
|
|
31
27
|
return selectors.reverse().join('.');
|
|
32
28
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
export const enhanceError = (subject, expected, actual, context, verb, expectation, arg2 = '', { message = '', containing = false }) => {
|
|
37
|
-
const { isNot = false } = context;
|
|
29
|
+
const not = (isNot) => `${isNot ? 'not ' : ''}`;
|
|
30
|
+
export const enhanceError = (subject, expected, actual, context, verb, expectation, expectedValueArgument2 = '', { message = '', containing = false } = {}) => {
|
|
31
|
+
const { isNot = false, useNotInLabel = true } = context;
|
|
38
32
|
subject = typeof subject === 'string' ? subject : getSelectors(subject);
|
|
39
33
|
let contain = '';
|
|
40
34
|
if (containing) {
|
|
@@ -43,25 +37,31 @@ export const enhanceError = (subject, expected, actual, context, verb, expectati
|
|
|
43
37
|
if (verb) {
|
|
44
38
|
verb += ' ';
|
|
45
39
|
}
|
|
46
|
-
|
|
47
|
-
?
|
|
48
|
-
:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
const label = {
|
|
41
|
+
expected: isNot && useNotInLabel ? 'Expected [not]' : 'Expected',
|
|
42
|
+
received: isNot && useNotInLabel ? 'Received ' : 'Received'
|
|
43
|
+
};
|
|
44
|
+
const diffString = equals(actual, expected) ? `\
|
|
45
|
+
${label.expected}: ${printExpected(expected)}
|
|
46
|
+
${label.received}: ${printReceived(actual)}`
|
|
47
|
+
: printDiffOrStringify(expected, actual, label.expected, label.received, true);
|
|
54
48
|
if (message) {
|
|
55
49
|
message += '\n';
|
|
56
50
|
}
|
|
57
|
-
if (
|
|
58
|
-
|
|
51
|
+
if (expectedValueArgument2) {
|
|
52
|
+
expectedValueArgument2 = ` ${expectedValueArgument2}`;
|
|
59
53
|
}
|
|
60
|
-
const msg =
|
|
54
|
+
const msg = `\
|
|
55
|
+
${message}Expect ${subject} ${not(isNot)}to ${verb}${expectation}${expectedValueArgument2}${contain}
|
|
56
|
+
|
|
57
|
+
${diffString}`;
|
|
61
58
|
return msg;
|
|
62
59
|
};
|
|
63
|
-
export const enhanceErrorBe = (subject,
|
|
64
|
-
|
|
60
|
+
export const enhanceErrorBe = (subject, context, options) => {
|
|
61
|
+
const { isNot, verb, expectation } = context;
|
|
62
|
+
const expected = `${not(isNot)}${expectation}`;
|
|
63
|
+
const actual = `${not(!isNot)}${expectation}`;
|
|
64
|
+
return enhanceError(subject, expected, actual, { ...context, useNotInLabel: false }, verb, expectation, '', options);
|
|
65
65
|
};
|
|
66
66
|
export const numberError = (options = {}) => {
|
|
67
67
|
if (typeof options.eq === 'number') {
|
package/lib/utils.js
CHANGED
|
@@ -56,14 +56,14 @@ const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait
|
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
async function executeCommandBe(received, command, options) {
|
|
59
|
-
const { isNot,
|
|
59
|
+
const { isNot, verb = 'be' } = this;
|
|
60
60
|
let el = await received?.getElement();
|
|
61
61
|
const pass = await waitUntil(async () => {
|
|
62
62
|
const result = await executeCommand.call(this, el, async (element) => ({ result: await command(element) }), options);
|
|
63
63
|
el = result.el;
|
|
64
64
|
return result.success;
|
|
65
65
|
}, isNot, options);
|
|
66
|
-
const message = enhanceErrorBe(el,
|
|
66
|
+
const message = enhanceErrorBe(el, { ...this, verb }, options);
|
|
67
67
|
return {
|
|
68
68
|
pass,
|
|
69
69
|
message: () => message,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expect-webdriverio",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.8",
|
|
4
4
|
"author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
|
|
5
5
|
"description": "WebdriverIO Assertion Library",
|
|
6
6
|
"license": "MIT",
|
|
@@ -65,43 +65,42 @@
|
|
|
65
65
|
"test:unit": "vitest --run",
|
|
66
66
|
"test:types": "npm run ts && npm run tsc:root-types",
|
|
67
67
|
"ts": "run-s ts:* ts:*:*",
|
|
68
|
-
"ts:
|
|
69
|
-
"ts:
|
|
70
|
-
"ts:
|
|
71
|
-
"ts:
|
|
72
|
-
"ts:jasmine-async": "cd test-types/jasmine-async && tsc --project ./tsconfig.json",
|
|
68
|
+
"ts:jasmine": "cd test-types/jasmine && vitest --typecheck --typecheck.tsconfig ./tsconfig.json --run",
|
|
69
|
+
"ts:jasmine-global-expect-async": "cd test-types/jasmine-global-expect-async && vitest --typecheck --typecheck.tsconfig ./tsconfig.json --run",
|
|
70
|
+
"ts:jest:@types-jest": "cd test-types/jest-@types_jest && vitest --typecheck --typecheck.tsconfig ./tsconfig.json --run",
|
|
71
|
+
"ts:mocha": "cd test-types/mocha && vitest --typecheck --typecheck.tsconfig ./tsconfig.json --run",
|
|
73
72
|
"checks:all": "npm run build && npm run compile && npm run tsc:root-types && npm run test && npm run ts",
|
|
74
73
|
"watch": "npm run compile -- --watch",
|
|
75
74
|
"prepare": "husky install",
|
|
76
|
-
"playgrounds:setup": "
|
|
77
|
-
"playgrounds:checks:all": "
|
|
78
|
-
"playgrounds:snapshots:update": "cd playgrounds
|
|
75
|
+
"playgrounds:setup": "cd playgrounds && npm run setup",
|
|
76
|
+
"playgrounds:checks:all": "cd playgrounds && npm run checks:all",
|
|
77
|
+
"playgrounds:snapshots:update": "cd playgrounds && npm run snapshots:update"
|
|
79
78
|
},
|
|
80
79
|
"dependencies": {
|
|
81
|
-
"@vitest/snapshot": "^4.
|
|
80
|
+
"@vitest/snapshot": "^4.1.7",
|
|
82
81
|
"deep-eql": "^5.0.2",
|
|
83
|
-
"expect": "^30.
|
|
84
|
-
"jest-matcher-utils": "^30.
|
|
82
|
+
"expect": "^30.4.1",
|
|
83
|
+
"jest-matcher-utils": "^30.4.1"
|
|
85
84
|
},
|
|
86
85
|
"devDependencies": {
|
|
87
|
-
"@types/debug": "^4.1.
|
|
88
|
-
"@types/jasmine": "^5.1.
|
|
86
|
+
"@types/debug": "^4.1.13",
|
|
87
|
+
"@types/jasmine": "^5.1.15",
|
|
89
88
|
"@types/jest": "^30.0.0",
|
|
90
|
-
"@types/node": "^24.
|
|
89
|
+
"@types/node": "^24.12.4",
|
|
91
90
|
"@types/mocha": "^10.0.10",
|
|
92
|
-
"@jest/globals": "^30.
|
|
93
|
-
"@vitest/coverage-v8": "^4.
|
|
94
|
-
"@wdio/eslint": "^0.1.
|
|
95
|
-
"@wdio/types": "^9.
|
|
96
|
-
"eslint": "^9.39.
|
|
91
|
+
"@jest/globals": "^30.4.1",
|
|
92
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
93
|
+
"@wdio/eslint": "^0.1.3",
|
|
94
|
+
"@wdio/types": "^9.27.2",
|
|
95
|
+
"eslint": "^9.39.4",
|
|
97
96
|
"husky": "^9.1.7",
|
|
98
|
-
"npm-run-all2": "^
|
|
99
|
-
"release-it": "^
|
|
100
|
-
"rimraf": "^6.1.
|
|
97
|
+
"npm-run-all2": "^9.0.1",
|
|
98
|
+
"release-it": "^20.2.0",
|
|
99
|
+
"rimraf": "^6.1.3",
|
|
101
100
|
"shelljs": "^0.10.0",
|
|
102
101
|
"typescript": "^5.9.3",
|
|
103
|
-
"vitest": "^4.
|
|
104
|
-
"webdriverio": "^9.
|
|
102
|
+
"vitest": "^4.1.7",
|
|
103
|
+
"webdriverio": "^9.27.2"
|
|
105
104
|
},
|
|
106
105
|
"peerDependencies": {
|
|
107
106
|
"@wdio/globals": "^9.0.0",
|