-
Notifications
You must be signed in to change notification settings - Fork 0
/
mocha.js
59 lines (50 loc) · 1.26 KB
/
mocha.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
53
54
55
56
57
58
59
// Global variables for mocha.js
import { assert, expect } from 'chai'
import addContext from 'mochawesome/addContext.js'
import chromium from './chromium.js'
import Utils from './Utils.js'
import YML from './YML.js'
global.chromium = chromium
global.Utils = Utils
global.YML = YML
global.addContext = addContext
global.assert = assert
global.expect = expect
// Global variables for puppeteer/lutkar
global.browser = {}
global.page = {}
// Hooks for mocha.js
export const mochaHooks = {
beforeAll: [
async function () {
browser = await chromium()
page = await browser.newPage()
}
],
beforeEach: [
async function () {
await page.bringToFront()
}
],
afterEach: [
async function () {
if (this.currentTest.state === 'failed') {
let title = this.currentTest.title
let parent = this.currentTest.parent
while (parent && parent.title) {
title = `${parent.title} - ${title}`
parent = parent.parent
}
const pages = await browser.pages()
for (const p of pages) {
if (await p.isPageVisible()) await p.screenshot(`./screens/${title}.png`, { fullPage: true })
}
}
}
],
afterAll: [
async function () {
await browser.close()
}
]
}