Skip to content

Commit b79029c

Browse files
committed
Fix errors that turned up in e2e testing - script init, favicon generation
1 parent 169e13d commit b79029c

20 files changed

Lines changed: 314 additions & 119 deletions

playwright.config.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import 'dotenv/config'
1010
* See https://playwright.dev/docs/test-configuration.
1111
*/
1212

13-
/** Debug mode - set DEBUG=true to run only chromium with no HTML report */
14-
const isDebugMode = process.env['DEBUG'] === 'true'
13+
/** Debug mode - set DEBUG=1 or DEBUG=true to run only chromium with no HTML report */
14+
const isDebugMode = Boolean(process.env['DEBUG'] && process.env['DEBUG'] !== 'false' && process.env['DEBUG'] !== '0')
1515

1616
export default defineConfig({
1717
/* Look for test files in the "tests" directory, relative to this configuration file. */
@@ -112,13 +112,18 @@ export default defineConfig({
112112
],
113113

114114
/* Run your local dev server before starting the tests */
115-
webServer: {
116-
command: 'npm run dev',
117-
url: 'http://localhost:4321',
118-
/** How long to wait for the process to start up and be available in milliseconds. */
119-
timeout: 120 * 1000,
120-
reuseExistingServer: !process.env['CI'],
121-
},
115+
/* In debug mode, assume server is already running */
116+
...(isDebugMode
117+
? {}
118+
: {
119+
webServer: {
120+
command: 'npm run dev',
121+
url: 'http://localhost:4321',
122+
/** How long to wait for the process to start up and be available in milliseconds. */
123+
timeout: 120 * 1000,
124+
reuseExistingServer: !process.env['CI'],
125+
},
126+
}),
122127

123128
// path to the global setup files.
124129
//globalSetup: require.resolve('./global-setup'),

public/apple-touch-icon.png

2.5 KB
Loading

public/favicon.ico

20.1 KB
Binary file not shown.

public/icon-192.png

2.7 KB
Loading

public/icon-512.png

9.01 KB
Loading

public/icon-mask.png

9.01 KB
Loading

scripts/build/favicon.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
*/
2121
import sharp, { type Metadata } from 'sharp'
2222
import toIco from 'to-ico'
23-
import { writeFile } from 'fs/promises'
23+
import { writeFile, mkdir } from 'fs/promises'
2424

25-
type IconGenerator = (options: Metadata) => Promise<Buffer>
25+
type IconGenerator = (_options: Metadata) => Promise<Buffer>
2626

2727
const faviconPath = `src/assets/favicon.svg`
2828
const generateIcoFavicon: IconGenerator = async ({ width, height, density }) => {
@@ -52,6 +52,17 @@ const generatePngFavicon: IconGenerator = ({ density, width, height }) => {
5252
.toBuffer()
5353
}
5454

55+
const generatePwaIcon = (size: number): IconGenerator => ({ density, width, height }) => {
56+
if (!width || !height || !density)
57+
throw new Error(`Required option not passed to generatePwaIcon`)
58+
return sharp(faviconPath, {
59+
density: (size / Math.max(width, height)) * density,
60+
})
61+
.resize(size, size)
62+
.png()
63+
.toBuffer()
64+
}
65+
5566
const saveFile = (destination: string) => {
5667
return async (buffer: Buffer) => {
5768
return await writeFile(destination, buffer)
@@ -61,12 +72,30 @@ const saveFile = (destination: string) => {
6172
const faviconTypes: Array<[string, IconGenerator]> = [
6273
['favicon.ico', generateIcoFavicon],
6374
['apple-touch-icon.png', generatePngFavicon],
75+
['icon-192.png', generatePwaIcon(192)],
76+
['icon-512.png', generatePwaIcon(512)],
77+
['icon-mask.png', generatePwaIcon(512)],
6478
]
6579

6680
export const buildFavicons = async () => {
6781
const metadata = await sharp(faviconPath).metadata()
82+
const outputDir = `${process.cwd()}/public`
83+
84+
// Ensure output directory exists
85+
await mkdir(outputDir, { recursive: true })
6886

69-
faviconTypes.forEach(([name, generator]) =>
70-
generator(metadata).then(saveFile(`${process.cwd()}/public/images/${name}`))
87+
// Generate all favicons
88+
await Promise.all(
89+
faviconTypes.map(([name, generator]) =>
90+
generator(metadata).then(saveFile(`${outputDir}/${name}`))
91+
)
7192
)
93+
94+
console.log('✅ Favicons and PWA icons generated successfully')
7295
}
96+
97+
// Execute when run directly (ES module)
98+
buildFavicons().catch((error) => {
99+
console.error('❌ Failed to generate favicons:', error)
100+
process.exit(1)
101+
})

src/components/Footer/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ const year = new Date().getFullYear()
169169
class="flex flex-col justify-center lg:pt-3 [&_a:hover]:text-bg-offset [&_a:hover]:underline [&_a:hover]:decoration-dotted [&_a:hover]:decoration-bg [&_a:hover]:underline-offset-4 [&_a:focus]:text-bg-offset [&_a:focus]:underline [&_a:focus]:decoration-dotted [&_a:focus]:decoration-bg [&_a:focus]:underline-offset-4"
170170
>
171171
<a
172-
href="/mailinglist"
172+
href="/#newsletter"
173173
class="lg:[&:hover]:no-underline lg:[&:focus]:no-underline text-color-bg no-underline"
174174
>
175175
<div class="lg:hidden">Subscribe to</div>

src/components/Head/index.astro

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,26 @@ const { pageTitle, path, description, image } = Astro.props
3737
{/* Development: Custom handlers log errors to console for debugging */}
3838
import { SentryBootstrap } from '@components/Scripts/sentry/client'
3939
import { PUBLIC_SENTRY_DSN } from 'astro:env/client'
40+
import { AppBootstrap } from '@components/Scripts/state/bootstrap'
4041

41-
if ( import.meta.env.PROD && PUBLIC_SENTRY_DSN) {
42+
if (import.meta.env.PROD && PUBLIC_SENTRY_DSN) {
4243
SentryBootstrap.init()
44+
AppBootstrap.init()
4345
} else {
4446
// Development: Use custom error handlers with console logging
45-
const { addErrorEventListeners } = await import('@components/Scripts/errors/errorListeners')
46-
addErrorEventListeners()
47-
console.info('🔧 Sentry disabled in development mode')
47+
import('@components/Scripts/errors/errorListeners')
48+
.then(({ addErrorEventListeners }) => {
49+
addErrorEventListeners()
50+
console.info('🔧 Sentry disabled in development mode')
51+
// Initialize AppBootstrap after error handlers
52+
AppBootstrap.init()
53+
})
54+
.catch((error) => {
55+
console.error('❌ Failed to initialize error listeners:', error)
56+
// Still try to initialize AppBootstrap even if error listeners fail
57+
AppBootstrap.init()
58+
})
4859
}
49-
50-
// Initialize AppBootstrap FIRST - initializes state management
51-
// MUST run before any scripts that depend on state
52-
import { AppBootstrap } from '@components/Scripts/state/bootstrap'
53-
54-
AppBootstrap.init()
5560
</script>
5661
{/* Client-side router for Astro pages (enables partial page reloads) */}
5762
{/* Must be placed at the end of the <head> to avoid blocking page rendering */}

src/components/ThemePicker/ThemeButton.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</style>
5252

5353
<button
54-
class="theme-toggle-btn"
54+
class="theme-toggle-btn themepicker-toggle__toggle-btn"
5555
type="button"
5656
aria-expanded="false"
5757
aria-owns="theme-menu"

0 commit comments

Comments
 (0)