@symbiote-native/keep-awake 0.0.1 → 0.1.0
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/build/angular/index.js +2 -2
- package/build/angular/services/keep-awake.service/index.js +1 -1
- package/build/core/index.js +1 -1
- package/build/core/keep-awake.js +1 -1
- package/build/react/hooks/use-keep-awake/index.js +1 -1
- package/build/react/index.js +2 -2
- package/build/vue/composables/use-keep-awake/index.js +1 -1
- package/build/vue/index.js +2 -2
- package/package.json +8 -5
- package/src/angular/services/keep-awake.service/keep-awake.service.test.ts +0 -98
- package/src/core/keep-awake.test.ts +0 -119
- package/src/react/hooks/use-keep-awake/use-keep-awake.test.tsx +0 -70
- package/src/vue/composables/use-keep-awake/use-keep-awake.test.ts +0 -76
package/build/angular/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// KeepAwakeService is the Angular-only lifecycle half; the free functions and event
|
|
2
2
|
// subscription plumbing all live in core, shared with React/Vue.
|
|
3
|
-
export { KeepAwakeService } from './services/keep-awake.service';
|
|
4
|
-
export { ExpoKeepAwakeTag, isAvailableAsync, activateKeepAwakeAsync, deactivateKeepAwake, addListener, } from '../core';
|
|
3
|
+
export { KeepAwakeService } from './services/keep-awake.service/index.js';
|
|
4
|
+
export { ExpoKeepAwakeTag, isAvailableAsync, activateKeepAwakeAsync, deactivateKeepAwake, addListener, } from '../core/index.js';
|
|
@@ -33,7 +33,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
33
33
|
return useValue ? value : void 0;
|
|
34
34
|
};
|
|
35
35
|
import { effect, inject, Injectable, Injector } from '@angular/core';
|
|
36
|
-
import { activateKeepAwakeAsync, addListener, deactivateKeepAwake, } from '../../../core';
|
|
36
|
+
import { activateKeepAwakeAsync, addListener, deactivateKeepAwake, } from '../../../core/index.js';
|
|
37
37
|
// Angular twin of React's `useKeepAwake` hook and Vue's `useKeepAwake` composable. See
|
|
38
38
|
// LowPowerModeService (packages/battery) for the `connect()`/`effect()` pattern rationale — same
|
|
39
39
|
// wiring, but keep-awake has no value to surface as a Signal since it's a pure side effect for
|
package/build/core/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ExpoKeepAwakeTag, isAvailableAsync, activateKeepAwakeAsync, deactivateKeepAwake, addListener, } from './keep-awake';
|
|
1
|
+
export { ExpoKeepAwakeTag, isAvailableAsync, activateKeepAwakeAsync, deactivateKeepAwake, addListener, } from './keep-awake.js';
|
package/build/core/keep-awake.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// upstream keep-awake throws from `addListener` when the native module lacks
|
|
5
5
|
// `addListenerForTag`, matching local-auth/haptics's UnavailabilityError convention.
|
|
6
6
|
import { UnavailabilityError } from 'expo-modules-core';
|
|
7
|
-
import { expoKeepAwake } from './native-module';
|
|
7
|
+
import { expoKeepAwake } from './native-module.js';
|
|
8
8
|
export const ExpoKeepAwakeTag = 'ExpoKeepAwakeDefaultTag';
|
|
9
9
|
/** Resolves with whether the keep-awake API is available on this device. */
|
|
10
10
|
export async function isAvailableAsync() {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// UnavailabilityError from `addListener` is swallowed by the trailing `.catch(() => {})` exactly
|
|
10
10
|
// like a rejected `activateKeepAwakeAsync`, same net effect as upstream's own guard.
|
|
11
11
|
import { useEffect, useId } from 'react';
|
|
12
|
-
import { activateKeepAwakeAsync, addListener, deactivateKeepAwake, } from '../../../core';
|
|
12
|
+
import { activateKeepAwakeAsync, addListener, deactivateKeepAwake, } from '../../../core/index.js';
|
|
13
13
|
export function useKeepAwake(tag, options) {
|
|
14
14
|
const defaultTag = useId();
|
|
15
15
|
const tagOrDefault = tag ?? defaultTag;
|
package/build/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @symbiote-native/keep-awake/react: the React entry over the framework-agnostic core. The
|
|
2
2
|
// lifecycle bucket is `hooks/` (never `composables/`, that's Vue's term) — see
|
|
3
3
|
// adapters/react/src/hooks for the same convention.
|
|
4
|
-
export { useKeepAwake } from './hooks/use-keep-awake';
|
|
5
|
-
export { ExpoKeepAwakeTag, isAvailableAsync, activateKeepAwakeAsync, deactivateKeepAwake, addListener, } from '../core';
|
|
4
|
+
export { useKeepAwake } from './hooks/use-keep-awake/index.js';
|
|
5
|
+
export { ExpoKeepAwakeTag, isAvailableAsync, activateKeepAwakeAsync, deactivateKeepAwake, addListener, } from '../core/index.js';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// counter instead — simplest robust way to give each composable instance its own tag when the
|
|
5
5
|
// caller doesn't supply one.
|
|
6
6
|
import { onMounted, onUnmounted } from '@vue/runtime-core';
|
|
7
|
-
import { activateKeepAwakeAsync, addListener, deactivateKeepAwake, } from '../../../core';
|
|
7
|
+
import { activateKeepAwakeAsync, addListener, deactivateKeepAwake, } from '../../../core/index.js';
|
|
8
8
|
let tagCounter = 0;
|
|
9
9
|
export function useKeepAwake(tag, options) {
|
|
10
10
|
const tagOrDefault = tag ?? `keep-awake-tag-${++tagCounter}`;
|
package/build/vue/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @symbiote-native/keep-awake/vue: the Vue entry over the framework-agnostic core. The
|
|
2
2
|
// lifecycle bucket is `composables/` (never `hooks/`, that's React's term) — see
|
|
3
3
|
// adapters/vue/src/composables for the same convention.
|
|
4
|
-
export { useKeepAwake } from './composables/use-keep-awake';
|
|
5
|
-
export { ExpoKeepAwakeTag, isAvailableAsync, activateKeepAwakeAsync, deactivateKeepAwake, addListener, } from '../core';
|
|
4
|
+
export { useKeepAwake } from './composables/use-keep-awake/index.js';
|
|
5
|
+
export { ExpoKeepAwakeTag, isAvailableAsync, activateKeepAwakeAsync, deactivateKeepAwake, addListener, } from '../core/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbiote-native/keep-awake",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "expo-keep-awake wrapped for SymbioteNative — one framework-agnostic core, built once and reachable from the React, Vue, and Angular adapters. Keeps the screen awake for the lifetime of a mounted component/composable/service, with an optional listener for keep-awake state changes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,7 +40,10 @@
|
|
|
40
40
|
"src",
|
|
41
41
|
"build",
|
|
42
42
|
"build-ngc",
|
|
43
|
-
"native-link.json"
|
|
43
|
+
"native-link.json",
|
|
44
|
+
"!src/**/*.test.*",
|
|
45
|
+
"!src/**/*.spec.*",
|
|
46
|
+
"!src/**/*.detox.*"
|
|
44
47
|
],
|
|
45
48
|
"publishConfig": {
|
|
46
49
|
"access": "public"
|
|
@@ -56,7 +59,7 @@
|
|
|
56
59
|
"react": ">=19.0.0",
|
|
57
60
|
"react-native": ">=0.86",
|
|
58
61
|
"vue": ">=3.5.0",
|
|
59
|
-
"@symbiote-native/angular": "0.6.
|
|
62
|
+
"@symbiote-native/angular": "0.6.2",
|
|
60
63
|
"@symbiote-native/react": "0.2.8",
|
|
61
64
|
"@symbiote-native/vue": "0.3.8"
|
|
62
65
|
},
|
|
@@ -92,10 +95,10 @@
|
|
|
92
95
|
"@vue/runtime-core": "^3.5.13",
|
|
93
96
|
"react": "19.2.3",
|
|
94
97
|
"typescript": "~6.0.0",
|
|
95
|
-
"@symbiote-native/
|
|
98
|
+
"@symbiote-native/angular": "0.6.2",
|
|
96
99
|
"@symbiote-native/engine": "0.1.7",
|
|
97
100
|
"@symbiote-native/react": "0.2.8",
|
|
98
|
-
"@symbiote-native/
|
|
101
|
+
"@symbiote-native/test-utils": "0.1.6",
|
|
99
102
|
"@symbiote-native/vue": "0.3.8"
|
|
100
103
|
},
|
|
101
104
|
"scripts": {
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// Co-located Angular-driven test (ADR 0025) for KeepAwakeService. See battery's
|
|
2
|
-
// low-power-mode.service.test.ts for the shared rationale.
|
|
3
|
-
//
|
|
4
|
-
// Two host classes rather than one @Input-driven host: Angular sets @Input-bound properties
|
|
5
|
-
// AFTER construction, so a constructor-time `connect(this.tag)` read off an @Input would always
|
|
6
|
-
// see `undefined` — the same field-initializer/constructor timing every other service host in
|
|
7
|
-
// this repo relies on (see battery's own PermissionsHost/BatteryLevelHost).
|
|
8
|
-
|
|
9
|
-
import '@angular/compiler';
|
|
10
|
-
import { Component, inject } from '@angular/core';
|
|
11
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
12
|
-
import { mount, unmount } from '@symbiote-native/angular';
|
|
13
|
-
import { installFabric } from '@symbiote-native/test-utils';
|
|
14
|
-
import { KeepAwakeService } from './index';
|
|
15
|
-
|
|
16
|
-
const activateKeepAwakeAsyncMock = vi.fn(async (_tag: string) => undefined);
|
|
17
|
-
const addListenerMock = vi.fn();
|
|
18
|
-
const deactivateKeepAwakeMock = vi.fn(async (_tag: string) => undefined);
|
|
19
|
-
|
|
20
|
-
vi.mock('../../../core', () => ({
|
|
21
|
-
activateKeepAwakeAsync: (tag: string) => activateKeepAwakeAsyncMock(tag),
|
|
22
|
-
addListener: (...args: unknown[]) => addListenerMock(...args),
|
|
23
|
-
deactivateKeepAwake: (tag: string) => deactivateKeepAwakeMock(tag),
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
const ROOT_TAG = 974;
|
|
27
|
-
const fabric = installFabric();
|
|
28
|
-
const tick = (): Promise<void> => new Promise(resolve => setTimeout(resolve, 0));
|
|
29
|
-
|
|
30
|
-
@Component({
|
|
31
|
-
selector: 'symbiote-keep-awake-default-host',
|
|
32
|
-
standalone: true,
|
|
33
|
-
template: '',
|
|
34
|
-
})
|
|
35
|
-
class KeepAwakeDefaultHost {
|
|
36
|
-
constructor() {
|
|
37
|
-
inject(KeepAwakeService).connect();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@Component({
|
|
42
|
-
selector: 'symbiote-keep-awake-custom-host',
|
|
43
|
-
standalone: true,
|
|
44
|
-
template: '',
|
|
45
|
-
})
|
|
46
|
-
class KeepAwakeCustomHost {
|
|
47
|
-
constructor() {
|
|
48
|
-
inject(KeepAwakeService).connect('custom-tag');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
activateKeepAwakeAsyncMock.mockClear();
|
|
54
|
-
addListenerMock.mockClear();
|
|
55
|
-
deactivateKeepAwakeMock.mockClear();
|
|
56
|
-
activateKeepAwakeAsyncMock.mockResolvedValue(undefined);
|
|
57
|
-
deactivateKeepAwakeMock.mockResolvedValue(undefined);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
afterEach(() => {
|
|
61
|
-
unmount(ROOT_TAG);
|
|
62
|
-
fabric.reset();
|
|
63
|
-
vi.clearAllMocks();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('KeepAwakeService.connect', () => {
|
|
67
|
-
it('activates a default tag on mount', async () => {
|
|
68
|
-
mount(ROOT_TAG, KeepAwakeDefaultHost);
|
|
69
|
-
await tick();
|
|
70
|
-
|
|
71
|
-
expect(activateKeepAwakeAsyncMock).toHaveBeenCalledTimes(1);
|
|
72
|
-
expect(typeof activateKeepAwakeAsyncMock.mock.calls[0][0]).toBe('string');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('activates the explicit tag when one is given', async () => {
|
|
76
|
-
mount(ROOT_TAG, KeepAwakeCustomHost);
|
|
77
|
-
await tick();
|
|
78
|
-
|
|
79
|
-
expect(activateKeepAwakeAsyncMock).toHaveBeenCalledWith('custom-tag');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('deactivates the same tag when the host component is unmounted', async () => {
|
|
83
|
-
mount(ROOT_TAG, KeepAwakeCustomHost);
|
|
84
|
-
await tick();
|
|
85
|
-
|
|
86
|
-
unmount(ROOT_TAG);
|
|
87
|
-
await tick();
|
|
88
|
-
|
|
89
|
-
expect(deactivateKeepAwakeMock).toHaveBeenCalledWith('custom-tag');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('never touches addListener when no options are given', async () => {
|
|
93
|
-
mount(ROOT_TAG, KeepAwakeCustomHost);
|
|
94
|
-
await tick();
|
|
95
|
-
|
|
96
|
-
expect(addListenerMock).not.toHaveBeenCalled();
|
|
97
|
-
});
|
|
98
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
const FAKE_NATIVE_KEEP_AWAKE = {
|
|
4
|
-
isAvailableAsync: vi.fn(async () => true),
|
|
5
|
-
activate: vi.fn(async () => undefined),
|
|
6
|
-
deactivate: vi.fn(async () => undefined),
|
|
7
|
-
addListenerForTag: vi.fn(() => ({ remove: vi.fn() })),
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// The real ExpoKeepAwake native module only exists on device — resolving it via
|
|
11
|
-
// requireNativeModule() at import time would throw in this headless test run, so the
|
|
12
|
-
// module-lookup file is faked in place of expo-modules-core's runtime resolution, same pattern
|
|
13
|
-
// packages/battery/src/core/battery.test.ts uses.
|
|
14
|
-
vi.mock('./native-module', () => ({
|
|
15
|
-
expoKeepAwake: FAKE_NATIVE_KEEP_AWAKE,
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
// expo-modules-core's real entry transitively imports 'react-native' for Platform/
|
|
19
|
-
// TurboModuleRegistry, whose Flow-typed source Vitest's Oxc transform can't parse — same fake
|
|
20
|
-
// packages/haptics/src/core/haptics.test.ts uses. keep-awake.ts imports UnavailabilityError as a
|
|
21
|
-
// real value (not just a type), so it needs mocking here too.
|
|
22
|
-
vi.mock('expo-modules-core', () => ({
|
|
23
|
-
UnavailabilityError: class UnavailabilityError extends Error {
|
|
24
|
-
constructor(moduleName: string, propertyName: string) {
|
|
25
|
-
super(`${propertyName} is not available on ${moduleName}`);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
const {
|
|
31
|
-
ExpoKeepAwakeTag,
|
|
32
|
-
isAvailableAsync,
|
|
33
|
-
activateKeepAwakeAsync,
|
|
34
|
-
deactivateKeepAwake,
|
|
35
|
-
addListener,
|
|
36
|
-
} = await import('./keep-awake');
|
|
37
|
-
|
|
38
|
-
afterEach(() => {
|
|
39
|
-
vi.clearAllMocks();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('isAvailableAsync', () => {
|
|
43
|
-
it('delegates to the native module when isAvailableAsync exists', async () => {
|
|
44
|
-
await expect(isAvailableAsync()).resolves.toBe(true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('defaults to true when the native method is absent', async () => {
|
|
48
|
-
const { isAvailableAsync: native } = FAKE_NATIVE_KEEP_AWAKE;
|
|
49
|
-
// @ts-expect-error -- simulating a platform where the native module has no such method
|
|
50
|
-
FAKE_NATIVE_KEEP_AWAKE.isAvailableAsync = undefined;
|
|
51
|
-
|
|
52
|
-
await expect(isAvailableAsync()).resolves.toBe(true);
|
|
53
|
-
|
|
54
|
-
FAKE_NATIVE_KEEP_AWAKE.isAvailableAsync = native;
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('activateKeepAwakeAsync', () => {
|
|
59
|
-
it('activates the default tag when none is given', async () => {
|
|
60
|
-
await activateKeepAwakeAsync();
|
|
61
|
-
|
|
62
|
-
expect(FAKE_NATIVE_KEEP_AWAKE.activate).toHaveBeenCalledWith(ExpoKeepAwakeTag);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('activates an explicit tag', async () => {
|
|
66
|
-
await activateKeepAwakeAsync('custom-tag');
|
|
67
|
-
|
|
68
|
-
expect(FAKE_NATIVE_KEEP_AWAKE.activate).toHaveBeenCalledWith('custom-tag');
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('deactivateKeepAwake', () => {
|
|
73
|
-
it('deactivates the default tag when none is given', async () => {
|
|
74
|
-
await deactivateKeepAwake();
|
|
75
|
-
|
|
76
|
-
expect(FAKE_NATIVE_KEEP_AWAKE.deactivate).toHaveBeenCalledWith(ExpoKeepAwakeTag);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('deactivates an explicit tag', async () => {
|
|
80
|
-
await deactivateKeepAwake('custom-tag');
|
|
81
|
-
|
|
82
|
-
expect(FAKE_NATIVE_KEEP_AWAKE.deactivate).toHaveBeenCalledWith('custom-tag');
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('addListener', () => {
|
|
87
|
-
it('subscribes the default tag when called with a bare listener', () => {
|
|
88
|
-
const listener = vi.fn();
|
|
89
|
-
addListener(listener);
|
|
90
|
-
|
|
91
|
-
expect(FAKE_NATIVE_KEEP_AWAKE.addListenerForTag).toHaveBeenCalledWith(
|
|
92
|
-
ExpoKeepAwakeTag,
|
|
93
|
-
listener,
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('subscribes an explicit tag when given tag + listener', () => {
|
|
98
|
-
const listener = vi.fn();
|
|
99
|
-
addListener('custom-tag', listener);
|
|
100
|
-
|
|
101
|
-
expect(FAKE_NATIVE_KEEP_AWAKE.addListenerForTag).toHaveBeenCalledWith('custom-tag', listener);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('throws an UnavailabilityError-shaped error when addListenerForTag is absent', () => {
|
|
105
|
-
const { addListenerForTag: native } = FAKE_NATIVE_KEEP_AWAKE;
|
|
106
|
-
// @ts-expect-error -- simulating a platform where the native module has no such method
|
|
107
|
-
FAKE_NATIVE_KEEP_AWAKE.addListenerForTag = undefined;
|
|
108
|
-
|
|
109
|
-
expect(() => addListener(vi.fn())).toThrow(
|
|
110
|
-
'addListenerForTag is not available on ExpoKeepAwake',
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
FAKE_NATIVE_KEEP_AWAKE.addListenerForTag = native;
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('throws when no listener can be resolved', () => {
|
|
117
|
-
expect(() => addListener('custom-tag')).toThrow('addListener requires a listener function');
|
|
118
|
-
});
|
|
119
|
-
});
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// Co-located React-driven test (ADR 0025) for useKeepAwake. See battery's
|
|
2
|
-
// use-low-power-mode.test.tsx for the shared rationale (mocks `core`, not expo-modules-core
|
|
3
|
-
// internals).
|
|
4
|
-
|
|
5
|
-
import { createElement, type ReactElement } from 'react';
|
|
6
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
7
|
-
import { mount, unmount, View } from '@symbiote-native/react';
|
|
8
|
-
import { installFabric } from '@symbiote-native/test-utils';
|
|
9
|
-
import { useKeepAwake } from './index';
|
|
10
|
-
|
|
11
|
-
const { activateKeepAwakeAsync, addListener, deactivateKeepAwake } = vi.hoisted(() => ({
|
|
12
|
-
activateKeepAwakeAsync: vi.fn(async (_tag: string) => undefined),
|
|
13
|
-
addListener: vi.fn(),
|
|
14
|
-
deactivateKeepAwake: vi.fn(async (_tag: string) => undefined),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
vi.mock('../../../core', () => ({
|
|
18
|
-
activateKeepAwakeAsync,
|
|
19
|
-
addListener,
|
|
20
|
-
deactivateKeepAwake,
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
const ROOT_TAG = 954;
|
|
24
|
-
|
|
25
|
-
function Probe({ tag }: { tag?: string }): ReactElement {
|
|
26
|
-
useKeepAwake(tag);
|
|
27
|
-
return createElement(View);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const fabric = installFabric();
|
|
31
|
-
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
fabric.reset();
|
|
34
|
-
vi.clearAllMocks();
|
|
35
|
-
activateKeepAwakeAsync.mockResolvedValue(undefined);
|
|
36
|
-
deactivateKeepAwake.mockResolvedValue(undefined);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
afterEach(() => unmount(ROOT_TAG));
|
|
40
|
-
|
|
41
|
-
describe('useKeepAwake', () => {
|
|
42
|
-
it('activates a default tag on mount', async () => {
|
|
43
|
-
mount(ROOT_TAG, createElement(Probe));
|
|
44
|
-
|
|
45
|
-
await vi.waitFor(() => expect(activateKeepAwakeAsync).toHaveBeenCalledTimes(1));
|
|
46
|
-
expect(typeof activateKeepAwakeAsync.mock.calls[0][0]).toBe('string');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('activates the explicit tag when one is given', async () => {
|
|
50
|
-
mount(ROOT_TAG, createElement(Probe, { tag: 'custom-tag' }));
|
|
51
|
-
|
|
52
|
-
await vi.waitFor(() => expect(activateKeepAwakeAsync).toHaveBeenCalledWith('custom-tag'));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('deactivates the same tag on unmount', async () => {
|
|
56
|
-
mount(ROOT_TAG, createElement(Probe, { tag: 'custom-tag' }));
|
|
57
|
-
await vi.waitFor(() => expect(activateKeepAwakeAsync).toHaveBeenCalledTimes(1));
|
|
58
|
-
|
|
59
|
-
unmount(ROOT_TAG);
|
|
60
|
-
|
|
61
|
-
expect(deactivateKeepAwake).toHaveBeenCalledWith('custom-tag');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('never touches addListener when no options are given', async () => {
|
|
65
|
-
mount(ROOT_TAG, createElement(Probe, { tag: 'custom-tag' }));
|
|
66
|
-
|
|
67
|
-
await vi.waitFor(() => expect(activateKeepAwakeAsync).toHaveBeenCalledTimes(1));
|
|
68
|
-
expect(addListener).not.toHaveBeenCalled();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// Co-located Vue-driven test (ADR 0025) for useKeepAwake. See battery's
|
|
2
|
-
// use-low-power-mode.test.ts for the shared rationale.
|
|
3
|
-
|
|
4
|
-
import { defineComponent, h } from '@vue/runtime-core';
|
|
5
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
-
import { mount, unmount } from '@symbiote-native/vue';
|
|
7
|
-
import { installFabric } from '@symbiote-native/test-utils';
|
|
8
|
-
import { useKeepAwake } from './index';
|
|
9
|
-
|
|
10
|
-
const ROOT_TAG = 9954;
|
|
11
|
-
|
|
12
|
-
const activateKeepAwakeAsyncMock = vi.fn(async (_tag: string) => undefined);
|
|
13
|
-
const addListenerMock = vi.fn();
|
|
14
|
-
const deactivateKeepAwakeMock = vi.fn(async (_tag: string) => undefined);
|
|
15
|
-
|
|
16
|
-
vi.mock('../../../core', () => ({
|
|
17
|
-
activateKeepAwakeAsync: (tag: string) => activateKeepAwakeAsyncMock(tag),
|
|
18
|
-
addListener: (...args: unknown[]) => addListenerMock(...args),
|
|
19
|
-
deactivateKeepAwake: (tag: string) => deactivateKeepAwakeMock(tag),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
const fabric = installFabric();
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
fabric.reset();
|
|
26
|
-
activateKeepAwakeAsyncMock.mockClear();
|
|
27
|
-
addListenerMock.mockClear();
|
|
28
|
-
deactivateKeepAwakeMock.mockClear();
|
|
29
|
-
activateKeepAwakeAsyncMock.mockResolvedValue(undefined);
|
|
30
|
-
deactivateKeepAwakeMock.mockResolvedValue(undefined);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
afterEach(() => unmount(ROOT_TAG));
|
|
34
|
-
|
|
35
|
-
function mountKeepAwake(tag?: string): void {
|
|
36
|
-
mount(
|
|
37
|
-
ROOT_TAG,
|
|
38
|
-
defineComponent({
|
|
39
|
-
setup: () => {
|
|
40
|
-
useKeepAwake(tag);
|
|
41
|
-
return () => h('symbiote-text', {}, 'keep-awake');
|
|
42
|
-
},
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
describe('useKeepAwake (Vue)', () => {
|
|
48
|
-
it('activates a default tag on mount', async () => {
|
|
49
|
-
mountKeepAwake();
|
|
50
|
-
|
|
51
|
-
await vi.waitFor(() => expect(activateKeepAwakeAsyncMock).toHaveBeenCalledTimes(1));
|
|
52
|
-
expect(typeof activateKeepAwakeAsyncMock.mock.calls[0][0]).toBe('string');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('activates the explicit tag when one is given', async () => {
|
|
56
|
-
mountKeepAwake('custom-tag');
|
|
57
|
-
|
|
58
|
-
await vi.waitFor(() => expect(activateKeepAwakeAsyncMock).toHaveBeenCalledWith('custom-tag'));
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('deactivates the same tag on unmount', async () => {
|
|
62
|
-
mountKeepAwake('custom-tag');
|
|
63
|
-
await vi.waitFor(() => expect(activateKeepAwakeAsyncMock).toHaveBeenCalledTimes(1));
|
|
64
|
-
|
|
65
|
-
unmount(ROOT_TAG);
|
|
66
|
-
|
|
67
|
-
expect(deactivateKeepAwakeMock).toHaveBeenCalledWith('custom-tag');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('never touches addListener when no options are given', async () => {
|
|
71
|
-
mountKeepAwake('custom-tag');
|
|
72
|
-
|
|
73
|
-
await vi.waitFor(() => expect(activateKeepAwakeAsyncMock).toHaveBeenCalledTimes(1));
|
|
74
|
-
expect(addListenerMock).not.toHaveBeenCalled();
|
|
75
|
-
});
|
|
76
|
-
});
|