Skip to content

Commit 7425123

Browse files
committed
Remove JSDOM from last two test cases using it in favor of happy-dom. The test cases need work to pass but are in line for refactoring to web components, so work is delayed.
1 parent c148c91 commit 7425123

8 files changed

Lines changed: 3829 additions & 4327 deletions

File tree

package-lock.json

Lines changed: 3794 additions & 4273 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"build:dev": "cross-env NODE_ENV=development npx astro build",
3131
"check": "npx astro check",
3232
"clean": "npx rimraf dist && npx rimraf .astro",
33-
"dev": "npm run sync && cross-env NODE_ENV=development npx vercel dev",
33+
"dev": "npm run sync && cross-env NODE_ENV=development npx astro dev",
3434
"format": "npm run format:json && npm run format:code && npm run format:style",
3535
"format:code": "npx prettier --write \"@types/**/*.{js,ts}\" \"scripts/**/*.{js,ts}\" \"src/**/*.{js,ts,tsx,astro}\" --plugin=prettier-plugin-astro",
3636
"format:json": "npx prettier --write '**/*.json' --cache --ignore-path .gitignore",
@@ -50,28 +50,28 @@
5050
},
5151
"dependencies": {
5252
"@astrojs/check": "0.9.5",
53-
"@astrojs/mdx": "4.3.10",
53+
"@astrojs/mdx": "4.3.11",
5454
"@astrojs/preact": "4.1.3",
5555
"@astrojs/rss": "4.0.13",
5656
"@astrojs/sitemap": "^3.6.0",
57-
"@astrojs/vercel": "^9.0.0",
57+
"@astrojs/vercel": "^9.0.1",
5858
"@axe-core/playwright": "^4.11.0",
5959
"@glidejs/glide": "^3.7.1",
6060
"@nanostores/lit": "^0.2.3",
6161
"@nanostores/persistent": "^1.2.0",
62-
"@sentry/astro": "^10.22.0",
63-
"@sentry/browser": "^10.22.0",
64-
"@shikijs/transformers": "^3.14.0",
65-
"@supabase/supabase-js": "^2.81.0",
62+
"@sentry/astro": "^10.25.0",
63+
"@sentry/browser": "^10.25.0",
64+
"@shikijs/transformers": "^3.15.0",
65+
"@supabase/supabase-js": "^2.81.1",
6666
"@tailwindcss/forms": "0.5.10",
6767
"@tailwindcss/typography": "0.5.19",
68-
"@tailwindcss/vite": "^4.1.16",
68+
"@tailwindcss/vite": "^4.1.17",
6969
"@types/hast": "^3.0.4",
7070
"@types/pubsub-js": "^1.8.6",
7171
"@upstash/ratelimit": "^2.0.7",
7272
"@upstash/redis": "^1.35.6",
7373
"@vite-pwa/astro": "^1.1.1",
74-
"astro": "5.15.7",
74+
"astro": "5.15.9",
7575
"astro-icon": "^1.1.5",
7676
"astro-vtbot": "^2.1.9",
7777
"cross-env": "^10.1.0",
@@ -96,14 +96,14 @@
9696
"remark-emoji": "^5.0.2",
9797
"remark-linkify-regex": "^1.2.1",
9898
"remark-toc": "^9.0.0",
99-
"resend": "^6.4.0",
100-
"sharp": "^0.34.4",
99+
"resend": "^6.4.2",
100+
"sharp": "^0.34.5",
101101
"svg-sprite": "2.0.4",
102-
"tailwindcss": "^4.1.16",
102+
"tailwindcss": "^4.1.17",
103103
"title-case": "4.3.2",
104104
"to-ico": "1.1.5",
105105
"uuid": "^13.0.0",
106-
"vite": "^7.1.12",
106+
"vite": "^7.2.2",
107107
"workbox-build": "7.3.0",
108108
"zod": "4.1.12"
109109
},
@@ -122,16 +122,16 @@
122122
"@types/glidejs__glide": "^3.6.6",
123123
"@types/js-cookie": "^3.0.6",
124124
"@types/jsdom": "27.0.0",
125-
"@types/node": "^24.10.0",
125+
"@types/node": "^24.10.1",
126126
"@types/nodemailer": "^7.0.3",
127-
"@types/react": "^19.2.2",
127+
"@types/react": "^19.2.5",
128128
"@types/svg-sprite": "0.0.39",
129129
"@types/to-ico": "1.1.3",
130130
"@types/uuid": "^11.0.0",
131131
"@types/yargs": "17.0.35",
132-
"@typescript-eslint/eslint-plugin": "8.46.4",
133-
"@typescript-eslint/parser": "8.46.4",
134-
"@vitest/coverage-v8": "^4.0.6",
132+
"@typescript-eslint/eslint-plugin": "8.47.0",
133+
"@typescript-eslint/parser": "8.47.0",
134+
"@vitest/coverage-v8": "^4.0.10",
135135
"confusing-browser-globals": "1.0.11",
136136
"cross-spawn": "7.0.6",
137137
"dedent": "^1.7.0",
@@ -147,7 +147,6 @@
147147
"html-element-attributes": "^3.5.0",
148148
"husky": "^9.1.7",
149149
"is-whitespace-character": "^2.0.1",
150-
"jsdom": "^27.1.0",
151150
"md-attr-parser": "^1.3.0",
152151
"prettier": "3.6.2",
153152
"prettier-plugin-astro": "0.14.1",
@@ -162,17 +161,17 @@
162161
"stylelint-config-standard": "^39.0.1",
163162
"stylelint-declaration-block-no-ignored-properties": "2.8.0",
164163
"stylelint-order": "7.0.0",
165-
"supabase": "^2.54.11",
164+
"supabase": "^2.58.5",
166165
"temp-dir": "3.0.0",
167166
"tslib": "2.8.1",
168167
"typescript": "5.9.3",
169-
"typescript-eslint": "8.46.4",
168+
"typescript-eslint": "8.47.0",
170169
"unist-util-inspect": "^8.1.0",
171170
"unist-util-visit": "^5.0.0",
172-
"vitest": "4.0.9",
171+
"vitest": "4.0.10",
173172
"vitest-axe": "0.1.0"
174173
},
175174
"optionalDependencies": {
176-
"@rollup/rollup-linux-x64-gnu": "^4.40.1"
175+
"@rollup/rollup-linux-x64-gnu": "^4.53.2"
177176
}
178177
}

src/components/Hero/__tests__/client.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
// @vitest-environment happy-dom
12
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'
2-
import { JSDOM } from 'jsdom'
33
import { readFileSync } from 'fs'
44
import { resolve } from 'path'
55
import { HeroLoader } from '@components/Hero/client'
@@ -37,9 +37,6 @@ describe('HeroLoader', () => {
3737
let timelineMock: any
3838

3939
beforeEach(() => {
40-
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>')
41-
global.document = dom.window.document
42-
global.window = dom.window as unknown as Window & typeof globalThis
4340
vi.clearAllMocks()
4441
gsapMock = gsap
4542
timelineMock = {

src/components/Navigation/__tests__/navigation.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @vitest-environment happy-dom
21
/**
32
* Tests for navigation menu script using Container API pattern with happy-dom
43
*/
@@ -8,7 +7,6 @@ import { getNavToggleBtnElement } from '@components/Navigation/selectors'
87
import { Navigation } from '@components/Navigation/client'
98
import TestNavigationComponent from '@components/Navigation/__tests__/TestNavigation.astro'
109

11-
// Mock focus-trap to work in jsdom environment
1210
vi.mock('focus-trap', () => {
1311
return {
1412
createFocusTrap: () => ({

src/components/Test/__tests__/container.spec.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
/* eslint-disable jsdoc/escape-inline-tags */
2-
// @vitest-environment node
2+
// @vitest-environment happy-dom
33
/**
44
* ✅ WORKING Container API Reference Implementation
55
*
66
* This demonstrates the successful pattern for using Astro's Container API
77
* with proper Vitest configuration using getViteConfig() from 'astro/config'.
8-
*
9-
* IMPORTANT: Container API requires @vitest-environment node due to esbuild issues in jsdom.
10-
* For DOM testing, use JSDOM manually within the node environment.
118
*/
129
import { describe, it, expect, beforeEach } from 'vitest'
10+
import { Window } from 'happy-dom'
1311
import { experimental_AstroContainer as AstroContainer } from 'astro/container'
14-
import { JSDOM } from 'jsdom'
1512
import ContainerComponent from '@components/Test/container.astro'
1613

1714
describe('Container API Reference Implementation', () => {
@@ -50,14 +47,14 @@ describe('Container API Reference Implementation', () => {
5047
},
5148
})
5249

53-
// Create JSDOM instance for DOM testing in node environment
54-
const dom = new JSDOM(result)
55-
const document = dom.window.document
50+
const window = new Window()
51+
const domParser = new window.DOMParser()
52+
const doc = domParser.parseFromString(result, 'text/html')
5653

5754
// Test DOM elements from actual Astro component
58-
const titleElement = document.querySelector('h2.test-title')
59-
const messageElement = document.querySelector('p.test-message')
60-
const buttonElement = document.querySelector('button.test-button')
55+
const titleElement = doc.querySelector('h2.test-title')
56+
const messageElement = doc.querySelector('p.test-message')
57+
const buttonElement = doc.querySelector('button.test-button')
6158

6259
expect(titleElement).toBeTruthy()
6360
expect(titleElement?.textContent).toBe('Interactive Test')
@@ -69,14 +66,4 @@ describe('Container API Reference Implementation', () => {
6966
expect(buttonElement?.textContent?.trim()).toBe('Test Button')
7067
expect(buttonElement?.id).toBe('test-btn')
7168
})
72-
73-
it('should demonstrate the Container API advantage over manual HTML', () => {
74-
// ✅ GOOD: Using Container API with actual Astro component
75-
// - Always in sync with template changes
76-
// - Includes proper CSS classes and attributes
77-
// - Validates props and component logic
78-
// - Includes Astro's development attributes for debugging
79-
80-
expect(true).toBe(true) // This test documents the approach
81-
})
8269
})

src/lib/markdown/__tests__/e2e/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,6 @@ Uses `@testing-library/preact` (not React) to match the project's Preact configu
135135
- `vitest` - Test runner
136136
- `@testing-library/preact` - Component rendering
137137
- `vitest-axe` - Accessibility testing
138-
- `jsdom` - DOM environment
138+
- `happy-dom` - DOM environment
139139

140140
All dependencies were already present in the project.

test/__mocks__/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ This directory contains reusable mock implementations for testing.
66

77
### `focus-trap.ts`
88

9-
Mock implementation of the `focus-trap` library for testing in jsdom environments.
9+
Mock implementation of the `focus-trap` library for testing in DOM test environments.
1010

1111
**Why this mock is needed:**
1212

13-
- The real `focus-trap` library uses tabbable element detection that doesn't work properly in jsdom
13+
- The real `focus-trap` library uses tabbable element detection that doesn't work properly in test environments
1414
- Tests fail with "Your focus-trap must have at least one container with at least one tabbable node" errors
1515
- This mock provides simplified focus-trap behavior that works reliably in test environments
1616

test/__mocks__/focus-trap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Mock implementation of focus-trap for testing
33
*
4-
* This mock provides a simplified version of focus-trap that works in jsdom environments
4+
* This mock provides a simplified version of focus-trap that works in test environments
55
* where the library's tabbable element detection doesn't work properly.
66
*
77
* **Reusability:**

0 commit comments

Comments
 (0)