-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
52 lines (45 loc) · 1.17 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import test from 'ava'
import {withChrome, withDirectory, writeFile} from '../../test/helpers/index.js'
import {openTab, evalInTab} from '../../index.js'
withChrome(test)
withDirectory(test)
test('executing code within the browser', async (t) => {
const {browser} = global
const {directory} = t.context
const filePath = await writeFile(
directory,
'index.html',
`
<!doctype html>
<meta charset="utf-8">
<div id="root">Hello World!</div>
`,
)
const tab = await openTab(browser, `file://${filePath}`)
const text = await evalInTab(
tab,
['#root'],
`
const [selector] = arguments
return document.querySelector(selector).textContent
`,
)
t.is(text, 'Hello World!')
})
test('propagating error messages', async (t) => {
const {browser} = global
const {directory} = t.context
const filePath = await writeFile(
directory,
'index.html',
`
<!doctype html>
<meta charset="utf-8">
<div id="root">Hello World!</div>
`,
)
const tab = await openTab(browser, `file://${filePath}`)
await t.throwsAsync(evalInTab(tab, [], 'throw new Error("Error Message")'), {
message: /Error Message/,
})
})