expect-webdriverio 4.11.0 → 4.11.2
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/snapshot.js +25 -10
- package/package.json +1 -1
- package/types/expect-webdriverio.d.ts +3 -2
package/lib/snapshot.js
CHANGED
|
@@ -9,11 +9,25 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _SnapshotService_instances, _SnapshotService_currentFilePath, _SnapshotService_currentTestName, _SnapshotService_options, _SnapshotService_snapshotResults,
|
|
12
|
+
var _WebdriverIOSnapshotEnvironment_resolveSnapshotPath, _SnapshotService_instances, _SnapshotService_currentFilePath, _SnapshotService_currentTestName, _SnapshotService_options, _SnapshotService_snapshotResults, _SnapshotService_snapshotClient, _SnapshotService_isEqual;
|
|
13
13
|
import { expect } from '@wdio/globals';
|
|
14
14
|
import { SnapshotClient } from '@vitest/snapshot';
|
|
15
15
|
import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
|
|
16
16
|
let service;
|
|
17
|
+
class WebdriverIOSnapshotEnvironment extends NodeSnapshotEnvironment {
|
|
18
|
+
constructor(resolveSnapshotPath) {
|
|
19
|
+
super({});
|
|
20
|
+
_WebdriverIOSnapshotEnvironment_resolveSnapshotPath.set(this, void 0);
|
|
21
|
+
__classPrivateFieldSet(this, _WebdriverIOSnapshotEnvironment_resolveSnapshotPath, resolveSnapshotPath, "f");
|
|
22
|
+
}
|
|
23
|
+
async resolvePath(filepath) {
|
|
24
|
+
if (__classPrivateFieldGet(this, _WebdriverIOSnapshotEnvironment_resolveSnapshotPath, "f")) {
|
|
25
|
+
return __classPrivateFieldGet(this, _WebdriverIOSnapshotEnvironment_resolveSnapshotPath, "f").call(this, filepath, '.snap');
|
|
26
|
+
}
|
|
27
|
+
return super.resolvePath(filepath);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
_WebdriverIOSnapshotEnvironment_resolveSnapshotPath = new WeakMap();
|
|
17
31
|
export class SnapshotService {
|
|
18
32
|
constructor(options) {
|
|
19
33
|
_SnapshotService_instances.add(this);
|
|
@@ -21,16 +35,17 @@ export class SnapshotService {
|
|
|
21
35
|
_SnapshotService_currentTestName.set(this, void 0);
|
|
22
36
|
_SnapshotService_options.set(this, void 0);
|
|
23
37
|
_SnapshotService_snapshotResults.set(this, []);
|
|
24
|
-
_SnapshotService_snapshotEnvironment.set(this, void 0);
|
|
25
38
|
_SnapshotService_snapshotClient.set(this, new SnapshotClient({
|
|
26
39
|
isEqual: __classPrivateFieldGet(this, _SnapshotService_instances, "m", _SnapshotService_isEqual).bind(this),
|
|
27
40
|
}));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
const updateSnapshot = (Boolean(process.env.CI) && !options?.updateState)
|
|
42
|
+
? 'none'
|
|
43
|
+
: options?.updateState
|
|
44
|
+
? options.updateState
|
|
45
|
+
: 'new';
|
|
31
46
|
__classPrivateFieldSet(this, _SnapshotService_options, {
|
|
32
|
-
updateSnapshot
|
|
33
|
-
snapshotEnvironment:
|
|
47
|
+
updateSnapshot,
|
|
48
|
+
snapshotEnvironment: new WebdriverIOSnapshotEnvironment(options?.resolveSnapshotPath)
|
|
34
49
|
}, "f");
|
|
35
50
|
}
|
|
36
51
|
get currentFilePath() {
|
|
@@ -45,10 +60,10 @@ export class SnapshotService {
|
|
|
45
60
|
get results() {
|
|
46
61
|
return __classPrivateFieldGet(this, _SnapshotService_snapshotResults, "f");
|
|
47
62
|
}
|
|
48
|
-
beforeTest(test) {
|
|
63
|
+
async beforeTest(test) {
|
|
49
64
|
__classPrivateFieldSet(this, _SnapshotService_currentFilePath, test.file, "f");
|
|
50
65
|
__classPrivateFieldSet(this, _SnapshotService_currentTestName, `${test.parent} > ${test.title}`, "f");
|
|
51
|
-
__classPrivateFieldGet(this, _SnapshotService_snapshotClient, "f").startCurrentRun(test.file, test.fullTitle, __classPrivateFieldGet(this, _SnapshotService_options, "f"));
|
|
66
|
+
await __classPrivateFieldGet(this, _SnapshotService_snapshotClient, "f").startCurrentRun(test.file, test.fullTitle, __classPrivateFieldGet(this, _SnapshotService_options, "f"));
|
|
52
67
|
}
|
|
53
68
|
async after() {
|
|
54
69
|
const result = await __classPrivateFieldGet(this, _SnapshotService_snapshotClient, "f").finishCurrentRun();
|
|
@@ -64,7 +79,7 @@ export class SnapshotService {
|
|
|
64
79
|
return service;
|
|
65
80
|
}
|
|
66
81
|
}
|
|
67
|
-
_SnapshotService_currentFilePath = new WeakMap(), _SnapshotService_currentTestName = new WeakMap(), _SnapshotService_options = new WeakMap(), _SnapshotService_snapshotResults = new WeakMap(),
|
|
82
|
+
_SnapshotService_currentFilePath = new WeakMap(), _SnapshotService_currentTestName = new WeakMap(), _SnapshotService_options = new WeakMap(), _SnapshotService_snapshotResults = new WeakMap(), _SnapshotService_snapshotClient = new WeakMap(), _SnapshotService_instances = new WeakSet(), _SnapshotService_isEqual = function _SnapshotService_isEqual(received, expected) {
|
|
68
83
|
try {
|
|
69
84
|
expect(received).toBe(expected);
|
|
70
85
|
return true;
|
package/package.json
CHANGED
|
@@ -3,9 +3,10 @@ declare namespace ExpectWebdriverIO {
|
|
|
3
3
|
function setOptions(options: DefaultOptions): void
|
|
4
4
|
function getConfig(): any
|
|
5
5
|
|
|
6
|
+
type ResolveSnapshotPathFunction = (path: string, extension: string) => string
|
|
6
7
|
interface SnapshotServiceArgs {
|
|
7
|
-
updateState?:
|
|
8
|
-
|
|
8
|
+
updateState?: SnapshotUpdateState
|
|
9
|
+
resolveSnapshotPath?: ResolveSnapshotPathFunction
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
class SnapshotService {
|