astro-better-declarative-screenshots 0.4.1 → 0.4.2

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.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2026 Better Static Sites
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # astro-better-declarative-screenshots
2
+
3
+ Astro components that render committed screenshot PNGs in your docs site. No Playwright, no Docker, no heavy dependencies.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install astro-better-declarative-screenshots
9
+ ```
10
+
11
+ ## What it does
12
+
13
+ - Declare screenshots and highlights inline in MDX
14
+ - Reads committed PNG files and renders them at build time
15
+ - Pairs with `astro-better-generate-screenshots`, which produces the PNGs
16
+
17
+ ## Documentation
18
+
19
+ Full documentation, including configuration and examples, is at
20
+ [https://better-static-sites.github.io/content/declarative-screenshots](https://better-static-sites.github.io/content/declarative-screenshots).
21
+
22
+ This package is published from the [Better Static Sites monorepo](https://github.com/better-static-sites/better-static-sites.github.io); the directory it lives in has a combined README covering it and its sibling package.
package/package.json CHANGED
@@ -1,16 +1,31 @@
1
1
  {
2
2
  "name": "astro-better-declarative-screenshots",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
+ "description": "Astro components that render committed screenshot PNGs in your docs site",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/better-static-sites/better-static-sites.github.io.git",
8
+ "directory": "astro-better-declarative-screenshots/use-screenshots"
9
+ },
10
+ "homepage": "https://better-static-sites.github.io",
11
+ "bugs": {
12
+ "url": "https://github.com/better-static-sites/better-static-sites.github.io/issues"
13
+ },
4
14
  "type": "module",
5
15
  "exports": {
6
16
  ".": "./index.mjs",
7
17
  "./Screenshot.astro": "./Screenshot.astro",
8
18
  "./Highlight.astro": "./Highlight.astro"
9
19
  },
10
- "peerDependencies": {
11
- "astro": ">=4.0.0"
12
- },
20
+ "files": [
21
+ "index.mjs",
22
+ "*.astro",
23
+ "src/"
24
+ ],
13
25
  "dependencies": {
14
26
  "zod": "^3.23.0"
27
+ },
28
+ "peerDependencies": {
29
+ "astro": ">=4.0.0"
15
30
  }
16
31
  }
@@ -1,96 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
- import { loadConfig } from '../src/config.mjs';
3
- import { mkdirSync, writeFileSync, rmSync } from 'fs';
4
- import path from 'path';
5
- import os from 'os';
6
-
7
- let tmpDir;
8
-
9
- beforeEach(() => {
10
- tmpDir = path.join(os.tmpdir(), `config-test-${Math.random().toString(36).slice(2)}`);
11
- mkdirSync(tmpDir, { recursive: true });
12
- });
13
-
14
- afterEach(() => {
15
- rmSync(tmpDir, { recursive: true, force: true });
16
- });
17
-
18
- function writeConfig(content) {
19
- writeFileSync(path.join(tmpDir, 'screenshot.config.mjs'), content);
20
- }
21
-
22
- describe('loadConfig', () => {
23
- it('throws when no config file exists', async () => {
24
- await expect(loadConfig(tmpDir)).rejects.toThrow(/No screenshot.config.mjs/);
25
- });
26
-
27
- it('loads a minimal valid config (no docker)', async () => {
28
- writeConfig(`
29
- export default {
30
- baseUrl: 'http://localhost:9011',
31
- };
32
- `);
33
- const config = await loadConfig(tmpDir);
34
- expect(config.baseUrl).toBe('http://localhost:9011');
35
- expect(config.docker).toBeUndefined();
36
- // defaults applied
37
- expect(config.browser).toBe('webkit');
38
- expect(config.outputDir).toBe('./src/assets/screenshots');
39
- expect(config.colorScheme).toBe('light');
40
- });
41
-
42
- it('loads a config with docker settings', async () => {
43
- writeConfig(`
44
- export default {
45
- baseUrl: 'http://localhost:9011',
46
- docker: {
47
- healthcheck: { url: 'http://localhost:9011/api/status' },
48
- },
49
- };
50
- `);
51
- const config = await loadConfig(tmpDir);
52
- expect(config.docker.healthcheck.url).toBe('http://localhost:9011/api/status');
53
- });
54
-
55
- it('applies window defaults', async () => {
56
- writeConfig(`export default { baseUrl: 'http://localhost:9011' };`);
57
- const config = await loadConfig(tmpDir);
58
- expect(config.window.width).toBe(1280);
59
- expect(config.window.height).toBe(800);
60
- });
61
-
62
- it('applies chrome defaults', async () => {
63
- writeConfig(`export default { baseUrl: 'http://localhost:9011' };`);
64
- const config = await loadConfig(tmpDir);
65
- expect(config.chrome.style).toBe('safari-macos');
66
- expect(config.chrome.showUrl).toBe(true);
67
- expect(config.chrome.shadowBlur).toBe(40);
68
- });
69
-
70
- it('accepts a custom outputDir', async () => {
71
- writeConfig(`
72
- export default {
73
- baseUrl: 'http://localhost:9011',
74
- outputDir: 'public/screenshots',
75
- };
76
- `);
77
- const config = await loadConfig(tmpDir);
78
- expect(config.outputDir).toBe('public/screenshots');
79
- });
80
-
81
- it('rejects an invalid baseUrl', async () => {
82
- writeConfig(`export default { baseUrl: 'not-a-url' };`);
83
- await expect(loadConfig(tmpDir)).rejects.toThrow(/invalid/i);
84
- });
85
-
86
- it('accepts beforeScreenshot as a function', async () => {
87
- writeConfig(`
88
- export default {
89
- baseUrl: 'http://localhost:9011',
90
- beforeScreenshot: async (page, spec) => {},
91
- };
92
- `);
93
- const config = await loadConfig(tmpDir);
94
- expect(typeof config.beforeScreenshot).toBe('function');
95
- });
96
- });
@@ -1,72 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { deriveName } from '../src/naming.mjs';
3
-
4
- describe('deriveName', () => {
5
- it('converts URL path segments to a slug', () => {
6
- expect(deriveName('/admin/group/add')).toBe('admin-group-add');
7
- });
8
-
9
- it('strips leading slash', () => {
10
- expect(deriveName('/admin')).toBe('admin');
11
- });
12
-
13
- it('handles root path', () => {
14
- expect(deriveName('/')).toBe('screenshot');
15
- });
16
-
17
- it('handles full URLs', () => {
18
- expect(deriveName('http://localhost:9011/admin/group')).toBe('admin-group');
19
- });
20
-
21
- it('ignores query string and hash', () => {
22
- expect(deriveName('/admin/group?tab=members#section')).toBe('admin-group');
23
- });
24
-
25
- it('appends selector slug for single highlight', () => {
26
- const result = deriveName('/admin/group', [{ selector: '#group-name' }]);
27
- expect(result).toBe('admin-group-group-name');
28
- });
29
-
30
- it('appends multiple selector slugs', () => {
31
- const result = deriveName('/admin/group', [
32
- { selector: '.group-name' },
33
- { selector: '#submit-btn' },
34
- ]);
35
- expect(result).toBe('admin-group-group-name-submit-btn');
36
- });
37
-
38
- it('handles complex selectors', () => {
39
- const result = deriveName('/admin', [{ selector: 'input[type="text"]' }]);
40
- expect(result).toBe('admin-input-type-text');
41
- });
42
-
43
- it('resolves simple collisions with numeric suffix', () => {
44
- const used = new Set();
45
- const a = deriveName('/admin/group', [], used);
46
- const b = deriveName('/admin/group', [], used);
47
- const c = deriveName('/admin/group', [], used);
48
- expect(a).toBe('admin-group');
49
- expect(b).toBe('admin-group-1');
50
- expect(c).toBe('admin-group-2');
51
- });
52
-
53
- it('mutates the used set', () => {
54
- const used = new Set();
55
- deriveName('/admin', [], used);
56
- expect(used.has('admin')).toBe(true);
57
- });
58
-
59
- it('handles path segments with special chars', () => {
60
- expect(deriveName('/foo/bar_baz.html')).toBe('foo-bar-baz-html');
61
- });
62
-
63
- it('handles multi-part class selector', () => {
64
- const result = deriveName('/page', [{ selector: '.foo .bar' }]);
65
- expect(result).toBe('page-foo-bar');
66
- });
67
-
68
- it('empty highlights have no effect on the name', () => {
69
- expect(deriveName('/admin/group', [])).toBe('admin-group');
70
- expect(deriveName('/admin/group', [{ selector: undefined }])).toBe('admin-group');
71
- });
72
- });