Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const requestSource = async (url: string, connector: string): Promise => {
try {
if (connector === 'local') {
return await readFileAsync(asPathString(getAsUri(url)!));
}
/*
* Allow us to use our self-signed cert for testing.
* https://github.com/request/request/issues/418#issuecomment-23058601
*/
return await requestAsync({
rejectUnauthorized: false,
strictSSL: false,
url
});
} catch (e) {
// Some tests deliberately use invalid URLs (e.g. `test:`).
return '';
}
};
private async getGitIgnore() {
try {
const rawList = await readFileAsync(path.join(cwd(), '.gitignore'));
const splitList = rawList.split('\n');
const result = splitList.reduce((total: string[], ignore: string) => {
const value: string = ignore.trim();
/* istanbul ignore if */
if (!value) {
return total;
}
/* istanbul ignore if */
if (value[0] === '/') {
total.push(value.substr(1));
} else {
total.push(value);
}
const getBrowserInfo = async (): Promise => {
let result = { browserWSEndpoint: '' };
try {
result = JSON.parse((await readFileAsync(infoFile)).trim());
} catch (e) /* istanbul ignore next */ {
debug(`Error reading ${infoFile}`);
debug(e);
return null;
}
return result;
};
const getScriptsContent = async (files: string[]): Promise => {
const result: FileContent[] = [];
for (const file of files) {
const regex = /<\/script>/g;
const content = await readFileAsync(path.resolve(__dirname, 'assets', file));
result.push({
// Replace the string to avoid problems in the website.
content: content.replace(regex, ''),
file
});
}
return result;
};
const createScript = async (): Promise => {
debug('Creating script to inject');
const libraryDetector = await readFileAsync(require.resolve('js-library-detector'));
const script = `/*RunInPageContext*/
(function (){
${libraryDetector};
const libraries = Object.entries(d41d8cd98f00b204e9800998ecf8427e_LibraryDetectorTests);
const detectedLibraries = libraries.reduce((detected, [name, lib]) => {
try {
const result = lib.test(window);
if (result) {
detected.push({
name,
version: result.version,
npmPkgName: lib.npm
});
}
export const compileTemplate = async (filePath: string, data: any): Promise => {
let templateContent;
try {
templateContent = await readFileAsync(filePath);
} catch (err) {
throw (err);
}
const template = Handlebars.compile(templateContent);
return template(data);
};
import { CheckResult, AxeResults, ImpactValue, NodeResult as AxeNodeResult } from 'axe-core';
import { HTMLDocument, HTMLElement } from '@hint/utils-dom';
import { readFileAsync } from '@hint/utils-fs';
import { CanEvaluateScript } from 'hint/dist/src/lib/types';
import { HintContext } from 'hint/dist/src/lib/hint-context';
import { Severity } from '@hint/utils-types';
import { getMessage } from '../i18n.import';
const axeCorePromise = readFileAsync(require.resolve('axe-core'));
type EngineKey = object;
type Options = {
[ruleId: string]: keyof typeof Severity;
} | string[];
type Registration = {
context: HintContext;
enabledRules: string[];
options: { [ruleId: string]: keyof typeof Severity };
event: CanEvaluateScript;
};
type RegistrationMap = Map>;
export const compileTemplate = async (filePath: string, data: any): Promise => {
let templateContent;
try {
templateContent = await readFileAsync(filePath);
} catch (err) {
throw (err);
}
const template = Handlebars.compile(templateContent);
return template(data);
};