-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
51 lines (44 loc) · 1.21 KB
/
jest.setup.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
import { paramCase } from 'change-case'
import {
classNames,
css,
definitions,
matchers,
injectPage,
styleOf,
takeScreenshot,
} from './jest-env'
const screenshotIfDebug = (...args) => {
// Taking screenshots only in the debug mode to seed up testing in general
//
// On MacOS, taking the screenshot gets at least 1/6s what could be quite
// long if the number of tests increases
//
// See more:
// https://pptr.dev/#?product=Puppeteer&version=v12.0.1&show=api-pagescreenshotoptions
if (!process.env.DEBUG || process.env.DEBUG === 'false') {
return
}
return takeScreenshot(...args)
}
const injectPageWithScreenshot = async (contentOrOptions, options) => {
const resolvedOptions = typeof contentOrOptions == 'string'
? { body: contentOrOptions, ...options }
: { ...contentOrOptions, ...options }
const {
screenshot: fileName = paramCase(expect.getState().currentTestName),
...passOptions
} = resolvedOptions
await injectPage(passOptions)
await screenshotIfDebug(fileName)
}
Object.assign(global, {
...definitions,
classNames,
css,
useVar: css.useVar,
styleOf,
injectPage: injectPageWithScreenshot,
takeScreenshot: screenshotIfDebug,
})
expect.extend(matchers)