-
Notifications
You must be signed in to change notification settings - Fork 2
/
percy.snapshot.list.js
43 lines (38 loc) · 1.25 KB
/
percy.snapshot.list.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
const getDeploymentTestUrls = require("./src/common-lib/urls/getDeploymentTestUrls");
/**
* Generate a list of snapshot configs for use with `percy snapshot`
* https://docs.percy.io/docs/percy-snapshot#configuration
*/
const baseUrl = process.env.PERCY_BASE_URL;
if (!baseUrl) {
throw new TypeError("process.env.PERCY_BASE_URL must be defined");
}
console.log("Percy base url:", baseUrl);
// Support single string relative URLs, or objects with a `url` key.
// https://docs.percy.io/docs/percy-snapshot#configuration
// Make Percy wait for the Next app to load.
const snapshotRelativeUrls = getDeploymentTestUrls().map((url) => {
/** @type {import('@percy/core/types/index').SnapshotOptions} */
const snapshotConfig = {
url,
// Wait for the Next app to load.
waitForSelector: `#__next:not(:has([data-testid="loading"]))`,
// waitForTimeout: 3000,
};
return snapshotConfig;
});
const urls = snapshotRelativeUrls.map((relUrl) => {
if (typeof relUrl === "string") {
const url = new URL(relUrl, baseUrl).href;
return { name: relUrl, url };
} else {
const url = new URL(relUrl.url, baseUrl).href;
return {
// Pass through any fancy config.
...relUrl,
name: relUrl.url,
url,
};
}
});
module.exports = urls;