@percy/core 1.0.0-beta.8 → 1.0.1
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/README.md +226 -67
- package/dist/api.js +94 -0
- package/dist/browser.js +292 -0
- package/dist/config.js +512 -30
- package/dist/discovery.js +118 -0
- package/dist/index.js +5 -29
- package/dist/install.js +156 -0
- package/dist/network.js +298 -0
- package/dist/page.js +264 -0
- package/dist/percy.js +373 -306
- package/dist/queue.js +122 -73
- package/dist/server.js +424 -76
- package/dist/session.js +103 -0
- package/dist/snapshot.js +433 -0
- package/dist/utils.js +127 -0
- package/package.json +42 -28
- package/post-install.js +20 -0
- package/test/helpers/server.js +33 -0
- package/types/index.d.ts +69 -39
- package/dist/discoverer.js +0 -367
- package/dist/percy-css.js +0 -33
- package/dist/utils/assert.js +0 -50
- package/dist/utils/bytes.js +0 -24
- package/dist/utils/idle.js +0 -15
- package/dist/utils/install-browser.js +0 -76
- package/dist/utils/resources.js +0 -75
- package/dist/utils/url.js +0 -64
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = maybeInstallBrowser;
|
|
7
|
-
|
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
-
|
|
10
|
-
var _puppeteerCore = _interopRequireDefault(require("puppeteer-core"));
|
|
11
|
-
|
|
12
|
-
var _logger = _interopRequireDefault(require("@percy/logger"));
|
|
13
|
-
|
|
14
|
-
var _bytes = _interopRequireDefault(require("./bytes"));
|
|
15
|
-
|
|
16
|
-
var _revisions = require("puppeteer-core/lib/cjs/puppeteer/revisions");
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
// Get the default revisions from within puppeteer
|
|
21
|
-
// If the default Chromium revision is not yet downloaded, download it. Lazily
|
|
22
|
-
// requires the progress package to print a progress bar during the download.
|
|
23
|
-
async function maybeInstallBrowser(path = process.env.PUPPETEER_EXECUTABLE_PATH) {
|
|
24
|
-
let revision = process.env.PUPPETEER_CHROMIUM_REVISION || _revisions.PUPPETEER_REVISIONS.chromium;
|
|
25
|
-
let local = false;
|
|
26
|
-
|
|
27
|
-
if (path) {
|
|
28
|
-
if (!_fs.default.existsSync(path)) {
|
|
29
|
-
_logger.default.error(`Puppeteer executable path not found: ${path}`);
|
|
30
|
-
} else {
|
|
31
|
-
return path;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let fetcher = _puppeteerCore.default.createBrowserFetcher();
|
|
36
|
-
|
|
37
|
-
({
|
|
38
|
-
executablePath: path,
|
|
39
|
-
local,
|
|
40
|
-
revision
|
|
41
|
-
} = fetcher.revisionInfo(revision));
|
|
42
|
-
|
|
43
|
-
if (!local) {
|
|
44
|
-
let ProgressBar = require('progress');
|
|
45
|
-
|
|
46
|
-
let progress, last; // we always want to log this
|
|
47
|
-
|
|
48
|
-
let loglevel = _logger.default.loglevel();
|
|
49
|
-
|
|
50
|
-
_logger.default.loglevel('info');
|
|
51
|
-
|
|
52
|
-
_logger.default.info('Chromium not found, downloading...');
|
|
53
|
-
|
|
54
|
-
await fetcher.download(revision, (downloaded, total) => {
|
|
55
|
-
progress = progress || new ProgressBar(_logger.default.formatter(`Chromium r${revision} - ${(0, _bytes.default)(total)} [:bar] :percent :etas`), {
|
|
56
|
-
incomplete: ' ',
|
|
57
|
-
width: 21,
|
|
58
|
-
total,
|
|
59
|
-
stream: process.stdout
|
|
60
|
-
});
|
|
61
|
-
progress.tick(downloaded - last);
|
|
62
|
-
last = downloaded;
|
|
63
|
-
});
|
|
64
|
-
process.stdout.write('\n');
|
|
65
|
-
|
|
66
|
-
_logger.default.info('Successfully downloaded Chromium');
|
|
67
|
-
|
|
68
|
-
_logger.default.loglevel(loglevel);
|
|
69
|
-
|
|
70
|
-
({
|
|
71
|
-
executablePath: path
|
|
72
|
-
} = fetcher.revisionInfo(revision));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return path;
|
|
76
|
-
}
|
package/dist/utils/resources.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createLocalResource = createLocalResource;
|
|
7
|
-
exports.createRootResource = createRootResource;
|
|
8
|
-
exports.createLogResource = createLogResource;
|
|
9
|
-
|
|
10
|
-
var _os = _interopRequireDefault(require("os"));
|
|
11
|
-
|
|
12
|
-
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
14
|
-
var _fs = require("fs");
|
|
15
|
-
|
|
16
|
-
var _utils = require("@percy/client/dist/utils");
|
|
17
|
-
|
|
18
|
-
var _assert = _interopRequireDefault(require("./assert"));
|
|
19
|
-
|
|
20
|
-
var _bytes = _interopRequireDefault(require("./bytes"));
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
const MAX_FILE_SIZE_BYTES = 15728640; // 15mb
|
|
25
|
-
|
|
26
|
-
const TEMP_DIR = _path.default.join(_os.default.tmpdir(), 'percy'); // Creates a local resource object containing the resource URL, SHA, mimetype,
|
|
27
|
-
// and local filepath in the OS temp directory. If the file does not exist, it
|
|
28
|
-
// is created unless it exceeds the file size limit.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
function createLocalResource(url, content, mimetype, beforeWrite, meta) {
|
|
32
|
-
if (!(0, _fs.existsSync)(TEMP_DIR)) (0, _fs.mkdirSync)(TEMP_DIR);
|
|
33
|
-
let sha = (0, _utils.sha256hash)(content);
|
|
34
|
-
|
|
35
|
-
let filepath = _path.default.join(TEMP_DIR, sha);
|
|
36
|
-
|
|
37
|
-
if (!(0, _fs.existsSync)(filepath)) {
|
|
38
|
-
beforeWrite === null || beforeWrite === void 0 ? void 0 : beforeWrite();
|
|
39
|
-
(0, _assert.default)(content.length < MAX_FILE_SIZE_BYTES, 'too many bytes', {
|
|
40
|
-
size: (0, _bytes.default)(content.length),
|
|
41
|
-
...meta
|
|
42
|
-
});
|
|
43
|
-
(0, _fs.writeFileSync)(filepath, content);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
url,
|
|
48
|
-
sha,
|
|
49
|
-
filepath,
|
|
50
|
-
mimetype
|
|
51
|
-
};
|
|
52
|
-
} // Creates a root resource object containing the URL, SHA, content, and mimetype
|
|
53
|
-
// with an additional `root: true` property.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
function createRootResource(url, content) {
|
|
57
|
-
return {
|
|
58
|
-
url,
|
|
59
|
-
content,
|
|
60
|
-
sha: (0, _utils.sha256hash)(content),
|
|
61
|
-
mimetype: 'text/html',
|
|
62
|
-
root: true
|
|
63
|
-
};
|
|
64
|
-
} // Creates a log resource object.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
function createLogResource(logs) {
|
|
68
|
-
let content = JSON.stringify(logs);
|
|
69
|
-
return {
|
|
70
|
-
content,
|
|
71
|
-
url: `/percy.${Date.now()}.log`,
|
|
72
|
-
sha: (0, _utils.sha256hash)(content),
|
|
73
|
-
mimetype: 'text/plain'
|
|
74
|
-
};
|
|
75
|
-
}
|
package/dist/utils/url.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.hostname = hostname;
|
|
7
|
-
exports.normalizeURL = normalizeURL;
|
|
8
|
-
exports.domainMatch = domainMatch;
|
|
9
|
-
|
|
10
|
-
var _url = require("url");
|
|
11
|
-
|
|
12
|
-
// Returns the hostname portion of a URL.
|
|
13
|
-
function hostname(url) {
|
|
14
|
-
return new _url.URL(url).hostname;
|
|
15
|
-
} // Normalizes a URL by stripping any anchors
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function normalizeURL(url) {
|
|
19
|
-
let {
|
|
20
|
-
protocol,
|
|
21
|
-
host,
|
|
22
|
-
pathname,
|
|
23
|
-
search
|
|
24
|
-
} = new _url.URL(url);
|
|
25
|
-
return `${protocol}//${host}${pathname}${search}`;
|
|
26
|
-
} // Returns true or false if the host matches the domain. When `isWild` is true,
|
|
27
|
-
// it will also return true if the host matches end of the domain.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function domainCheck(domain, host, isWild) {
|
|
31
|
-
if (host === domain) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (isWild && host) {
|
|
36
|
-
let last = host.lastIndexOf(domain);
|
|
37
|
-
return last >= 0 && last + domain.length === host.length;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return false;
|
|
41
|
-
} // Returns true or false if `url` matches the provided domain `pattern`.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function domainMatch(pattern, url) {
|
|
45
|
-
if (pattern === '*') {
|
|
46
|
-
return true;
|
|
47
|
-
} else if (!pattern) {
|
|
48
|
-
return false;
|
|
49
|
-
} // check for wildcard patterns
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let isWild = pattern.indexOf('*.') === 0 || pattern.indexOf('*/') === 0; // get the pattern's domain and path prefix
|
|
53
|
-
|
|
54
|
-
let slashed = pattern.split('/');
|
|
55
|
-
let domain = isWild ? slashed.shift().substr(2) : slashed.shift();
|
|
56
|
-
let pathprefix = `/${slashed.join('/')}`; // parse the provided URL
|
|
57
|
-
|
|
58
|
-
let {
|
|
59
|
-
hostname,
|
|
60
|
-
pathname
|
|
61
|
-
} = new _url.URL(url); // check that the URL matches the pattern's domain and path prefix
|
|
62
|
-
|
|
63
|
-
return domainCheck(domain, hostname, isWild) && pathname.indexOf(pathprefix) === 0;
|
|
64
|
-
}
|