-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.spec.ts
68 lines (57 loc) · 2.05 KB
/
template.spec.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import path from 'path'
import {execSync} from 'child_process'
import {extensionFixtures, takeScreenshot} from '../extension-fixtures'
const exampleDir = 'examples/content-react'
const pathToExtension = path.join(__dirname, `dist/chrome`)
const test = extensionFixtures(pathToExtension, true)
test.beforeAll(async () => {
execSync(`pnpm extension build ${exampleDir}`, {
cwd: path.join(__dirname, '..')
})
})
test('should exist an element with the class name extension-root', async ({
page
}) => {
await page.goto('https://extension.js.org/')
const div = page.locator('#extension-root')
await test.expect(div).toBeVisible()
})
test('should exist an h2 element with specified content', async ({page}) => {
await page.goto('https://extension.js.org/')
const h2 = page.locator('#extension-root h2')
await test.expect(h2).toContainText('This is a content script')
})
test('should exist a default color value', async ({page}) => {
await page.goto('https://extension.js.org/')
const h2 = page.locator('#extension-root h2')
const color = await page.evaluate(
(locator) => {
return window.getComputedStyle(locator!).getPropertyValue('color')
},
await h2.elementHandle()
)
await test.expect(color).toEqual('rgb(255, 255, 255)')
})
test('should load all images successfully', async ({page}) => {
await page.goto('https://extension.js.org/')
const images = page.locator('#extension-root img')
const imageElements = await images.all()
const results: boolean[] = []
for (const image of imageElements) {
const naturalWidth = await page.evaluate(
(img) => {
return img ? (img as HTMLImageElement).naturalWidth : 0
},
await image.elementHandle()
)
const naturalHeight = await page.evaluate(
(img) => {
return img ? (img as HTMLImageElement).naturalHeight : 0
},
await image.elementHandle()
)
const loadedSuccessfully = naturalWidth > 0 && naturalHeight > 0
results.push(loadedSuccessfully)
}
await test.expect(results.every((result) => result)).toBeTruthy()
})