Repository navigation
Expand file tree
/
Copy pathsupport.ts
More file actions
86 lines (82 loc) · 3.1 KB
/
Copy pathsupport.ts
File metadata and controls
86 lines (82 loc) · 3.1 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import "./commands";
import { takeSnapshot } from "./takeSnapshot";
import { type CypressSnapshot } from "./types";
const buildChromaticParams = (expose: Cypress.Cypress["expose"]) => ({
...(expose("diffThreshold") && {
diffThreshold: expose("diffThreshold"),
}),
...(expose("delay") && { delay: expose("delay") }),
...(expose("diffIncludeAntiAliasing") && {
diffIncludeAntiAliasing: expose("diffIncludeAntiAliasing"),
}),
...(expose("diffThreshold") && {
diffThreshold: expose("diffThreshold"),
}),
...(expose("forcedColors") && { forcedColors: expose("forcedColors") }),
...(expose("pauseAnimationAtEnd") && {
pauseAnimationAtEnd: expose("pauseAnimationAtEnd"),
}),
...(expose("prefersReducedMotion") && {
prefersReducedMotion: expose("prefersReducedMotion"),
}),
...(expose("cropToViewport") && {
cropToViewport: expose("cropToViewport"),
}),
...(expose("ignoreSelectors") && {
ignoreSelectors: expose("ignoreSelectors"),
}),
});
// these client-side lifecycle hooks will be added to the user's Cypress suite
beforeEach(() => {
// don't take snapshots when running `cypress open`
if (!Cypress.config("isTextTerminal")) {
return;
}
// this "manualSnapshots" variable will be available before, during, and after the test,
// then cleaned up before the next test is run
// (see https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Aliases)
cy.wrap([]).as("manualSnapshots");
cy.task("prepareArchives", {
action: "setup-network-listener",
payload: { allowedDomains: Cypress.expose("assetDomains") },
});
});
afterEach(() => {
// don't take snapshots when running `cypress open`
if (!Cypress.config("isTextTerminal")) {
return;
}
cy.window().then((win) => {
const viewport = { width: win.innerWidth, height: win.innerHeight };
const colorScheme = win.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
// can we be sure this always fires after all the requests are back?
cy.document().then((doc) => {
cy.wrap(takeSnapshot(doc, viewport, colorScheme)).then(
(automaticSnapshot: CypressSnapshot) => {
cy.get("@manualSnapshots").then((manualSnapshots = []) => {
cy.url().then((url) => {
// pass the snapshot to the server to write to disk
cy.task("prepareArchives", {
action: "save-archives",
payload: {
testTitlePath: [
// @ts-expect-error relativeToCommonRoot is on spec (but undocumented)
Cypress.spec.relativeToCommonRoot,
...Cypress.currentTest.titlePath,
],
domSnapshots: [
...manualSnapshots,
...(automaticSnapshot ? [automaticSnapshot] : []),
],
chromaticStorybookParams: buildChromaticParams(Cypress.expose.bind(Cypress)),
pageUrl: url,
outputDir: Cypress.config("downloadsFolder"),
},
});
});
});
},
);
});
});
});