expect-webdriverio 4.11.0 → 4.11.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.
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, _SnapshotService_snapshotEnvironment, _SnapshotService_snapshotClient, _SnapshotService_isEqual;
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 Promise.resolve(__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
- __classPrivateFieldSet(this, _SnapshotService_snapshotEnvironment, new NodeSnapshotEnvironment({
29
- snapshotsDirName: options?.snapshotsDirName
30
- }), "f");
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: options?.updateState || 'new',
33
- snapshotEnvironment: __classPrivateFieldGet(this, _SnapshotService_snapshotEnvironment, "f"),
47
+ updateSnapshot,
48
+ snapshotEnvironment: new WebdriverIOSnapshotEnvironment(options?.resolveSnapshotPath)
34
49
  }, "f");
35
50
  }
36
51
  get currentFilePath() {
@@ -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(), _SnapshotService_snapshotEnvironment = new WeakMap(), _SnapshotService_snapshotClient = new WeakMap(), _SnapshotService_instances = new WeakSet(), _SnapshotService_isEqual = function _SnapshotService_isEqual(received, expected) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "4.11.0",
3
+ "version": "4.11.1",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -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?: import('@vitest/snapshot').SnapshotUpdateState
8
- snapshotsDirName?: string
8
+ updateState?: SnapshotUpdateState
9
+ resolveSnapshotPath?: ResolveSnapshotPathFunction
9
10
  }
10
11
 
11
12
  class SnapshotService {