@askjo/camofox-browser 1.5.2 → 1.6.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,117 @@
1
+ /**
2
+ * Tests for scripts/plugin.js — plugin install, remove, list.
3
+ */
4
+
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import { execSync } from 'child_process';
8
+ import { fileURLToPath } from 'url';
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
+ const ROOT = path.join(__dirname, '..');
12
+ const SCRIPT = path.join(ROOT, 'scripts', 'plugin.js');
13
+ const PLUGINS_DIR = path.join(ROOT, 'plugins');
14
+ const CONFIG_PATH = path.join(ROOT, 'camofox.config.json');
15
+
16
+ const run = (args) => execSync(`node ${SCRIPT} ${args}`, { cwd: ROOT, encoding: 'utf-8' });
17
+
18
+ // Save/restore config around tests
19
+ let originalConfig;
20
+ beforeAll(() => { originalConfig = fs.readFileSync(CONFIG_PATH, 'utf-8'); });
21
+ afterAll(() => { fs.writeFileSync(CONFIG_PATH, originalConfig); });
22
+
23
+ // Clean up test plugins after each test
24
+ afterEach(() => {
25
+ const testDir = path.join(PLUGINS_DIR, 'test-plugin');
26
+ if (fs.existsSync(testDir)) fs.rmSync(testDir, { recursive: true });
27
+ // Restore config
28
+ fs.writeFileSync(CONFIG_PATH, originalConfig);
29
+ });
30
+
31
+ describe('plugin list', () => {
32
+ test('lists youtube as enabled', () => {
33
+ const out = run('list');
34
+ expect(out).toContain('youtube');
35
+ expect(out).toContain('✓');
36
+ });
37
+ });
38
+
39
+ describe('plugin install (local)', () => {
40
+ const tmpDir = path.join(ROOT, '.tmp-test-plugin');
41
+
42
+ beforeEach(() => {
43
+ fs.mkdirSync(tmpDir, { recursive: true });
44
+ fs.writeFileSync(path.join(tmpDir, 'index.js'),
45
+ 'export function register(app, ctx) { app.get("/test", (req, res) => res.json({})); }');
46
+ });
47
+
48
+ afterEach(() => {
49
+ if (fs.existsSync(tmpDir)) fs.rmSync(tmpDir, { recursive: true });
50
+ const installed = path.join(PLUGINS_DIR, '.tmp-test-plugin');
51
+ if (fs.existsSync(installed)) fs.rmSync(installed, { recursive: true });
52
+ });
53
+
54
+ test('copies plugin dir and updates config', () => {
55
+ const out = run(`install ${tmpDir}`);
56
+ expect(out).toContain('Installed');
57
+
58
+ // Plugin dir exists
59
+ const installed = path.join(PLUGINS_DIR, '.tmp-test-plugin');
60
+ expect(fs.existsSync(installed)).toBe(true);
61
+ expect(fs.existsSync(path.join(installed, 'index.js'))).toBe(true);
62
+
63
+ // Config updated
64
+ const config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
65
+ if (Array.isArray(config.plugins)) {
66
+ expect(config.plugins).toContain('.tmp-test-plugin');
67
+ } else {
68
+ expect(config.plugins['.tmp-test-plugin']).toBeDefined();
69
+ }
70
+ });
71
+
72
+ test('rejects duplicate install', () => {
73
+ run(`install ${tmpDir}`);
74
+ expect(() => run(`install ${tmpDir}`)).toThrow();
75
+ });
76
+ });
77
+
78
+ describe('plugin remove', () => {
79
+ const tmpDir = path.join(ROOT, '.tmp-test-plugin-rm');
80
+
81
+ beforeEach(() => {
82
+ fs.mkdirSync(tmpDir, { recursive: true });
83
+ fs.writeFileSync(path.join(tmpDir, 'index.js'),
84
+ 'export function register(app, ctx) {}');
85
+ run(`install ${tmpDir}`);
86
+ });
87
+
88
+ afterEach(() => {
89
+ if (fs.existsSync(tmpDir)) fs.rmSync(tmpDir, { recursive: true });
90
+ const installed = path.join(PLUGINS_DIR, '.tmp-test-plugin-rm');
91
+ if (fs.existsSync(installed)) fs.rmSync(installed, { recursive: true });
92
+ });
93
+
94
+ test('removes plugin dir and config entry', () => {
95
+ const out = run('remove .tmp-test-plugin-rm');
96
+ expect(out).toContain('Removed');
97
+
98
+ const installed = path.join(PLUGINS_DIR, '.tmp-test-plugin-rm');
99
+ expect(fs.existsSync(installed)).toBe(false);
100
+
101
+ const config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
102
+ expect(config.plugins).not.toContain('.tmp-test-plugin-rm');
103
+ });
104
+
105
+ test('errors on unknown plugin', () => {
106
+ expect(() => run('remove nonexistent-plugin-xyz')).toThrow();
107
+ });
108
+ });
109
+
110
+ describe('plugin help', () => {
111
+ test('shows usage with no args', () => {
112
+ const out = run('');
113
+ expect(out).toContain('Usage');
114
+ expect(out).toContain('install');
115
+ expect(out).toContain('remove');
116
+ });
117
+ });