astro-better-declarative-screenshots 0.1.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,72 @@
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
+ });
@@ -0,0 +1,35 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { generatePlaceholder } from '../src/placeholder.mjs';
3
+ import sharp from 'sharp';
4
+
5
+ describe('generatePlaceholder', () => {
6
+ it('returns a Buffer', async () => {
7
+ const buf = await generatePlaceholder({ name: 'test-screenshot' });
8
+ expect(Buffer.isBuffer(buf)).toBe(true);
9
+ });
10
+
11
+ it('generates a valid PNG', async () => {
12
+ const buf = await generatePlaceholder({ name: 'test' });
13
+ const meta = await sharp(buf).metadata();
14
+ expect(meta.format).toBe('png');
15
+ });
16
+
17
+ it('uses the specified dimensions', async () => {
18
+ const buf = await generatePlaceholder({ name: 'test', width: 800, height: 600 });
19
+ const meta = await sharp(buf).metadata();
20
+ expect(meta.width).toBe(800);
21
+ expect(meta.height).toBe(600);
22
+ });
23
+
24
+ it('defaults to 1280x800', async () => {
25
+ const buf = await generatePlaceholder({ name: 'test' });
26
+ const meta = await sharp(buf).metadata();
27
+ expect(meta.width).toBe(1280);
28
+ expect(meta.height).toBe(800);
29
+ });
30
+
31
+ it('handles names with special XML characters', async () => {
32
+ // should not throw
33
+ await expect(generatePlaceholder({ name: 'foo<bar>&baz' })).resolves.toBeTruthy();
34
+ });
35
+ });
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ['tests/**/*.test.mjs'],
6
+ environment: 'node',
7
+ // chrome/placeholder tests use sharp which is native -- run them serially
8
+ // to avoid port/resource contention
9
+ pool: 'forks',
10
+ timeout: 30000,
11
+ },
12
+ });