Skip to content

Commit c8dbc91

Browse files
committed
test: try to address flakiness
1 parent 98b96a2 commit c8dbc91

3 files changed

Lines changed: 17 additions & 30 deletions

File tree

test/nuxt/composables/use-install-command.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ describe('useInstallCommand', () => {
261261

262262
describe('copyInstallCommand', () => {
263263
it('should copy command to clipboard and set copied state', async () => {
264+
vi.useFakeTimers()
265+
264266
const { copyInstallCommand, copied, fullInstallCommand } = useInstallCommand(
265267
'vue',
266268
null,
@@ -276,9 +278,11 @@ describe('useInstallCommand', () => {
276278
// useClipboard sets copied to true after successful copy
277279
expect(copied.value).toBe(true)
278280

279-
// Wait for the timeout to reset copied (copiedDuring: 2000)
280-
await new Promise(resolve => setTimeout(resolve, 2100))
281+
// Advance timers to reset copied (copiedDuring: 2000)
282+
await vi.advanceTimersByTimeAsync(2100)
281283
expect(copied.value).toBe(false)
284+
285+
vi.useRealTimers()
282286
})
283287

284288
it('should not copy when command is empty', async () => {

tests/create-command.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ test.describe('Create Command', () => {
111111
const clipboardContent = await page.evaluate(() => navigator.clipboard.readText())
112112
expect(clipboardContent).toMatch(/create vite/i)
113113

114-
// After timeout, should revert to "copy"
115-
await page.waitForTimeout(2500)
116-
await expect(copyButton).toContainText(/copy/i)
114+
await expect(copyButton).toContainText(/copy/i, { timeout: 5000 })
117115
await expect(copyButton).not.toContainText(/copied/i)
118116
})
119117
})
@@ -162,9 +160,7 @@ test.describe('Create Command', () => {
162160
const clipboardContent = await page.evaluate(() => navigator.clipboard.readText())
163161
expect(clipboardContent).toMatch(/install lodash|add lodash/i)
164162

165-
// After timeout, should revert to "copy"
166-
await page.waitForTimeout(2500)
167-
await expect(copyButton).toContainText(/copy/i)
163+
await expect(copyButton).toContainText(/copy/i, { timeout: 5000 })
168164
await expect(copyButton).not.toContainText(/copied/i)
169165
})
170166
})

tests/docs.spec.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,11 @@ test.describe('API Documentation Pages', () => {
105105

106106
test.describe('Version Selector', () => {
107107
test('version selector dropdown shows versions', async ({ page, goto }) => {
108-
await goto('/docs/ufo/v/1.6.3', { waitUntil: 'networkidle' })
108+
await goto('/docs/ufo/v/1.6.3', { waitUntil: 'hydration' })
109109

110-
// Find and click the version selector button
110+
// Find and click the version selector button (wait for it to be visible)
111111
const versionButton = page.locator('header button').filter({ hasText: '1.6.3' })
112-
113-
// Skip if version selector not present (data might not be loaded)
114-
if (!(await versionButton.isVisible())) {
115-
test.skip()
116-
return
117-
}
112+
await expect(versionButton).toBeVisible({ timeout: 10000 })
118113

119114
await versionButton.click()
120115

@@ -128,16 +123,11 @@ test.describe('Version Selector', () => {
128123
})
129124

130125
test('selecting a version navigates to that version', async ({ page, goto }) => {
131-
await goto('/docs/ufo/v/1.6.3', { waitUntil: 'networkidle' })
126+
await goto('/docs/ufo/v/1.6.3', { waitUntil: 'hydration' })
132127

133-
// Find and click the version selector button
128+
// Find and click the version selector button (wait for it to be visible)
134129
const versionButton = page.locator('header button').filter({ hasText: '1.6.3' })
135-
136-
// Skip if version selector not present
137-
if (!(await versionButton.isVisible())) {
138-
test.skip()
139-
return
140-
}
130+
await expect(versionButton).toBeVisible({ timeout: 10000 })
141131

142132
await versionButton.click()
143133

@@ -167,14 +157,11 @@ test.describe('Version Selector', () => {
167157
})
168158

169159
test('escape key closes version dropdown', async ({ page, goto }) => {
170-
await goto('/docs/ufo/v/1.6.3', { waitUntil: 'networkidle' })
160+
await goto('/docs/ufo/v/1.6.3', { waitUntil: 'hydration' })
171161

162+
// Wait for version button to be visible
172163
const versionButton = page.locator('header button').filter({ hasText: '1.6.3' })
173-
174-
if (!(await versionButton.isVisible())) {
175-
test.skip()
176-
return
177-
}
164+
await expect(versionButton).toBeVisible({ timeout: 10000 })
178165

179166
await versionButton.click()
180167

0 commit comments

Comments
 (0)