Skip to content

Commit 0ef968b

Browse files
committed
test: add test
1 parent 373613e commit 0ef968b

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { page } from '@vitest/browser/context';
2+
import { afterEach, expect, test } from 'vitest';
3+
4+
afterEach(() => {
5+
document.body.innerHTML = ''
6+
})
7+
8+
test('click', async () => {
9+
document.body.innerHTML = '<div><span>hello</span></div>'
10+
await page.getByText('world').click()
11+
})
12+
13+
test('element', async () => {
14+
document.body.innerHTML = '<div><span>hello</span></div>'
15+
await expect.element(page.getByText('world')).toBeVisible()
16+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { fileURLToPath } from 'node:url'
2+
import { defineConfig } from 'vitest/config'
3+
4+
const provider = process.env.PROVIDER || 'playwright'
5+
const name =
6+
process.env.BROWSER || (provider === 'playwright' ? 'chromium' : 'chrome')
7+
8+
export default defineConfig({
9+
cacheDir: fileURLToPath(new URL("./node_modules/.vite", import.meta.url)),
10+
test: {
11+
browser: {
12+
enabled: true,
13+
provider,
14+
name,
15+
providerOptions: {
16+
context: {
17+
actionTimeout: 500
18+
}
19+
}
20+
},
21+
expect: {
22+
poll: {
23+
timeout: 500
24+
}
25+
}
26+
},
27+
})

test/browser/specs/runner.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readFile } from 'node:fs/promises'
22
import { beforeAll, describe, expect, onTestFailed, test } from 'vitest'
3-
import { browser, runBrowserTests } from './utils'
3+
import { browser, provider, runBrowserTests } from './utils'
44

55
describe('running browser tests', async () => {
66
let stderr: string
@@ -153,3 +153,16 @@ test('user-event', async () => {
153153
}
154154
`)
155155
})
156+
157+
test('timeout', async () => {
158+
const { stderr } = await runBrowserTests({
159+
root: './fixtures/timeout',
160+
})
161+
expect(stderr).toContain('Matcher did not succeed in 500ms')
162+
if (provider === 'playwright') {
163+
expect(stderr).toContain('locator.click: Timeout 500ms exceeded.')
164+
}
165+
if (provider === 'webdriverio') {
166+
expect(stderr).toContain('Cannot find element with locator')
167+
}
168+
})

0 commit comments

Comments
 (0)