@myerscarpenter/quest-dev 1.2.0 → 1.3.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/README.md +65 -1
- package/build/commands/battery.js +3 -3
- package/build/commands/battery.js.map +1 -1
- package/build/commands/logcat.d.ts.map +1 -1
- package/build/commands/logcat.js +8 -6
- package/build/commands/logcat.js.map +1 -1
- package/build/commands/stay-awake.d.ts +31 -4
- package/build/commands/stay-awake.d.ts.map +1 -1
- package/build/commands/stay-awake.js +160 -83
- package/build/commands/stay-awake.js.map +1 -1
- package/build/index.js +44 -12
- package/build/index.js.map +1 -1
- package/build/utils/adb.d.ts +10 -3
- package/build/utils/adb.d.ts.map +1 -1
- package/build/utils/adb.js +10 -13
- package/build/utils/adb.js.map +1 -1
- package/build/utils/config.d.ts +19 -0
- package/build/utils/config.d.ts.map +1 -0
- package/build/utils/config.js +59 -0
- package/build/utils/config.js.map +1 -0
- package/build/utils/exec.d.ts.map +1 -1
- package/build/utils/exec.js +0 -2
- package/build/utils/exec.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/battery.ts +3 -3
- package/src/commands/logcat.ts +7 -5
- package/src/commands/stay-awake.ts +184 -96
- package/src/index.ts +49 -14
- package/src/utils/adb.ts +17 -13
- package/src/utils/config.ts +66 -0
- package/src/utils/exec.ts +0 -2
- package/tests/config.test.ts +88 -0
- package/tests/exec.test.ts +3 -3
- package/tests/stay-awake.test.ts +71 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { loadConfig, loadPin } from '../src/utils/config.js';
|
|
4
|
+
|
|
5
|
+
vi.mock('fs');
|
|
6
|
+
|
|
7
|
+
const mockReadFileSync = vi.mocked(fs.readFileSync);
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
vi.resetAllMocks();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('loadConfig', () => {
|
|
14
|
+
it('returns empty object when no config files exist', () => {
|
|
15
|
+
mockReadFileSync.mockImplementation(() => {
|
|
16
|
+
throw new Error('ENOENT');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const config = loadConfig();
|
|
20
|
+
expect(config).toEqual({});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('reads .quest-dev.json from cwd when present', () => {
|
|
24
|
+
mockReadFileSync.mockImplementation((path) => {
|
|
25
|
+
if (String(path).endsWith('.quest-dev.json')) {
|
|
26
|
+
return JSON.stringify({ pin: '1234' });
|
|
27
|
+
}
|
|
28
|
+
throw new Error('ENOENT');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const config = loadConfig();
|
|
32
|
+
expect(config.pin).toBe('1234');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('merges configs: local file wins over global file', () => {
|
|
36
|
+
mockReadFileSync.mockImplementation((path) => {
|
|
37
|
+
if (String(path).endsWith('.quest-dev.json')) {
|
|
38
|
+
return JSON.stringify({ pin: 'local-pin', idleTimeout: 5000 });
|
|
39
|
+
}
|
|
40
|
+
if (String(path).endsWith('config.json')) {
|
|
41
|
+
return JSON.stringify({ pin: 'global-pin', lowBattery: 15 });
|
|
42
|
+
}
|
|
43
|
+
throw new Error('ENOENT');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const config = loadConfig();
|
|
47
|
+
expect(config.pin).toBe('local-pin');
|
|
48
|
+
expect(config.idleTimeout).toBe(5000);
|
|
49
|
+
expect(config.lowBattery).toBe(15);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('loadPin', () => {
|
|
54
|
+
it('returns CLI pin when provided', () => {
|
|
55
|
+
// Should not even read config files
|
|
56
|
+
const pin = loadPin('cli-pin');
|
|
57
|
+
expect(pin).toBe('cli-pin');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('falls back to config file pin', () => {
|
|
61
|
+
mockReadFileSync.mockImplementation((path) => {
|
|
62
|
+
if (String(path).endsWith('.quest-dev.json')) {
|
|
63
|
+
return JSON.stringify({ pin: 'config-pin' });
|
|
64
|
+
}
|
|
65
|
+
throw new Error('ENOENT');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const pin = loadPin();
|
|
69
|
+
expect(pin).toBe('config-pin');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('exits with error when no pin found', () => {
|
|
73
|
+
mockReadFileSync.mockImplementation(() => {
|
|
74
|
+
throw new Error('ENOENT');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
|
|
78
|
+
throw new Error('process.exit');
|
|
79
|
+
});
|
|
80
|
+
const mockError = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
81
|
+
|
|
82
|
+
expect(() => loadPin()).toThrow('process.exit');
|
|
83
|
+
expect(mockExit).toHaveBeenCalledWith(1);
|
|
84
|
+
|
|
85
|
+
mockExit.mockRestore();
|
|
86
|
+
mockError.mockRestore();
|
|
87
|
+
});
|
|
88
|
+
});
|
package/tests/exec.test.ts
CHANGED
|
@@ -8,7 +8,7 @@ describe('execCommand', () => {
|
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
it('should reject on non-zero exit code', async () => {
|
|
11
|
-
await expect(execCommand('sh -c
|
|
11
|
+
await expect(execCommand('sh', ['-c', 'exit 1'])).rejects.toThrow();
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it('should handle shell commands', async () => {
|
|
@@ -25,12 +25,12 @@ describe('execCommandFull', () => {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
it('should return non-zero exit code without throwing', async () => {
|
|
28
|
-
const result = await execCommandFull('sh -c
|
|
28
|
+
const result = await execCommandFull('sh', ['-c', 'exit 42']);
|
|
29
29
|
expect(result.code).toBe(42);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
it('should capture stderr', async () => {
|
|
33
|
-
const result = await execCommandFull('sh -c
|
|
33
|
+
const result = await execCommandFull('sh', ['-c', 'echo error >&2']);
|
|
34
34
|
expect(result.stderr.trim()).toBe('error');
|
|
35
35
|
});
|
|
36
36
|
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { parseTestProperties, buildSetPropertyArgs } from '../src/commands/stay-awake.js';
|
|
3
|
+
|
|
4
|
+
describe('parseTestProperties', () => {
|
|
5
|
+
it('parses a full Bundle output', () => {
|
|
6
|
+
const output = 'Bundle[{disable_guardian=true, set_proximity_close=true, disable_dialogs=true, disable_autosleep=true}]';
|
|
7
|
+
const props = parseTestProperties(output);
|
|
8
|
+
expect(props).toEqual({
|
|
9
|
+
disable_guardian: true,
|
|
10
|
+
set_proximity_close: true,
|
|
11
|
+
disable_dialogs: true,
|
|
12
|
+
disable_autosleep: true,
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('parses Bundle with false values', () => {
|
|
17
|
+
const output = 'Bundle[{disable_guardian=false, set_proximity_close=false, disable_dialogs=false, disable_autosleep=false}]';
|
|
18
|
+
const props = parseTestProperties(output);
|
|
19
|
+
expect(props).toEqual({
|
|
20
|
+
disable_guardian: false,
|
|
21
|
+
set_proximity_close: false,
|
|
22
|
+
disable_dialogs: false,
|
|
23
|
+
disable_autosleep: false,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('returns defaults for unparseable output', () => {
|
|
28
|
+
const props = parseTestProperties('some garbage output');
|
|
29
|
+
expect(props).toEqual({
|
|
30
|
+
disable_guardian: false,
|
|
31
|
+
set_proximity_close: false,
|
|
32
|
+
disable_dialogs: false,
|
|
33
|
+
disable_autosleep: false,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('returns defaults for empty string', () => {
|
|
38
|
+
const props = parseTestProperties('');
|
|
39
|
+
expect(props).toEqual({
|
|
40
|
+
disable_guardian: false,
|
|
41
|
+
set_proximity_close: false,
|
|
42
|
+
disable_dialogs: false,
|
|
43
|
+
disable_autosleep: false,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('buildSetPropertyArgs', () => {
|
|
49
|
+
it('builds enable args with correct PIN', () => {
|
|
50
|
+
const args = buildSetPropertyArgs('5678', true);
|
|
51
|
+
expect(args).toEqual([
|
|
52
|
+
'shell', 'content', 'call',
|
|
53
|
+
'--uri', 'content://com.oculus.rc',
|
|
54
|
+
'--method', 'SET_PROPERTY',
|
|
55
|
+
'--extra', 'disable_guardian:b:true',
|
|
56
|
+
'--extra', 'disable_dialogs:b:true',
|
|
57
|
+
'--extra', 'disable_autosleep:b:true',
|
|
58
|
+
'--extra', 'set_proximity_close:b:true',
|
|
59
|
+
'--extra', 'PIN:s:5678',
|
|
60
|
+
]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('builds disable args', () => {
|
|
64
|
+
const args = buildSetPropertyArgs('1234', false);
|
|
65
|
+
expect(args).toContain('disable_guardian:b:false');
|
|
66
|
+
expect(args).toContain('disable_dialogs:b:false');
|
|
67
|
+
expect(args).toContain('disable_autosleep:b:false');
|
|
68
|
+
expect(args).toContain('set_proximity_close:b:false');
|
|
69
|
+
expect(args).toContain('PIN:s:1234');
|
|
70
|
+
});
|
|
71
|
+
});
|