@percy/core 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +94 -0
- package/dist/browser.js +292 -0
- package/dist/config.js +551 -0
- package/dist/discovery.js +118 -0
- package/dist/index.js +5 -0
- package/dist/install.js +156 -0
- package/dist/network.js +298 -0
- package/dist/page.js +264 -0
- package/dist/percy.js +484 -0
- package/dist/queue.js +152 -0
- package/dist/server.js +430 -0
- package/dist/session.js +103 -0
- package/dist/snapshot.js +433 -0
- package/dist/utils.js +127 -0
- package/package.json +11 -11
- package/post-install.js +20 -0
- package/test/helpers/dedent.js +27 -0
- package/test/helpers/index.js +34 -0
- package/test/helpers/request.js +15 -0
- package/test/helpers/server.js +33 -0
- package/types/index.d.ts +101 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export async function request(url, method = 'GET', handle) {
|
|
2
|
+
if (typeof method === 'boolean' || typeof method === 'function') [handle, method] = [method, 'GET'];
|
|
3
|
+
let cb = typeof handle === 'boolean' ? (handle ? (...a) => a : (_, r) => r) : handle;
|
|
4
|
+
let options = typeof method === 'string' ? { method } : method;
|
|
5
|
+
let { request } = await import('@percy/client/utils');
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
return await request(url, options, cb);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (typeof handle !== 'boolean') throw error;
|
|
11
|
+
return handle ? [error.response.body, error.response] : error.response;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default request;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// aliased to src for coverage during tests without needing to compile this file
|
|
2
|
+
import Server from '../../dist/server.js';
|
|
3
|
+
|
|
4
|
+
export function createTestServer({ default: defaultReply, ...replies }, port = 8000) {
|
|
5
|
+
let server = new Server();
|
|
6
|
+
|
|
7
|
+
// alternate route handling
|
|
8
|
+
let handleReply = reply => async (req, res) => {
|
|
9
|
+
let [status, headers, body] = typeof reply === 'function' ? await reply(req) : reply;
|
|
10
|
+
if (!Buffer.isBuffer(body) && typeof body !== 'string') body = JSON.stringify(body);
|
|
11
|
+
return res.send(status, headers, body);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// map replies to alternate route handlers
|
|
15
|
+
server.reply = (p, reply) => (replies[p] = handleReply(reply), null);
|
|
16
|
+
for (let [p, reply] of Object.entries(replies)) server.reply(p, reply);
|
|
17
|
+
if (defaultReply) defaultReply = handleReply(defaultReply);
|
|
18
|
+
|
|
19
|
+
// track requests and route replies
|
|
20
|
+
server.requests = [];
|
|
21
|
+
server.route(async (req, res, next) => {
|
|
22
|
+
let pathname = req.url.pathname;
|
|
23
|
+
if (req.url.search) pathname += req.url.search;
|
|
24
|
+
server.requests.push(req.body ? [pathname, req.body] : [pathname]);
|
|
25
|
+
let reply = replies[req.url.pathname] || defaultReply;
|
|
26
|
+
return reply ? await reply(req, res) : next();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// automatically listen
|
|
30
|
+
return server.listen(port);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default createTestServer;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// utility types
|
|
2
|
+
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
|
|
3
|
+
type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
|
|
4
|
+
|
|
5
|
+
type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'silent';
|
|
6
|
+
|
|
7
|
+
interface Pojo {
|
|
8
|
+
[x: string]: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface AuthCredentials {
|
|
12
|
+
username: string;
|
|
13
|
+
password: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface DiscoveryOptions {
|
|
17
|
+
requestHeaders?: Pojo;
|
|
18
|
+
authorization?: AuthCredentials;
|
|
19
|
+
allowedHostnames?: string[];
|
|
20
|
+
disableCache?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface DiscoveryLaunchOptions {
|
|
24
|
+
executable?: string;
|
|
25
|
+
args?: string[];
|
|
26
|
+
timeout?: number;
|
|
27
|
+
headless?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface AllDiscoveryOptions extends DiscoveryOptions {
|
|
31
|
+
networkIdleTimeout?: number;
|
|
32
|
+
concurrency?: number;
|
|
33
|
+
launchOptions?: DiscoveryLaunchOptions;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface CommonSnapshotOptions {
|
|
37
|
+
widths?: number[];
|
|
38
|
+
minHeight?: number;
|
|
39
|
+
percyCSS?: string;
|
|
40
|
+
enableJavaScript?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SnapshotOptions extends CommonSnapshotOptions {
|
|
44
|
+
discovery?: DiscoveryOptions;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type ClientEnvInfo = {
|
|
48
|
+
clientInfo?: string,
|
|
49
|
+
environmentInfo?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type PercyConfigOptions<C = Pojo> = C & {
|
|
53
|
+
snapshot?: CommonSnapshotOptions,
|
|
54
|
+
discovery?: AllDiscoveryOptions
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type PercyOptions<C = Pojo> = {
|
|
58
|
+
token?: string,
|
|
59
|
+
server?: boolean,
|
|
60
|
+
port?: number,
|
|
61
|
+
concurrency?: number,
|
|
62
|
+
loglevel?: LogLevel,
|
|
63
|
+
config?: undefined | string | false
|
|
64
|
+
} & ClientEnvInfo & PercyConfigOptions<C>;
|
|
65
|
+
|
|
66
|
+
type SnapshotExec = () => void | Promise<void>;
|
|
67
|
+
|
|
68
|
+
type AdditionalSnapshot = (XOR<XOR<
|
|
69
|
+
{ name: string },
|
|
70
|
+
{ prefix: string, suffix?: string }>,
|
|
71
|
+
{ suffix: string, prefix?: string }>
|
|
72
|
+
) & { execute: SnapshotExec };
|
|
73
|
+
|
|
74
|
+
declare class Percy {
|
|
75
|
+
static start(options?: PercyOptions): Promise<Percy>;
|
|
76
|
+
constructor(options?: PercyOptions);
|
|
77
|
+
loglevel(): LogLevel;
|
|
78
|
+
loglevel(level: LogLevel): void;
|
|
79
|
+
config: PercyConfigOptions;
|
|
80
|
+
setConfig(config: ClientEnvInfo & PercyConfigOptions): PercyConfigOptions;
|
|
81
|
+
start(): Promise<void>;
|
|
82
|
+
stop(force?: boolean): Promise<void>;
|
|
83
|
+
idle(): Promise<void>;
|
|
84
|
+
close(): void;
|
|
85
|
+
|
|
86
|
+
snapshot(options: {
|
|
87
|
+
url: string,
|
|
88
|
+
name?: string,
|
|
89
|
+
clientInfo?: string,
|
|
90
|
+
environmentInfo?: string
|
|
91
|
+
} & XOR<{
|
|
92
|
+
domSnapshot: string
|
|
93
|
+
}, {
|
|
94
|
+
waitForTimeout?: number,
|
|
95
|
+
waitForSelector?: string,
|
|
96
|
+
execute?: SnapshotExec,
|
|
97
|
+
additionalSnapshots?: AdditionalSnapshot[]
|
|
98
|
+
}> & SnapshotOptions): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default Percy;
|