Skip to content

Commit

Permalink
fix: change default timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Jan 11, 2025
1 parent 7fcdfe1 commit 43fc2ce
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 12 deletions.
20 changes: 20 additions & 0 deletions .changeset/slow-colts-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"storybook-addon-vis": patch
"vitest-plugin-vis": patch
---

Change default timeout to 30s.
The initial timeout of 1s was set by Vitest.
It is causing tests to fail with `TimeoutError`,
even when getting `Locator` like `getByRole`.

This timeout will be removed in Vitest 3.

The underlying provider (`playwright`) does not have a default timeout.

Setting to 30s should be a good default for most cases.

It could still be too short for slow CI or when it is running scripts in parallel.
That was the case for `storybook-test-runner` but could be improved in Vitest browser mode.

If timeout is still an issue, we can further default it to 60s or even 120s.
2 changes: 1 addition & 1 deletion packages/storybook-addon-vis/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default defineConfig({
diffOptions: undefined,
failureThresholdType: 'pixel',
failureThreshold: 0,
timeout: 5000 // 30000 on CI
timeout: 30000
})
],
})
Expand Down
6 changes: 3 additions & 3 deletions packages/vitest-plugin-vis/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default defineConfig({
diffOptions: undefined,
failureThresholdType: 'pixel',
failureThreshold: 0,
timeout: 5000 // 30000 on CI
timeout: 30000
})
],
test:{
Expand Down Expand Up @@ -191,7 +191,7 @@ setAutoSnapshotOptions({
diffOptions: { threshold: 0.01 },
failureThreshold: 0.01,
failureThresholdType: 'percent',
timeout: 15000
timeout: 60000
})
```

Expand Down Expand Up @@ -244,7 +244,7 @@ it('manual snapshot with options', async () => {
diffOptions: {
threshold: 0.1
},
timeout: 15000
timeout: 60000
})
})
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dedent from 'dedent'
import ci from 'is-ci'
import { resolve } from 'pathe'
import { PNG } from 'pngjs'
import type { BrowserCommand } from 'vitest/node'
Expand Down Expand Up @@ -41,7 +40,7 @@ export const matchImageSnapshot: BrowserCommand<

// vitest:browser passes in `null` when not defined
if (!options) options = {}
options.timeout = options.timeout ?? (ci ? 30000 : 5000)
options.timeout = options.timeout ?? 30000

const info = visContext.getSnapshotInfo(context.testPath, taskId, options)
const baselineBuffer = await file.tryReadFile(info.baselinePath)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ci from 'is-ci'
import type { BrowserCommand } from 'vitest/node'
import { isBase64String } from '../../shared/base64.ts'
import type {
Expand Down Expand Up @@ -39,7 +38,7 @@ export const prepareImageSnapshotComparison: BrowserCommand<

// vitest:browser passes in `null` when not defined
if (!options) options = {}
options.timeout = options.timeout ?? (ci ? 30000 : 5000)
options.timeout = options.timeout ?? 30000

const info = visContext.getSnapshotInfo(context.testPath, taskId, options)
const baselineBuffer = await file.tryReadFile(info.baselinePath)
Expand Down
1 change: 0 additions & 1 deletion packages/vitest-plugin-vis/src/server/vis_context.ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { rimraf } from 'rimraf'
export const ctx = {
rimraf,
getSnapshotPlatform() {
/* v8 ignore next */
return ci ? process.platform : 'local'
},
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest-plugin-vis/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ImageSnapshotTimeoutOptions {
/**
* Timeout for taking the snapshot.
*
* Default: 5000 ms locally, 30000 ms on CI.
* Default: 30000 ms (30 seconds)
*/
timeout?: number | undefined
}
Expand Down
2 changes: 1 addition & 1 deletion testcases/vpv/src/to_match_image_snapshot.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ it('uses options set in vis()', async () => {
(error) => {
expect(error.message).toMatch(
`Options: failureThreshold: 0.01 percent
timeout: 15000 ms
timeout: 60000 ms
comparisonMethod: ssim
diffOptions: {\"ssim\":\"bezkrovny\"}`,
)
Expand Down
2 changes: 1 addition & 1 deletion testcases/vpv/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
diffOptions: { ssim: 'bezkrovny' },
failureThreshold: 0.01,
failureThresholdType: 'percent',
timeout: 15000,
timeout: 60000,
}),
],
test: {
Expand Down

0 comments on commit 43fc2ce

Please sign in to comment.