@myerscarpenter/quest-dev 1.2.1 → 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.
@@ -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
+ });
@@ -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
+ });