@symbiote-native/sensors 0.2.0 → 0.2.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.
Files changed (36) hide show
  1. package/README.md +5 -5
  2. package/native-link.json +52 -0
  3. package/package.json +8 -4
  4. package/src/angular/services/accelerometer.service/accelerometer.service.test.ts +0 -118
  5. package/src/angular/services/barometer.service/barometer.service.test.ts +0 -122
  6. package/src/angular/services/device-motion.service/device-motion.service.test.ts +0 -125
  7. package/src/angular/services/gyroscope.service/gyroscope.service.test.ts +0 -118
  8. package/src/angular/services/light-sensor.service/light-sensor.service.test.ts +0 -118
  9. package/src/angular/services/magnetometer-uncalibrated.service/magnetometer-uncalibrated.service.test.ts +0 -123
  10. package/src/angular/services/magnetometer.service/magnetometer.service.test.ts +0 -118
  11. package/src/angular/services/pedometer.service/pedometer.service.test.ts +0 -86
  12. package/src/core/accelerometer.test.ts +0 -49
  13. package/src/core/barometer.test.ts +0 -46
  14. package/src/core/device-motion.test.ts +0 -60
  15. package/src/core/device-sensor.test.ts +0 -76
  16. package/src/core/gyroscope.test.ts +0 -46
  17. package/src/core/light-sensor.test.ts +0 -49
  18. package/src/core/magnetometer-uncalibrated.test.ts +0 -49
  19. package/src/core/magnetometer.test.ts +0 -49
  20. package/src/core/pedometer.test.ts +0 -118
  21. package/src/react/hooks/use-accelerometer/use-accelerometer.test.tsx +0 -81
  22. package/src/react/hooks/use-barometer/use-barometer.test.tsx +0 -83
  23. package/src/react/hooks/use-device-motion/use-device-motion.test.tsx +0 -88
  24. package/src/react/hooks/use-gyroscope/use-gyroscope.test.tsx +0 -79
  25. package/src/react/hooks/use-light-sensor/use-light-sensor.test.tsx +0 -79
  26. package/src/react/hooks/use-magnetometer/use-magnetometer.test.tsx +0 -81
  27. package/src/react/hooks/use-magnetometer-uncalibrated/use-magnetometer-uncalibrated.test.tsx +0 -88
  28. package/src/react/hooks/use-pedometer/use-pedometer.test.tsx +0 -69
  29. package/src/vue/composables/use-accelerometer/use-accelerometer.test.ts +0 -96
  30. package/src/vue/composables/use-barometer/use-barometer.test.ts +0 -100
  31. package/src/vue/composables/use-device-motion/use-device-motion.test.ts +0 -104
  32. package/src/vue/composables/use-gyroscope/use-gyroscope.test.ts +0 -96
  33. package/src/vue/composables/use-light-sensor/use-light-sensor.test.ts +0 -96
  34. package/src/vue/composables/use-magnetometer/use-magnetometer.test.ts +0 -96
  35. package/src/vue/composables/use-magnetometer-uncalibrated/use-magnetometer-uncalibrated.test.ts +0 -103
  36. package/src/vue/composables/use-pedometer/use-pedometer.test.ts +0 -77
@@ -1,96 +0,0 @@
1
- // Co-located Vue-driven test (ADR 0025) for useGyroscope. Mocks the whole core module
2
- // (never expo-modules-core internals) since this exercises composable mount/unmount lifecycle
3
- // timing, not any native view — there is none here, so no ViewConfig fixture is needed.
4
-
5
- import { defineComponent, h, type Ref } from '@vue/runtime-core';
6
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
- import { mount, unmount } from '@symbiote-native/vue';
8
- import { installFabric } from '@symbiote-native/test-utils';
9
- import type { IGyroscopeMeasurement } from '../../../core';
10
- import { useGyroscope } from './index';
11
-
12
- const ROOT_TAG = 9822;
13
-
14
- type IListener = (measurement: IGyroscopeMeasurement) => void;
15
-
16
- let registeredListener: IListener | undefined;
17
- const removeMock = vi.fn();
18
- const addListenerMock = vi.fn((listener: IListener) => {
19
- registeredListener = listener;
20
- return { remove: removeMock };
21
- });
22
- const setUpdateIntervalMock = vi.fn();
23
-
24
- vi.mock('../../../core', () => ({
25
- Gyroscope: {
26
- addListener: (listener: IListener) => addListenerMock(listener),
27
- removeAllListeners: vi.fn(),
28
- setUpdateInterval: (intervalMs: number) => setUpdateIntervalMock(intervalMs),
29
- },
30
- }));
31
-
32
- const fabric = installFabric();
33
-
34
- beforeEach(() => {
35
- fabric.reset();
36
- registeredListener = undefined;
37
- addListenerMock.mockClear();
38
- removeMock.mockClear();
39
- setUpdateIntervalMock.mockClear();
40
- });
41
-
42
- afterEach(() => unmount(ROOT_TAG));
43
-
44
- function mountGyroscope(updateIntervalMs?: number): Ref<IGyroscopeMeasurement | null> {
45
- let measurement: Ref<IGyroscopeMeasurement | null> | undefined;
46
- mount(
47
- ROOT_TAG,
48
- defineComponent({
49
- setup: () => {
50
- measurement = useGyroscope(updateIntervalMs);
51
- return () => h('symbiote-text', {}, 'sensor');
52
- },
53
- }),
54
- );
55
- if (measurement === undefined) {
56
- throw new Error('setup() did not run');
57
- }
58
- return measurement;
59
- }
60
-
61
- describe('useGyroscope (Vue)', () => {
62
- it('starts null before any measurement arrives', () => {
63
- const measurement = mountGyroscope();
64
-
65
- expect(measurement.value).toBeNull();
66
- });
67
-
68
- it('updates the ref when the native listener fires', () => {
69
- const measurement = mountGyroscope();
70
- const reading: IGyroscopeMeasurement = { x: 0.1, y: 0.2, z: 0.9, timestamp: 123 };
71
-
72
- registeredListener?.(reading);
73
-
74
- expect(measurement.value).toEqual(reading);
75
- });
76
-
77
- it('removes the subscription on unmount', () => {
78
- mountGyroscope();
79
- unmount(ROOT_TAG);
80
-
81
- expect(removeMock).toHaveBeenCalledTimes(1);
82
- });
83
-
84
- it('sets the update interval once at subscribe time when provided', () => {
85
- mountGyroscope(50);
86
-
87
- expect(setUpdateIntervalMock).toHaveBeenCalledWith(50);
88
- expect(setUpdateIntervalMock).toHaveBeenCalledTimes(1);
89
- });
90
-
91
- it('does not touch the update interval when omitted', () => {
92
- mountGyroscope();
93
-
94
- expect(setUpdateIntervalMock).not.toHaveBeenCalled();
95
- });
96
- });
@@ -1,96 +0,0 @@
1
- // Co-located Vue-driven test (ADR 0025) for useLightSensor. Mocks the whole core module
2
- // (never expo-modules-core internals) since this exercises composable mount/unmount lifecycle
3
- // timing, not any native view — there is none here, so no ViewConfig fixture is needed.
4
-
5
- import { defineComponent, h, type Ref } from '@vue/runtime-core';
6
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
- import { mount, unmount } from '@symbiote-native/vue';
8
- import { installFabric } from '@symbiote-native/test-utils';
9
- import type { ILightSensorMeasurement } from '../../../core';
10
- import { useLightSensor } from './index';
11
-
12
- const ROOT_TAG = 9822;
13
-
14
- type IListener = (measurement: ILightSensorMeasurement) => void;
15
-
16
- let registeredListener: IListener | undefined;
17
- const removeMock = vi.fn();
18
- const addListenerMock = vi.fn((listener: IListener) => {
19
- registeredListener = listener;
20
- return { remove: removeMock };
21
- });
22
- const setUpdateIntervalMock = vi.fn();
23
-
24
- vi.mock('../../../core', () => ({
25
- LightSensor: {
26
- addListener: (listener: IListener) => addListenerMock(listener),
27
- removeAllListeners: vi.fn(),
28
- setUpdateInterval: (intervalMs: number) => setUpdateIntervalMock(intervalMs),
29
- },
30
- }));
31
-
32
- const fabric = installFabric();
33
-
34
- beforeEach(() => {
35
- fabric.reset();
36
- registeredListener = undefined;
37
- addListenerMock.mockClear();
38
- removeMock.mockClear();
39
- setUpdateIntervalMock.mockClear();
40
- });
41
-
42
- afterEach(() => unmount(ROOT_TAG));
43
-
44
- function mountLightSensor(updateIntervalMs?: number): Ref<ILightSensorMeasurement | null> {
45
- let measurement: Ref<ILightSensorMeasurement | null> | undefined;
46
- mount(
47
- ROOT_TAG,
48
- defineComponent({
49
- setup: () => {
50
- measurement = useLightSensor(updateIntervalMs);
51
- return () => h('symbiote-text', {}, 'sensor');
52
- },
53
- }),
54
- );
55
- if (measurement === undefined) {
56
- throw new Error('setup() did not run');
57
- }
58
- return measurement;
59
- }
60
-
61
- describe('useLightSensor (Vue)', () => {
62
- it('starts null before any measurement arrives', () => {
63
- const measurement = mountLightSensor();
64
-
65
- expect(measurement.value).toBeNull();
66
- });
67
-
68
- it('updates the ref when the native listener fires', () => {
69
- const measurement = mountLightSensor();
70
- const reading: ILightSensorMeasurement = { illuminance: 42, timestamp: 123 };
71
-
72
- registeredListener?.(reading);
73
-
74
- expect(measurement.value).toEqual(reading);
75
- });
76
-
77
- it('removes the subscription on unmount', () => {
78
- mountLightSensor();
79
- unmount(ROOT_TAG);
80
-
81
- expect(removeMock).toHaveBeenCalledTimes(1);
82
- });
83
-
84
- it('sets the update interval once at subscribe time when provided', () => {
85
- mountLightSensor(50);
86
-
87
- expect(setUpdateIntervalMock).toHaveBeenCalledWith(50);
88
- expect(setUpdateIntervalMock).toHaveBeenCalledTimes(1);
89
- });
90
-
91
- it('does not touch the update interval when omitted', () => {
92
- mountLightSensor();
93
-
94
- expect(setUpdateIntervalMock).not.toHaveBeenCalled();
95
- });
96
- });
@@ -1,96 +0,0 @@
1
- // Co-located Vue-driven test (ADR 0025) for useMagnetometer. Mocks the whole core module
2
- // (never expo-modules-core internals) since this exercises composable mount/unmount lifecycle
3
- // timing, not any native view — there is none here, so no ViewConfig fixture is needed.
4
-
5
- import { defineComponent, h, type Ref } from '@vue/runtime-core';
6
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
- import { mount, unmount } from '@symbiote-native/vue';
8
- import { installFabric } from '@symbiote-native/test-utils';
9
- import type { IMagnetometerMeasurement } from '../../../core';
10
- import { useMagnetometer } from './index';
11
-
12
- const ROOT_TAG = 9822;
13
-
14
- type IListener = (measurement: IMagnetometerMeasurement) => void;
15
-
16
- let registeredListener: IListener | undefined;
17
- const removeMock = vi.fn();
18
- const addListenerMock = vi.fn((listener: IListener) => {
19
- registeredListener = listener;
20
- return { remove: removeMock };
21
- });
22
- const setUpdateIntervalMock = vi.fn();
23
-
24
- vi.mock('../../../core', () => ({
25
- Magnetometer: {
26
- addListener: (listener: IListener) => addListenerMock(listener),
27
- removeAllListeners: vi.fn(),
28
- setUpdateInterval: (intervalMs: number) => setUpdateIntervalMock(intervalMs),
29
- },
30
- }));
31
-
32
- const fabric = installFabric();
33
-
34
- beforeEach(() => {
35
- fabric.reset();
36
- registeredListener = undefined;
37
- addListenerMock.mockClear();
38
- removeMock.mockClear();
39
- setUpdateIntervalMock.mockClear();
40
- });
41
-
42
- afterEach(() => unmount(ROOT_TAG));
43
-
44
- function mountMagnetometer(updateIntervalMs?: number): Ref<IMagnetometerMeasurement | null> {
45
- let measurement: Ref<IMagnetometerMeasurement | null> | undefined;
46
- mount(
47
- ROOT_TAG,
48
- defineComponent({
49
- setup: () => {
50
- measurement = useMagnetometer(updateIntervalMs);
51
- return () => h('symbiote-text', {}, 'sensor');
52
- },
53
- }),
54
- );
55
- if (measurement === undefined) {
56
- throw new Error('setup() did not run');
57
- }
58
- return measurement;
59
- }
60
-
61
- describe('useMagnetometer (Vue)', () => {
62
- it('starts null before any measurement arrives', () => {
63
- const measurement = mountMagnetometer();
64
-
65
- expect(measurement.value).toBeNull();
66
- });
67
-
68
- it('updates the ref when the native listener fires', () => {
69
- const measurement = mountMagnetometer();
70
- const reading: IMagnetometerMeasurement = { x: 0.1, y: 0.2, z: 0.9, timestamp: 123 };
71
-
72
- registeredListener?.(reading);
73
-
74
- expect(measurement.value).toEqual(reading);
75
- });
76
-
77
- it('removes the subscription on unmount', () => {
78
- mountMagnetometer();
79
- unmount(ROOT_TAG);
80
-
81
- expect(removeMock).toHaveBeenCalledTimes(1);
82
- });
83
-
84
- it('sets the update interval once at subscribe time when provided', () => {
85
- mountMagnetometer(50);
86
-
87
- expect(setUpdateIntervalMock).toHaveBeenCalledWith(50);
88
- expect(setUpdateIntervalMock).toHaveBeenCalledTimes(1);
89
- });
90
-
91
- it('does not touch the update interval when omitted', () => {
92
- mountMagnetometer();
93
-
94
- expect(setUpdateIntervalMock).not.toHaveBeenCalled();
95
- });
96
- });
@@ -1,103 +0,0 @@
1
- // Co-located Vue-driven test (ADR 0025) for useMagnetometerUncalibrated. Mocks the whole core
2
- // module (never expo-modules-core internals) since this exercises composable mount/unmount
3
- // lifecycle timing, not any native view — there is none here, so no ViewConfig fixture is needed.
4
-
5
- import { defineComponent, h, type Ref } from '@vue/runtime-core';
6
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
- import { mount, unmount } from '@symbiote-native/vue';
8
- import { installFabric } from '@symbiote-native/test-utils';
9
- import type { IMagnetometerUncalibratedMeasurement } from '../../../core';
10
- import { useMagnetometerUncalibrated } from './index';
11
-
12
- const ROOT_TAG = 9822;
13
-
14
- type IListener = (measurement: IMagnetometerUncalibratedMeasurement) => void;
15
-
16
- let registeredListener: IListener | undefined;
17
- const removeMock = vi.fn();
18
- const addListenerMock = vi.fn((listener: IListener) => {
19
- registeredListener = listener;
20
- return { remove: removeMock };
21
- });
22
- const setUpdateIntervalMock = vi.fn();
23
-
24
- vi.mock('../../../core', () => ({
25
- MagnetometerUncalibrated: {
26
- addListener: (listener: IListener) => addListenerMock(listener),
27
- removeAllListeners: vi.fn(),
28
- setUpdateInterval: (intervalMs: number) => setUpdateIntervalMock(intervalMs),
29
- },
30
- }));
31
-
32
- const fabric = installFabric();
33
-
34
- beforeEach(() => {
35
- fabric.reset();
36
- registeredListener = undefined;
37
- addListenerMock.mockClear();
38
- removeMock.mockClear();
39
- setUpdateIntervalMock.mockClear();
40
- });
41
-
42
- afterEach(() => unmount(ROOT_TAG));
43
-
44
- function mountMagnetometerUncalibrated(
45
- updateIntervalMs?: number,
46
- ): Ref<IMagnetometerUncalibratedMeasurement | null> {
47
- let measurement: Ref<IMagnetometerUncalibratedMeasurement | null> | undefined;
48
- mount(
49
- ROOT_TAG,
50
- defineComponent({
51
- setup: () => {
52
- measurement = useMagnetometerUncalibrated(updateIntervalMs);
53
- return () => h('symbiote-text', {}, 'sensor');
54
- },
55
- }),
56
- );
57
- if (measurement === undefined) {
58
- throw new Error('setup() did not run');
59
- }
60
- return measurement;
61
- }
62
-
63
- describe('useMagnetometerUncalibrated (Vue)', () => {
64
- it('starts null before any measurement arrives', () => {
65
- const measurement = mountMagnetometerUncalibrated();
66
-
67
- expect(measurement.value).toBeNull();
68
- });
69
-
70
- it('updates the ref when the native listener fires', () => {
71
- const measurement = mountMagnetometerUncalibrated();
72
- const reading: IMagnetometerUncalibratedMeasurement = {
73
- x: 0.1,
74
- y: 0.2,
75
- z: 0.9,
76
- timestamp: 123,
77
- };
78
-
79
- registeredListener?.(reading);
80
-
81
- expect(measurement.value).toEqual(reading);
82
- });
83
-
84
- it('removes the subscription on unmount', () => {
85
- mountMagnetometerUncalibrated();
86
- unmount(ROOT_TAG);
87
-
88
- expect(removeMock).toHaveBeenCalledTimes(1);
89
- });
90
-
91
- it('sets the update interval once at subscribe time when provided', () => {
92
- mountMagnetometerUncalibrated(50);
93
-
94
- expect(setUpdateIntervalMock).toHaveBeenCalledWith(50);
95
- expect(setUpdateIntervalMock).toHaveBeenCalledTimes(1);
96
- });
97
-
98
- it('does not touch the update interval when omitted', () => {
99
- mountMagnetometerUncalibrated();
100
-
101
- expect(setUpdateIntervalMock).not.toHaveBeenCalled();
102
- });
103
- });
@@ -1,77 +0,0 @@
1
- // Co-located Vue-driven test (ADR 0025) for usePedometer. Mocks the whole core module (never
2
- // expo-modules-core internals) since this exercises composable mount/unmount lifecycle timing,
3
- // not any native view — there is none here, so no ViewConfig fixture is needed.
4
-
5
- import { defineComponent, h, type Ref } from '@vue/runtime-core';
6
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
- import { mount, unmount } from '@symbiote-native/vue';
8
- import { installFabric } from '@symbiote-native/test-utils';
9
- import type { IPedometerResult } from '../../../core';
10
- import { usePedometer } from './index';
11
-
12
- const ROOT_TAG = 9822;
13
-
14
- type IListener = (result: IPedometerResult) => void;
15
-
16
- let registeredListener: IListener | undefined;
17
- const removeMock = vi.fn();
18
- const watchStepCountMock = vi.fn((listener: IListener) => {
19
- registeredListener = listener;
20
- return { remove: removeMock };
21
- });
22
-
23
- vi.mock('../../../core', () => ({
24
- watchStepCount: (listener: IListener) => watchStepCountMock(listener),
25
- }));
26
-
27
- const fabric = installFabric();
28
-
29
- beforeEach(() => {
30
- fabric.reset();
31
- registeredListener = undefined;
32
- watchStepCountMock.mockClear();
33
- removeMock.mockClear();
34
- });
35
-
36
- afterEach(() => unmount(ROOT_TAG));
37
-
38
- function mountPedometer(): Ref<IPedometerResult | null> {
39
- let result: Ref<IPedometerResult | null> | undefined;
40
- mount(
41
- ROOT_TAG,
42
- defineComponent({
43
- setup: () => {
44
- result = usePedometer();
45
- return () => h('symbiote-text', {}, 'pedometer');
46
- },
47
- }),
48
- );
49
- if (result === undefined) {
50
- throw new Error('setup() did not run');
51
- }
52
- return result;
53
- }
54
-
55
- describe('usePedometer (Vue)', () => {
56
- it('starts null before any step count arrives', () => {
57
- const result = mountPedometer();
58
-
59
- expect(result.value).toBeNull();
60
- });
61
-
62
- it('updates the ref when the native listener fires', () => {
63
- const result = mountPedometer();
64
- const reading: IPedometerResult = { steps: 456 };
65
-
66
- registeredListener?.(reading);
67
-
68
- expect(result.value).toEqual(reading);
69
- });
70
-
71
- it('removes the subscription on unmount', () => {
72
- mountPedometer();
73
- unmount(ROOT_TAG);
74
-
75
- expect(removeMock).toHaveBeenCalledTimes(1);
76
- });
77
- });