@openmrs/esm-state 8.0.1-pre.3457 → 8.0.1-pre.3465

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.
@@ -1,3 +1,3 @@
1
- [0] Successfully compiled: 3 files with swc (93.17ms)
1
+ [0] Successfully compiled: 3 files with swc (84.14ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
package/dist/state.js CHANGED
@@ -1,10 +1,18 @@
1
1
  /** @module @category Store */ import { shallowEqual } from "@openmrs/esm-utils";
2
2
  import { createStore } from "zustand/vanilla";
3
3
  const availableStores = {};
4
+ // Check if we're in a test environment (Vitest or Jest)
5
+ const isTestEnvironment = ()=>{
6
+ try {
7
+ return process.env.NODE_ENV === 'test' || typeof process !== 'undefined' && (process.env.VITEST === 'true' || process.env.JEST_WORKER_ID !== undefined) || typeof globalThis !== 'undefined' && ('__vitest_worker__' in globalThis || '__jest__' in globalThis);
8
+ } catch {
9
+ return false;
10
+ }
11
+ };
4
12
  // spaEnv isn't available immediately. Wait a bit before making stores available
5
13
  // on window in development mode.
6
14
  setTimeout(()=>{
7
- if (window && window.spaEnv === 'development') {
15
+ if (typeof window !== 'undefined' && window.spaEnv === 'development') {
8
16
  window['stores'] = availableStores;
9
17
  }
10
18
  }, 1000);
@@ -19,7 +27,9 @@ setTimeout(()=>{
19
27
  const available = availableStores[name];
20
28
  if (available) {
21
29
  if (available.active) {
22
- console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
30
+ if (!isTestEnvironment()) {
31
+ console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
32
+ }
23
33
  } else {
24
34
  available.value.setState(initialState, true);
25
35
  }
@@ -45,7 +55,9 @@ setTimeout(()=>{
45
55
  const available = availableStores[name];
46
56
  if (available) {
47
57
  if (available.active) {
48
- console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
58
+ if (!isTestEnvironment()) {
59
+ console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
60
+ }
49
61
  } else {
50
62
  available.value = store;
51
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-state",
3
- "version": "8.0.1-pre.3457",
3
+ "version": "8.0.1-pre.3465",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Frontend stores & state management for OpenMRS",
6
6
  "type": "module",
@@ -58,8 +58,8 @@
58
58
  "@openmrs/esm-utils": "6.x"
59
59
  },
60
60
  "devDependencies": {
61
- "@openmrs/esm-globals": "8.0.1-pre.3457",
62
- "@openmrs/esm-utils": "8.0.1-pre.3457",
61
+ "@openmrs/esm-globals": "8.0.1-pre.3465",
62
+ "@openmrs/esm-utils": "8.0.1-pre.3465",
63
63
  "@swc/cli": "^0.7.7",
64
64
  "@swc/core": "^1.11.29",
65
65
  "concurrently": "^9.1.2",
package/src/state.ts CHANGED
@@ -11,10 +11,23 @@ interface StoreEntity {
11
11
 
12
12
  const availableStores: Record<string, StoreEntity> = {};
13
13
 
14
+ // Check if we're in a test environment (Vitest or Jest)
15
+ const isTestEnvironment = () => {
16
+ try {
17
+ return (
18
+ process.env.NODE_ENV === 'test' ||
19
+ (typeof process !== 'undefined' && (process.env.VITEST === 'true' || process.env.JEST_WORKER_ID !== undefined)) ||
20
+ (typeof globalThis !== 'undefined' && ('__vitest_worker__' in globalThis || '__jest__' in globalThis))
21
+ );
22
+ } catch {
23
+ return false;
24
+ }
25
+ };
26
+
14
27
  // spaEnv isn't available immediately. Wait a bit before making stores available
15
28
  // on window in development mode.
16
29
  setTimeout(() => {
17
- if (window && window.spaEnv === 'development') {
30
+ if (typeof window !== 'undefined' && window.spaEnv === 'development') {
18
31
  window['stores'] = availableStores;
19
32
  }
20
33
  }, 1000);
@@ -32,7 +45,9 @@ export function createGlobalStore<T>(name: string, initialState: T): StoreApi<T>
32
45
 
33
46
  if (available) {
34
47
  if (available.active) {
35
- console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
48
+ if (!isTestEnvironment()) {
49
+ console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
50
+ }
36
51
  } else {
37
52
  available.value.setState(initialState, true);
38
53
  }
@@ -64,7 +79,9 @@ export function registerGlobalStore<T>(name: string, store: StoreApi<T>): StoreA
64
79
 
65
80
  if (available) {
66
81
  if (available.active) {
67
- console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
82
+ if (!isTestEnvironment()) {
83
+ console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
84
+ }
68
85
  } else {
69
86
  available.value = store;
70
87
  }