@vitus-labs/tools-favicon 1.5.2-alpha.4 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitus-labs/tools-favicon",
3
- "version": "1.5.2-alpha.4+45b8634",
3
+ "version": "1.6.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,15 +29,16 @@
29
29
  },
30
30
  "scripts": {
31
31
  "prepublish": "bun run build",
32
- "build": "rm -rf lib && tsc"
32
+ "build": "rm -rf lib && tsc",
33
+ "typecheck": "tsc --noEmit"
33
34
  },
34
35
  "dependencies": {
35
- "@vitus-labs/tools-core": "1.5.2-alpha.4+45b8634",
36
+ "@vitus-labs/tools-core": "1.6.0",
36
37
  "favicons": "^7.2.0"
37
38
  },
38
39
  "devDependencies": {
39
- "@vitus-labs/tools-typescript": "1.5.2-alpha.4+45b8634",
40
+ "@vitus-labs/tools-typescript": "1.6.0",
40
41
  "typescript": "^5.9.3"
41
42
  },
42
- "gitHead": "45b863472eafa888f12f8f56d347dd20b72cd4f9"
43
+ "gitHead": "cb7b3bfa4e5730ecb95b3c886d23074a3ce9e85f"
43
44
  }
@@ -0,0 +1,47 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { configuration } from './baseConfig.js'
3
+
4
+ describe('favicon baseConfig', () => {
5
+ it('should have correct default display settings', () => {
6
+ expect(configuration.dir).toBe('auto')
7
+ expect(configuration.lang).toBe('en-US')
8
+ expect(configuration.display).toBe('standalone')
9
+ expect(configuration.orientation).toBe('any')
10
+ })
11
+
12
+ it('should have correct color settings', () => {
13
+ expect(configuration.background).toBe('#fff')
14
+ expect(configuration.theme_color).toBe('#fff')
15
+ })
16
+
17
+ it('should have apple status bar style', () => {
18
+ expect(configuration.appleStatusBarStyle).toBe('black-translucent')
19
+ })
20
+
21
+ it('should have correct URL settings', () => {
22
+ expect(configuration.scope).toBe('/')
23
+ expect(configuration.start_url).toBe('/?homescreen=1')
24
+ })
25
+
26
+ it('should have logging disabled by default', () => {
27
+ expect(configuration.logging).toBe(false)
28
+ expect(configuration.pixel_art).toBe(false)
29
+ expect(configuration.loadManifestWithCredentials).toBe(false)
30
+ })
31
+
32
+ it('should have all icon platforms enabled', () => {
33
+ const { icons } = configuration
34
+ expect(icons.android).toBe(true)
35
+ expect(icons.appleIcon).toBe(true)
36
+ expect(icons.appleStartup).toBe(true)
37
+ expect(icons.coast).toBe(true)
38
+ expect(icons.favicons).toBe(true)
39
+ expect(icons.firefox).toBe(true)
40
+ expect(icons.windows).toBe(true)
41
+ expect(icons.yandex).toBe(true)
42
+ })
43
+
44
+ it('should have version string', () => {
45
+ expect(configuration.version).toBe('1.0')
46
+ })
47
+ })
@@ -0,0 +1,82 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
+
3
+ const mockWriteFileSync = vi.fn()
4
+ vi.mock('node:fs', () => ({
5
+ default: { writeFileSync: mockWriteFileSync },
6
+ writeFileSync: mockWriteFileSync,
7
+ }))
8
+
9
+ const mockFavicons = vi.fn()
10
+ vi.mock('favicons', () => ({ default: mockFavicons }))
11
+
12
+ vi.mock('@vitus-labs/tools-core', () => ({
13
+ VL_CONFIG: (_key: string) => ({
14
+ config: {},
15
+ get: vi.fn(),
16
+ merge: (config: any) => ({
17
+ config: {
18
+ ...config,
19
+ icons: [
20
+ { input: 'src/icon.png', output: 'public/icons', path: 'icons' },
21
+ ],
22
+ path: '/assets',
23
+ },
24
+ }),
25
+ }),
26
+ }))
27
+
28
+ describe('generateFavicons', () => {
29
+ beforeEach(() => {
30
+ mockWriteFileSync.mockClear()
31
+ mockFavicons.mockClear()
32
+ })
33
+
34
+ it('should generate favicons for each icon config', async () => {
35
+ mockFavicons.mockResolvedValue({
36
+ images: [{ name: 'favicon.ico', contents: Buffer.from('icon') }],
37
+ files: [{ name: 'manifest.json', contents: Buffer.from('{}') }],
38
+ })
39
+
40
+ vi.resetModules()
41
+ const { generateFavicons } = await import('./generateFavicon.js')
42
+
43
+ await generateFavicons()
44
+
45
+ expect(mockFavicons).toHaveBeenCalledTimes(1)
46
+ expect(mockWriteFileSync).toHaveBeenCalledTimes(2)
47
+ })
48
+
49
+ it('should handle favicon generation errors', async () => {
50
+ const consoleSpy = vi
51
+ .spyOn(console, 'log')
52
+ .mockImplementation(() => undefined)
53
+
54
+ mockFavicons.mockRejectedValue(new Error('Generation failed'))
55
+
56
+ vi.resetModules()
57
+ const { generateFavicons } = await import('./generateFavicon.js')
58
+
59
+ await generateFavicons()
60
+
61
+ expect(consoleSpy).toHaveBeenCalledWith('Generation failed')
62
+ consoleSpy.mockRestore()
63
+ })
64
+
65
+ it('should write images and manifests to output path', async () => {
66
+ mockFavicons.mockResolvedValue({
67
+ images: [
68
+ { name: 'icon-192.png', contents: Buffer.from('192') },
69
+ { name: 'icon-512.png', contents: Buffer.from('512') },
70
+ ],
71
+ files: [{ name: 'manifest.webmanifest', contents: Buffer.from('{}') }],
72
+ })
73
+
74
+ vi.resetModules()
75
+ const { generateFavicons } = await import('./generateFavicon.js')
76
+
77
+ await generateFavicons()
78
+
79
+ // 2 images + 1 manifest
80
+ expect(mockWriteFileSync).toHaveBeenCalledTimes(3)
81
+ })
82
+ })
package/tsconfig.json CHANGED
@@ -8,5 +8,5 @@
8
8
  "declarationDir": "./lib/types"
9
9
  },
10
10
  "include": ["src"],
11
- "exclude": ["node_modules", "__stories__", "lib"]
11
+ "exclude": ["node_modules", "__stories__", "lib", "**/*.test.ts"]
12
12
  }
@@ -0,0 +1,3 @@
1
+ import { createVitestConfig } from '../../vitest.shared.js'
2
+
3
+ export default createVitestConfig()