Innovenergy_trunk/frontend/node_modules/testcafe/lib/custom-client-scripts/client-script.js

108 lines
15 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const promisified_functions_1 = require("../utils/promisified-functions");
const runtime_1 = require("../errors/runtime");
const types_1 = require("../errors/types");
const path_1 = require("path");
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
const crypto_1 = require("crypto");
const BEAUTIFY_REGEXP = /[/.:\s\\]/g;
const BEAUTIFY_CHAR = '_';
const EMPTY_CONTENT_STR = '{ content: <empty> }';
const CONTENT_STR_MAX_LENGTH = 30;
const CONTENT_ELLIPSIS_STR = '...';
const URL_UNIQUE_PART_LENGTH = 7;
class ClientScript {
constructor(init, basePath) {
this.init = init || null;
this.url = (0, testcafe_hammerhead_1.generateUniqueId)(URL_UNIQUE_PART_LENGTH);
this.content = '';
this.path = null;
this.module = null;
this.hash = null;
this.page = testcafe_hammerhead_1.RequestFilterRule.ANY;
this.basePath = basePath;
}
_resolvePath(path) {
let resolvedPath = null;
if ((0, path_1.isAbsolute)(path))
resolvedPath = path;
else {
if (!this.basePath)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.clientScriptBasePathIsNotSpecified);
resolvedPath = (0, path_1.join)(this.basePath, path);
}
return resolvedPath;
}
async _loadFromPath(path) {
const resolvedPath = this._resolvePath(path);
try {
this.path = resolvedPath;
this.content = await (0, promisified_functions_1.readFile)(this.path);
this.content = this.content.toString();
this.url = path || this.url;
}
catch (e) {
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.cannotLoadClientScriptFromPath, path, e.message);
}
}
async _loadFromModule(name) {
let resolvedPath = null;
try {
resolvedPath = require.resolve(name);
}
catch (e) {
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.clientScriptModuleEntryPointPathCalculationError, e.message);
}
await this._loadFromPath(resolvedPath);
this.module = name;
}
_prepareUrl() {
this.url = this.url.replace(BEAUTIFY_REGEXP, BEAUTIFY_CHAR).toLowerCase();
}
async load() {
if (this.init === null)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.clientScriptInitializerIsNotSpecified);
else if (typeof this.init === 'string')
await this._loadFromPath(this.init);
else {
const { path: initPath, content: initContent, module: initModule, page: initPage } = this.init;
if (initPath && initContent || initPath && initModule || initContent && initModule)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.clientScriptInitializerMultipleContentSources);
if (initPath)
await this._loadFromPath(initPath);
else if (initModule)
await this._loadFromModule(initModule);
else
this.content = initContent;
if (initPage)
this.page = new testcafe_hammerhead_1.RequestFilterRule(initPage);
}
this._calculateHash();
this._prepareUrl();
}
_calculateHash() {
this.hash = (0, crypto_1.createHash)('md5').update(this.content).digest();
}
_contentToString() {
let displayContent;
if (this.content.length <= CONTENT_STR_MAX_LENGTH - CONTENT_ELLIPSIS_STR.length)
displayContent = this.content;
else
displayContent = this.content.substring(0, CONTENT_STR_MAX_LENGTH - CONTENT_ELLIPSIS_STR.length) + CONTENT_ELLIPSIS_STR;
return `{ content: '${displayContent}' }`;
}
toString() {
if (!this.content)
return EMPTY_CONTENT_STR;
else if (this.content && !this.path)
return this._contentToString();
return `{ path: '${this.path}' }`;
}
static get URL_UNIQUE_PART_LENGTH() {
return URL_UNIQUE_PART_LENGTH;
}
}
exports.default = ClientScript;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpZW50LXNjcmlwdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jdXN0b20tY2xpZW50LXNjcmlwdHMvY2xpZW50LXNjcmlwdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBFQUEwRDtBQUMxRCwrQ0FBaUQ7QUFDakQsMkNBQWlEO0FBQ2pELCtCQUF3QztBQUN4Qyw2REFBMEU7QUFDMUUsbUNBQW9DO0FBR3BDLE1BQU0sZUFBZSxHQUFHLFlBQVksQ0FBQ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