react-native-nitro-geolocation 1.1.2 → 1.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-geolocation",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "⚡🚀Blazing-fast geolocation for React Native powered by Nitro Modules",
5
5
  "main": "src/index",
6
6
  "source": "src/index",
@@ -0,0 +1,54 @@
1
+ import { afterEach, describe, expect, it } from "vitest";
2
+ import { isDevtoolsEnabled } from "./index";
3
+
4
+ const globalState = globalThis as typeof globalThis & {
5
+ __DEV__?: boolean;
6
+ __geolocationDevToolsEnabled?: boolean;
7
+ };
8
+
9
+ const originalState = {
10
+ hasDev: Object.prototype.hasOwnProperty.call(globalState, "__DEV__"),
11
+ dev: globalState.__DEV__,
12
+ hasDevtoolsEnabled: Object.prototype.hasOwnProperty.call(
13
+ globalState,
14
+ "__geolocationDevToolsEnabled"
15
+ ),
16
+ devtoolsEnabled: globalState.__geolocationDevToolsEnabled
17
+ };
18
+
19
+ describe("isDevtoolsEnabled", () => {
20
+ afterEach(() => {
21
+ if (originalState.hasDev) {
22
+ globalState.__DEV__ = originalState.dev;
23
+ } else {
24
+ globalState.__DEV__ = undefined;
25
+ }
26
+
27
+ if (originalState.hasDevtoolsEnabled) {
28
+ globalState.__geolocationDevToolsEnabled = originalState.devtoolsEnabled;
29
+ } else {
30
+ globalState.__geolocationDevToolsEnabled = undefined;
31
+ }
32
+ });
33
+
34
+ it("enables devtools only when React Native __DEV__ and the devtools flag are true", () => {
35
+ globalState.__DEV__ = true;
36
+ globalState.__geolocationDevToolsEnabled = true;
37
+
38
+ expect(isDevtoolsEnabled()).toBe(true);
39
+ });
40
+
41
+ it("ignores the devtools flag outside React Native __DEV__", () => {
42
+ globalState.__DEV__ = false;
43
+ globalState.__geolocationDevToolsEnabled = true;
44
+
45
+ expect(isDevtoolsEnabled()).toBe(false);
46
+ });
47
+
48
+ it("stays disabled when __DEV__ is unavailable", () => {
49
+ globalState.__DEV__ = undefined;
50
+ globalState.__geolocationDevToolsEnabled = true;
51
+
52
+ expect(isDevtoolsEnabled()).toBe(false);
53
+ });
54
+ });
@@ -1,5 +1,7 @@
1
1
  import type { GeolocationResponse } from "../types";
2
2
 
3
+ declare const __DEV__: boolean;
4
+
3
5
  declare global {
4
6
  var __geolocationDevToolsEnabled: boolean | undefined;
5
7
  var __geolocationDevtools: DevtoolsState | undefined;
@@ -18,6 +20,10 @@ export function getDevtoolsState(): DevtoolsState {
18
20
  return globalThis.__geolocationDevtools;
19
21
  }
20
22
 
23
+ function isReactNativeDev(): boolean {
24
+ return typeof __DEV__ !== "undefined" && __DEV__ === true;
25
+ }
26
+
21
27
  export function isDevtoolsEnabled(): boolean {
22
- return globalThis.__geolocationDevToolsEnabled === true;
28
+ return isReactNativeDev() && globalThis.__geolocationDevToolsEnabled === true;
23
29
  }