expect-webdriverio 4.10.1 → 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/index.js CHANGED
@@ -21,5 +21,5 @@ export const setDefaultOptions = (options = {}) => {
21
21
  });
22
22
  };
23
23
  export const setOptions = setDefaultOptions;
24
- export * from './snapshot.js';
24
+ export { SnapshotService } from './snapshot.js';
25
25
  export * as utils from './utils.js';
package/lib/snapshot.js CHANGED
@@ -1,33 +1,51 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- 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");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
1
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
2
  if (kind === "m") throw new TypeError("Private method is not writable");
8
3
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
5
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
6
  };
12
- var _SnapshotService_instances, _SnapshotService_currentFilePath, _SnapshotService_currentTestName, _SnapshotService_options, _SnapshotService_snapshotResults, _SnapshotService_snapshotEnvironment, _SnapshotService_snapshotClient, _SnapshotService_isEqual;
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
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
- constructor(updateState) {
32
+ constructor(options) {
19
33
  _SnapshotService_instances.add(this);
20
34
  _SnapshotService_currentFilePath.set(this, void 0);
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, new NodeSnapshotEnvironment());
25
38
  _SnapshotService_snapshotClient.set(this, new SnapshotClient({
26
39
  isEqual: __classPrivateFieldGet(this, _SnapshotService_instances, "m", _SnapshotService_isEqual).bind(this),
27
40
  }));
41
+ const updateSnapshot = (Boolean(process.env.CI) && !options?.updateState)
42
+ ? 'none'
43
+ : options?.updateState
44
+ ? options.updateState
45
+ : 'new';
28
46
  __classPrivateFieldSet(this, _SnapshotService_options, {
29
- updateSnapshot: updateState,
30
- snapshotEnvironment: __classPrivateFieldGet(this, _SnapshotService_snapshotEnvironment, "f"),
47
+ updateSnapshot,
48
+ snapshotEnvironment: new WebdriverIOSnapshotEnvironment(options?.resolveSnapshotPath)
31
49
  }, "f");
32
50
  }
33
51
  get currentFilePath() {
@@ -54,14 +72,14 @@ export class SnapshotService {
54
72
  }
55
73
  __classPrivateFieldGet(this, _SnapshotService_snapshotResults, "f").push(result);
56
74
  }
57
- static initiate(updateState = 'new') {
75
+ static initiate(options) {
58
76
  if (!service) {
59
- service = new SnapshotService(updateState);
77
+ service = new SnapshotService(options);
60
78
  }
61
79
  return service;
62
80
  }
63
81
  }
64
- _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) {
65
83
  try {
66
84
  expect(received).toBe(expected);
67
85
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "4.10.1",
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,10 +3,14 @@ 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
7
+ interface SnapshotServiceArgs {
8
+ updateState?: SnapshotUpdateState
9
+ resolveSnapshotPath?: ResolveSnapshotPathFunction
10
+ }
11
+
6
12
  class SnapshotService {
7
- static initiate(
8
- updateState?: import('@vitest/snapshot').SnapshotUpdateState
9
- ): import('@wdio/types').Services.ServiceInstance & {
13
+ static initiate(options: SnapshotServiceArgs): import('@wdio/types').Services.ServiceInstance & {
10
14
  results: import('@vitest/snapshot').SnapshotResult[]
11
15
  }
12
16
  }