Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

percy-seleniumjs

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

percy-seleniumjs - npm Package Compare versions

Comparing version 0.1.0-alpha.1 to 0.1.0-alpha.2

82

lib/fileSystemAssetLoader.js

@@ -1,37 +0,25 @@

"use strict";
// This is a clone of
// https://github.com/percy/percy-webdriverio/blob/master/src/fileSystemAssetLoader.js
exports.__esModule = true;
exports.default = void 0;
import fs from 'fs';
import path from 'path';
import mime from 'mime-types';
import walk from 'walk';
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _mimeTypes = _interopRequireDefault(require("mime-types"));
var _walk = _interopRequireDefault(require("walk"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This is a clone of
// https://github.com/percy/percy-webdriverio/blob/master/src/fileSystemAssetLoader.js
const MAX_FILE_SIZE_BYTES = 15728640;
const DEFAULT_SKIPPED_ASSETS = [];
class FileSystemAssetLoader {
export default class FileSystemAssetLoader {
constructor(options) {
this.options = options;
this.options.skippedAssets = this.options.skippedAssets || DEFAULT_SKIPPED_ASSETS;
this.options.skippedAssets =
this.options.skippedAssets || DEFAULT_SKIPPED_ASSETS;
}
findBuildResources(percyClient) {
return new Promise((resolve, reject) => {
const {
options
} = this;
const {
buildDir
} = options;
let mountPath = `${options.mountPath || ''}`; // Only add a / to the mountPath if it doesn't already end in one.
const { options } = this;
const { buildDir } = options;
let mountPath = `${options.mountPath || ''}`;
// Only add a / to the mountPath if it doesn't already end in one.
if (mountPath.slice(-1) !== '/') {

@@ -42,5 +30,4 @@ mountPath += '/';

let isDirectory = false;
try {
isDirectory = _fs.default.statSync(buildDir).isDirectory();
isDirectory = fs.statSync(buildDir).isDirectory();
} catch (err) {

@@ -54,12 +41,9 @@ reject(err);

let errors;
_walk.default.walkSync(buildDir, {
walk.walkSync(buildDir, {
followLinks: true,
listeners: {
file: function file(root, fileStats, next) {
const absolutePath = _path.default.join(root, fileStats.name);
const absolutePath = path.join(root, fileStats.name);
let resourceUrl = absolutePath;
if (_path.default.sep === '\\') {
if (path.sep === '\\') {
// Windows: transform filesystem backslashes into forward-slashes for the URL.

@@ -81,16 +65,18 @@ resourceUrl = resourceUrl.replace(/\\/g, '/');

}
if (_fs.default.statSync(absolutePath).size > MAX_FILE_SIZE_BYTES) {
if (fs.statSync(absolutePath).size > MAX_FILE_SIZE_BYTES) {
// eslint-disable-next-line no-console
console.warn('\n[percy][WARNING] Skipping large file: ', resourceUrl);
console.warn(
'\n[percy][WARNING] Skipping large file: ',
resourceUrl,
);
return;
}
const content = _fs.default.readFileSync(absolutePath);
resources.push(percyClient.makeResource({
resourceUrl: encodeURI(`${mountPath}${resourceUrl}`),
content,
mimetype: _mimeTypes.default.lookup(resourceUrl)
}));
const content = fs.readFileSync(absolutePath);
resources.push(
percyClient.makeResource({
resourceUrl: encodeURI(`${mountPath}${resourceUrl}`),
content,
mimetype: mime.lookup(resourceUrl),
}),
);
next();

@@ -101,6 +87,5 @@ },

next();
}
}
},
},
});
if (resources.length === 0 && errors) {

@@ -116,5 +101,2 @@ reject(errors);

}
}
exports.default = FileSystemAssetLoader;

@@ -1,25 +0,15 @@

"use strict";
import PercyClient from 'percy-client';
exports.__esModule = true;
exports.default = void 0;
import FileSystemAssetLoader from './fileSystemAssetLoader';
var _percyClient = _interopRequireDefault(require("percy-client"));
var _fileSystemAssetLoader = _interopRequireDefault(require("./fileSystemAssetLoader"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class PercySeleniumClient {
constructor({
driver,
assetLoaderOpts,
...clientOptions
}) {
this.percyClient = new _percyClient.default({
export default class PercySeleniumClient {
constructor({ driver, assetLoaderOpts, ...clientOptions }) {
this.percyClient = new PercyClient({
token: process.env.PERCY_TOKEN,
apIUrl: process.env.PERCY_API,
clientInfo: 'percy-seleniumjs',
...clientOptions
...clientOptions,
});
this.assetLoader = new _fileSystemAssetLoader.default(assetLoaderOpts);
this.assetLoader = new FileSystemAssetLoader(assetLoaderOpts);
this.driver = driver;

@@ -29,3 +19,9 @@ }

parseMissingResources(response) {
return response.body.data && response.body.data.relationships && response.body.data.relationships['missing-resources'] && response.body.data.relationships['missing-resources'].data || [];
return (
(response.body.data &&
response.body.data.relationships &&
response.body.data.relationships['missing-resources'] &&
response.body.data.relationships['missing-resources'].data) ||
[]
);
}

@@ -35,17 +31,25 @@

const missingResources = this.parseMissingResources(response);
return Promise.all(missingResources.map(missingResource => this.percyClient.uploadResource(this.buildId, shaToResource[missingResource.id].content)));
return Promise.all(
missingResources.map(missingResource =>
this.percyClient.uploadResource(
this.buildId,
shaToResource[missingResource.id].content,
),
),
);
}
async createBuild() {
const resources = await this.assetLoader.findBuildResources(this.percyClient);
const buildResponse = await this.percyClient.createBuild({
resources
});
const resources = await this.assetLoader.findBuildResources(
this.percyClient,
);
const buildResponse = await this.percyClient.createBuild({ resources });
this.buildId = buildResponse.body.data.id;
const shaToResource = {};
for (const resource of resources) {
shaToResource[resource.sha] = resource;
}
await this.uploadMissingResources(buildResponse, shaToResource);

@@ -60,5 +64,9 @@ }

isRoot: true,
mimetype: 'text/html'
mimetype: 'text/html',
});
const snapshotResponse = await this.percyClient.createSnapshot(this.buildId, [rootResource], options);
const snapshotResponse = await this.percyClient.createSnapshot(
this.buildId,
[rootResource],
options,
);
const snapshotId = snapshotResponse.body.data.id;

@@ -74,5 +82,2 @@ const shaToResource = {};

}
}
exports.default = PercySeleniumClient;
{
"name": "percy-seleniumjs",
"version": "0.1.0-alpha.1",
"version": "0.1.0-alpha.2",
"description": "Unofficial SeleniumJS SDK for Percy. Works with Protractor too.",
"main": "lib/index.js",
"scripts": {
"build": "rimraf lib/* && babel src --out-dir lib --delete-dir-on-start",
"lint": "eslint ."

@@ -21,2 +20,5 @@ },

},
"engines": {
"node": ">=10.0.0"
},
"prettier": {

@@ -44,12 +46,6 @@ "printWidth": 79,

"devDependencies": {
"@4c/babel-preset-4catalyzer": "^3.1.1",
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.6",
"@babel/node": "^7.0.0",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.4",
"eslint": "^5.6.1",
"eslint-config-4catalyzer": "^0.4.4",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-babel": "^5.2.1",
"eslint-plugin-import": "^2.14.0",

@@ -56,0 +52,0 @@ "eslint-plugin-prettier": "^3.0.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc