@ever-works/screenshotone-plugin 1.0.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/LICENSE +661 -0
- package/README.md +79 -0
- package/package.json +82 -0
- package/src/__tests__/screenshotone.plugin.spec.ts +349 -0
- package/src/index.ts +2 -0
- package/src/screenshotone.plugin.ts +542 -0
- package/tsconfig.json +23 -0
- package/tsup.config.ts +12 -0
- package/vitest.config.ts +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @ever-works/screenshotone-plugin
|
|
2
|
+
|
|
3
|
+
ScreenshotOne screenshot plugin for Ever Works - capture website screenshots using the ScreenshotOne API
|
|
4
|
+
|
|
5
|
+
## Plugin metadata
|
|
6
|
+
|
|
7
|
+
| Field | Value |
|
|
8
|
+
| ------------ | --------------- |
|
|
9
|
+
| ID | `screenshotone` |
|
|
10
|
+
| Category | `screenshot` |
|
|
11
|
+
| Capabilities | `screenshot` |
|
|
12
|
+
| Author | Ever Works Team |
|
|
13
|
+
| License | AGPL-3.0 |
|
|
14
|
+
| Built-in | no |
|
|
15
|
+
| Auto-enable | no |
|
|
16
|
+
|
|
17
|
+
## What does ScreenshotOne do?
|
|
18
|
+
|
|
19
|
+
ScreenshotOne is a screenshot capture API. When work items include source URLs, this plugin automatically generates preview images by capturing a screenshot of each page.
|
|
20
|
+
|
|
21
|
+
## Why use it?
|
|
22
|
+
|
|
23
|
+
- **Automated capture** — preview images are generated for each work item without manual effort
|
|
24
|
+
- **Consistent output** — every screenshot uses the same viewport size, format, and rendering settings
|
|
25
|
+
- **Ad and tracker blocking** — captures clean screenshots free of ads and cookie banners
|
|
26
|
+
- **Multiple formats** — supports PNG, JPG, and WebP output with configurable resolution
|
|
27
|
+
|
|
28
|
+
## How it works in Ever Works
|
|
29
|
+
|
|
30
|
+
During work generation, the screenshot facade sends capture requests to ScreenshotOne for items that have a source URL. The resulting images are used as item preview thumbnails. You can configure viewport dimensions, image format, device scale factor, and caching behavior.
|
|
31
|
+
|
|
32
|
+
## Getting started
|
|
33
|
+
|
|
34
|
+
1. Sign up at [screenshotone.com](https://screenshotone.com)
|
|
35
|
+
2. Copy your access key and optional secret key (for signed URLs)
|
|
36
|
+
3. Enable the ScreenshotOne plugin on this page
|
|
37
|
+
4. Enter your credentials in the settings below
|
|
38
|
+
|
|
39
|
+
## Settings
|
|
40
|
+
|
|
41
|
+
- **Access Key** (required, secret) — your ScreenshotOne access key; falls back to `PLUGIN_SCREENSHOTONE_ACCESS_KEY`.
|
|
42
|
+
- **Secret Key** (secret) — used to generate signed URLs; falls back to `PLUGIN_SCREENSHOTONE_SECRET_KEY`.
|
|
43
|
+
- **Viewport Width / Height** — default capture viewport in pixels (defaults: 1280 x 800).
|
|
44
|
+
- **Image Format** — output format: `png`, `jpg`, `jpeg`, or `webp` (default: `png`).
|
|
45
|
+
- **Full Page** — capture the full scrollable page (default: off).
|
|
46
|
+
- **Device Scale Factor** — `1` for normal, `2` for retina (range 0.5–3).
|
|
47
|
+
- **Block Ads** — strip ads from captured pages (default: on).
|
|
48
|
+
- **Block Trackers** — strip tracking scripts (default: on).
|
|
49
|
+
|
|
50
|
+
## Troubleshooting
|
|
51
|
+
|
|
52
|
+
| Symptom | Likely cause | Fix |
|
|
53
|
+
| ------------------------------------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
54
|
+
| `401` / `Authentication failed` | API key (or signing secret) missing or wrong | Re-enter the credential(s) from the ScreenshotOne dashboard, or set `PLUGIN_SCREENSHOTONE_API_KEY` (and signing-secret env var if applicable) for default fallback |
|
|
55
|
+
| Black / blank / `null` `imageUrl` returned | Target page failed to render within the configured timeout, or is blocked by anti-bot protection | Increase the timeout, enable wait-for-network-idle / `full_page` mode, or set a custom `user_agent` and `viewport` |
|
|
56
|
+
| Plugin not used for screenshot capture | Another screenshot plugin is set as the default | In **Settings → Plugins**, set `screenshotone` as the default for `screenshot`, or disable competing plugins |
|
|
57
|
+
| Quota exhausted / `429` | Monthly / per-minute screenshot cap reached on ScreenshotOne | Throttle calls, wait for the quota reset, or upgrade the plan in the ScreenshotOne dashboard |
|
|
58
|
+
| `healthCheck` reports unhealthy | Credential invalid OR ScreenshotOne endpoint unreachable from the host | Verify the credential with a manual call to the upstream API and confirm outbound HTTPS is allowed by the firewall |
|
|
59
|
+
|
|
60
|
+
## Local development
|
|
61
|
+
|
|
62
|
+
This plugin ships built-in with the Ever Works platform. To work on it locally from the monorepo root:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm install
|
|
66
|
+
pnpm --filter @ever-works/screenshotone-plugin build
|
|
67
|
+
pnpm --filter @ever-works/screenshotone-plugin test
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
- [Ever Works documentation](https://docs.ever.works)
|
|
73
|
+
- [Ever Works repository](https://github.com/ever-works/ever-works)
|
|
74
|
+
- [Plugin system](../../plugin/README.md)
|
|
75
|
+
- [ScreenshotOne homepage](https://screenshotone.com)
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
AGPL-3.0
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ever-works/screenshotone-plugin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "ScreenshotOne screenshot plugin for Ever Works - capture website screenshots using the ScreenshotOne API",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Ever Co. LTD",
|
|
7
|
+
"email": "ever@ever.co",
|
|
8
|
+
"url": "https://ever.co"
|
|
9
|
+
},
|
|
10
|
+
"license": "AGPL-3.0",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"screenshotone-api-sdk": "^1.1.6"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@ever-works/plugin": "1.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^22.0.0",
|
|
30
|
+
"tsup": "^8.4.0",
|
|
31
|
+
"typescript": "^5.7.3",
|
|
32
|
+
"vitest": "^4.1.0",
|
|
33
|
+
"@ever-works/plugin": "1.1.0"
|
|
34
|
+
},
|
|
35
|
+
"everworks": {
|
|
36
|
+
"plugin": {
|
|
37
|
+
"id": "screenshotone",
|
|
38
|
+
"name": "ScreenshotOne",
|
|
39
|
+
"version": "1.0.0",
|
|
40
|
+
"category": "screenshot",
|
|
41
|
+
"capabilities": [
|
|
42
|
+
"screenshot"
|
|
43
|
+
],
|
|
44
|
+
"description": "Capture website screenshots using the ScreenshotOne API service. Supports configurable viewport sizes, formats, and advanced options like ad blocking.",
|
|
45
|
+
"author": {
|
|
46
|
+
"name": "Ever Works Team"
|
|
47
|
+
},
|
|
48
|
+
"license": "AGPL-3.0",
|
|
49
|
+
"systemPlugin": false,
|
|
50
|
+
"builtIn": false,
|
|
51
|
+
"envVars": [
|
|
52
|
+
{
|
|
53
|
+
"name": "PLUGIN_SCREENSHOTONE_ACCESS_KEY",
|
|
54
|
+
"required": false,
|
|
55
|
+
"secret": true,
|
|
56
|
+
"description": "ScreenshotOne access key (optional - can be set via admin/user settings)"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "PLUGIN_SCREENSHOTONE_SECRET_KEY",
|
|
60
|
+
"required": false,
|
|
61
|
+
"secret": true,
|
|
62
|
+
"description": "ScreenshotOne secret key for signed URLs (optional - can be set via admin/user settings)"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"distribution": "registry"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"private": false,
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "restricted",
|
|
71
|
+
"registry": "https://registry.npmjs.org"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "tsc --noEmit && tsup",
|
|
75
|
+
"dev": "tsup --watch",
|
|
76
|
+
"type-check": "tsc --noEmit",
|
|
77
|
+
"clean": "rm -rf dist",
|
|
78
|
+
"test": "vitest run --passWithNoTests",
|
|
79
|
+
"test:watch": "vitest",
|
|
80
|
+
"test:coverage": "vitest run --coverage"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { ScreenshotOnePlugin } from '../screenshotone.plugin.js';
|
|
3
|
+
import type { PluginContext, ScreenshotOptions } from '@ever-works/plugin';
|
|
4
|
+
|
|
5
|
+
// Mock the screenshotone-api-sdk module
|
|
6
|
+
vi.mock('screenshotone-api-sdk', () => {
|
|
7
|
+
const mockTakeOptions = {
|
|
8
|
+
url: vi.fn().mockReturnThis(),
|
|
9
|
+
viewportWidth: vi.fn().mockReturnThis(),
|
|
10
|
+
viewportHeight: vi.fn().mockReturnThis(),
|
|
11
|
+
format: vi.fn().mockReturnThis(),
|
|
12
|
+
fullPage: vi.fn().mockReturnThis(),
|
|
13
|
+
deviceScaleFactor: vi.fn().mockReturnThis(),
|
|
14
|
+
blockAds: vi.fn().mockReturnThis(),
|
|
15
|
+
blockTrackers: vi.fn().mockReturnThis(),
|
|
16
|
+
blockCookieBanners: vi.fn().mockReturnThis(),
|
|
17
|
+
delay: vi.fn().mockReturnThis(),
|
|
18
|
+
cache: vi.fn().mockReturnThis(),
|
|
19
|
+
cacheTtl: vi.fn().mockReturnThis(),
|
|
20
|
+
selector: vi.fn().mockReturnThis(),
|
|
21
|
+
userAgent: vi.fn().mockReturnThis()
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
Client: vi.fn().mockImplementation(function () {
|
|
26
|
+
return {
|
|
27
|
+
take: vi.fn().mockResolvedValue({
|
|
28
|
+
arrayBuffer: vi.fn().mockResolvedValue(new ArrayBuffer(100))
|
|
29
|
+
}),
|
|
30
|
+
generateTakeURL: vi.fn().mockReturnValue('https://api.screenshotone.com/take?url=test'),
|
|
31
|
+
generateSignedTakeURL: vi
|
|
32
|
+
.fn()
|
|
33
|
+
.mockReturnValue('https://api.screenshotone.com/take?url=test&signature=abc')
|
|
34
|
+
};
|
|
35
|
+
}),
|
|
36
|
+
TakeOptions: {
|
|
37
|
+
url: vi.fn().mockReturnValue(mockTakeOptions)
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('ScreenshotOnePlugin', () => {
|
|
43
|
+
let plugin: ScreenshotOnePlugin;
|
|
44
|
+
let mockContext: PluginContext;
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
plugin = new ScreenshotOnePlugin();
|
|
48
|
+
mockContext = {
|
|
49
|
+
pluginId: 'screenshotone',
|
|
50
|
+
logger: {
|
|
51
|
+
log: vi.fn(),
|
|
52
|
+
error: vi.fn(),
|
|
53
|
+
warn: vi.fn(),
|
|
54
|
+
debug: vi.fn()
|
|
55
|
+
},
|
|
56
|
+
cache: {} as any,
|
|
57
|
+
http: {} as any,
|
|
58
|
+
env: {} as any,
|
|
59
|
+
envVars: {} as any,
|
|
60
|
+
services: {} as any,
|
|
61
|
+
getSettings: vi.fn().mockResolvedValue({}),
|
|
62
|
+
getResolvedSettings: vi.fn().mockResolvedValue({}),
|
|
63
|
+
onEvent: vi.fn(),
|
|
64
|
+
emitEvent: vi.fn(),
|
|
65
|
+
registerCustomCapability: vi.fn(),
|
|
66
|
+
getCustomCapability: vi.fn(),
|
|
67
|
+
hasCustomCapability: vi.fn(),
|
|
68
|
+
listCustomCapabilities: vi.fn()
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
afterEach(() => {
|
|
73
|
+
vi.clearAllMocks();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('Plugin Metadata', () => {
|
|
77
|
+
it('should have correct plugin metadata', () => {
|
|
78
|
+
expect(plugin.id).toBe('screenshotone');
|
|
79
|
+
expect(plugin.name).toBe('ScreenshotOne');
|
|
80
|
+
expect(plugin.version).toBe('1.0.0');
|
|
81
|
+
expect(plugin.category).toBe('screenshot');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should have screenshot capability', () => {
|
|
85
|
+
expect(plugin.capabilities).toContain('screenshot');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should have provider name', () => {
|
|
89
|
+
expect(plugin.providerName).toBe('ScreenshotOne');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should have hybrid configuration mode', () => {
|
|
93
|
+
expect(plugin.configurationMode).toBe('hybrid');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('Settings Schema', () => {
|
|
98
|
+
it('should define accessKey as required', () => {
|
|
99
|
+
expect(plugin.settingsSchema.required).toContain('accessKey');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should mark accessKey as secret', () => {
|
|
103
|
+
const properties = plugin.settingsSchema.properties as Record<string, any>;
|
|
104
|
+
expect(properties.accessKey['x-secret']).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should mark secretKey as secret', () => {
|
|
108
|
+
const properties = plugin.settingsSchema.properties as Record<string, any>;
|
|
109
|
+
expect(properties.secretKey['x-secret']).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should have environment variable fallbacks', () => {
|
|
113
|
+
const properties = plugin.settingsSchema.properties as Record<string, any>;
|
|
114
|
+
expect(properties.accessKey['x-envVar']).toBe('PLUGIN_SCREENSHOTONE_ACCESS_KEY');
|
|
115
|
+
expect(properties.secretKey['x-envVar']).toBe('PLUGIN_SCREENSHOTONE_SECRET_KEY');
|
|
116
|
+
expect(properties.viewportWidth['x-envVar']).toBe('PLUGIN_SCREENSHOTONE_VIEWPORT_WIDTH');
|
|
117
|
+
expect(properties.viewportHeight['x-envVar']).toBe('PLUGIN_SCREENSHOTONE_VIEWPORT_HEIGHT');
|
|
118
|
+
expect(properties.format['x-envVar']).toBe('PLUGIN_SCREENSHOTONE_FORMAT');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should have default values for viewport settings', () => {
|
|
122
|
+
const properties = plugin.settingsSchema.properties as Record<string, any>;
|
|
123
|
+
expect(properties.viewportWidth.default).toBe(1280);
|
|
124
|
+
expect(properties.viewportHeight.default).toBe(800);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should have default values for format and blocking options', () => {
|
|
128
|
+
const properties = plugin.settingsSchema.properties as Record<string, any>;
|
|
129
|
+
expect(properties.format.default).toBe('png');
|
|
130
|
+
expect(properties.fullPage.default).toBe(false);
|
|
131
|
+
expect(properties.blockAds.default).toBe(true);
|
|
132
|
+
expect(properties.blockTrackers.default).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('IScreenshotPlugin - capture', () => {
|
|
137
|
+
it('should capture screenshot successfully with settings', async () => {
|
|
138
|
+
await plugin.onLoad(mockContext);
|
|
139
|
+
|
|
140
|
+
const options: ScreenshotOptions = {
|
|
141
|
+
url: 'https://example.com',
|
|
142
|
+
settings: {
|
|
143
|
+
accessKey: 'test-access-key',
|
|
144
|
+
secretKey: 'test-secret-key'
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const result = await plugin.capture(options);
|
|
149
|
+
|
|
150
|
+
expect(result.success).toBe(true);
|
|
151
|
+
expect(result.imageBuffer).toBeDefined();
|
|
152
|
+
expect(result.imageBase64).toBeDefined();
|
|
153
|
+
expect(result.imageUrl).toBeDefined();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should fail when access key is not configured', async () => {
|
|
157
|
+
await plugin.onLoad(mockContext);
|
|
158
|
+
|
|
159
|
+
const options: ScreenshotOptions = {
|
|
160
|
+
url: 'https://example.com',
|
|
161
|
+
settings: {}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const result = await plugin.capture(options);
|
|
165
|
+
|
|
166
|
+
expect(result.success).toBe(false);
|
|
167
|
+
expect(result.error).toContain('access key not configured');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('should use provided viewport dimensions', async () => {
|
|
171
|
+
await plugin.onLoad(mockContext);
|
|
172
|
+
|
|
173
|
+
const options: ScreenshotOptions = {
|
|
174
|
+
url: 'https://example.com',
|
|
175
|
+
viewportWidth: 1920,
|
|
176
|
+
viewportHeight: 1080,
|
|
177
|
+
settings: {
|
|
178
|
+
accessKey: 'test-key'
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const result = await plugin.capture(options);
|
|
183
|
+
|
|
184
|
+
expect(result.success).toBe(true);
|
|
185
|
+
expect(result.width).toBe(1920);
|
|
186
|
+
expect(result.height).toBe(1080);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('IScreenshotPlugin - getScreenshotUrl', () => {
|
|
191
|
+
it('should generate URL with settings', async () => {
|
|
192
|
+
await plugin.onLoad(mockContext);
|
|
193
|
+
|
|
194
|
+
const options: ScreenshotOptions = {
|
|
195
|
+
url: 'https://example.com',
|
|
196
|
+
settings: {
|
|
197
|
+
accessKey: 'test-key'
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const url = await plugin.getScreenshotUrl(options);
|
|
202
|
+
|
|
203
|
+
expect(url).toBeDefined();
|
|
204
|
+
expect(url).toContain('api.screenshotone.com');
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('should generate signed URL when secret key is available', async () => {
|
|
208
|
+
await plugin.onLoad(mockContext);
|
|
209
|
+
|
|
210
|
+
const options: ScreenshotOptions = {
|
|
211
|
+
url: 'https://example.com',
|
|
212
|
+
settings: {
|
|
213
|
+
accessKey: 'test-key',
|
|
214
|
+
secretKey: 'test-secret'
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const url = await plugin.getScreenshotUrl(options);
|
|
219
|
+
|
|
220
|
+
expect(url).toBeDefined();
|
|
221
|
+
expect(url).toContain('signature');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should return null when access key is missing', async () => {
|
|
225
|
+
await plugin.onLoad(mockContext);
|
|
226
|
+
|
|
227
|
+
const options: ScreenshotOptions = {
|
|
228
|
+
url: 'https://example.com',
|
|
229
|
+
settings: {}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const url = await plugin.getScreenshotUrl(options);
|
|
233
|
+
|
|
234
|
+
expect(url).toBeNull();
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe('IScreenshotPlugin - isAvailable', () => {
|
|
239
|
+
it('should return true when access key is configured', async () => {
|
|
240
|
+
(mockContext.getSettings as ReturnType<typeof vi.fn>).mockResolvedValue({ accessKey: 'test-key' });
|
|
241
|
+
await plugin.onLoad(mockContext);
|
|
242
|
+
const available = await plugin.isAvailable();
|
|
243
|
+
expect(available).toBe(true);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('should return false when not loaded', async () => {
|
|
247
|
+
const available = await plugin.isAvailable();
|
|
248
|
+
expect(available).toBe(false);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe('IScreenshotPlugin - validateCredentials', () => {
|
|
253
|
+
it('should return invalid when plugin not initialized', async () => {
|
|
254
|
+
const result = await plugin.validateCredentials();
|
|
255
|
+
|
|
256
|
+
expect(result.valid).toBe(false);
|
|
257
|
+
expect(result.message).toContain('not initialized');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('should return invalid when access key not configured', async () => {
|
|
261
|
+
vi.mocked(mockContext.getSettings).mockResolvedValue({});
|
|
262
|
+
await plugin.onLoad(mockContext);
|
|
263
|
+
|
|
264
|
+
const result = await plugin.validateCredentials();
|
|
265
|
+
|
|
266
|
+
expect(result.valid).toBe(false);
|
|
267
|
+
expect(result.message).toContain('Access key is not configured');
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('should return valid when credentials are configured', async () => {
|
|
271
|
+
vi.mocked(mockContext.getSettings).mockResolvedValue({
|
|
272
|
+
accessKey: 'test-key'
|
|
273
|
+
});
|
|
274
|
+
await plugin.onLoad(mockContext);
|
|
275
|
+
|
|
276
|
+
const result = await plugin.validateCredentials();
|
|
277
|
+
|
|
278
|
+
expect(result.valid).toBe(true);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('IScreenshotPlugin - getSupportedFormats', () => {
|
|
283
|
+
it('should return supported formats', () => {
|
|
284
|
+
const formats = plugin.getSupportedFormats();
|
|
285
|
+
|
|
286
|
+
expect(formats).toContain('png');
|
|
287
|
+
expect(formats).toContain('jpg');
|
|
288
|
+
expect(formats).toContain('jpeg');
|
|
289
|
+
expect(formats).toContain('webp');
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe('IScreenshotPlugin - getMaxDimensions', () => {
|
|
294
|
+
it('should return maximum viewport dimensions', () => {
|
|
295
|
+
const dimensions = plugin.getMaxDimensions();
|
|
296
|
+
|
|
297
|
+
expect(dimensions.width).toBe(3840);
|
|
298
|
+
expect(dimensions.height).toBe(2160);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
describe('Lifecycle', () => {
|
|
303
|
+
it('should log on load', async () => {
|
|
304
|
+
await plugin.onLoad(mockContext);
|
|
305
|
+
expect(mockContext.logger.log).toHaveBeenCalledWith('ScreenshotOne Plugin loaded');
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('should clear context on unload', async () => {
|
|
309
|
+
await plugin.onLoad(mockContext);
|
|
310
|
+
await plugin.onUnload();
|
|
311
|
+
// Context should be cleared - validateCredentials should fail
|
|
312
|
+
const result = await plugin.validateCredentials();
|
|
313
|
+
expect(result.valid).toBe(false);
|
|
314
|
+
expect(result.message).toContain('not initialized');
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
describe('healthCheck', () => {
|
|
319
|
+
it('should return healthy status', async () => {
|
|
320
|
+
const health = await plugin.healthCheck();
|
|
321
|
+
|
|
322
|
+
expect(health.status).toBe('healthy');
|
|
323
|
+
expect(health.checkedAt).toBeDefined();
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
describe('getManifest', () => {
|
|
328
|
+
it('should return correct manifest', () => {
|
|
329
|
+
const manifest = plugin.getManifest();
|
|
330
|
+
|
|
331
|
+
expect(manifest.id).toBe('screenshotone');
|
|
332
|
+
expect(manifest.name).toBe('ScreenshotOne');
|
|
333
|
+
expect(manifest.version).toBe('1.0.0');
|
|
334
|
+
expect(manifest.category).toBe('screenshot');
|
|
335
|
+
expect(manifest.capabilities).toContain('screenshot');
|
|
336
|
+
expect(manifest.builtIn).toBe(false);
|
|
337
|
+
expect(manifest.systemPlugin).toBe(false);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('should have icon configuration', () => {
|
|
341
|
+
const manifest = plugin.getManifest();
|
|
342
|
+
|
|
343
|
+
expect(manifest.icon).toBeDefined();
|
|
344
|
+
expect(manifest.icon?.type).toBe('lucide');
|
|
345
|
+
expect(manifest.icon?.value).toBe('Camera');
|
|
346
|
+
expect(manifest.icon?.backgroundColor).toBe('#4f46e5');
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
});
|
package/src/index.ts
ADDED