How to use testcafe-hammerhead - 10 common examples

To help you get started, we’ve selected a few testcafe-hammerhead examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DevExpress / testcafe / src / compiler / compile-client-function.js View on Github external
export default function compileClientFunction (fnCode, dependencies, instantiationCallsiteName, compilationCallsiteName) {
    if (fnCode === ASYNC_TO_GENERATOR_OUTPUT_CODE)
        throw new ClientFunctionAPIError(compilationCallsiteName, instantiationCallsiteName, RUNTIME_ERRORS.regeneratorInClientFunctionCode);

    fnCode = makeFnCodeSuitableForParsing(fnCode);

    // NOTE: we need to recompile ES6 code for the browser if we are on newer versions of Node.
    fnCode = downgradeES(fnCode);
    fnCode = hammerhead.processScript(fnCode, false);

    // NOTE: check compiled code for regenerator injection: we have either generator
    // recompiled in Node.js 4+ for client or async function declared in function code.
    if (REGENERATOR_FOOTPRINTS_RE.test(fnCode))
        throw new ClientFunctionAPIError(compilationCallsiteName, instantiationCallsiteName, RUNTIME_ERRORS.regeneratorInClientFunctionCode);

    if (!TRAILING_SEMICOLON_RE.test(fnCode))
        fnCode += ';';

    const dependenciesDefinition = dependencies ? getDependenciesDefinition(dependencies) : '';

    return addBabelArtifactsPolyfills(fnCode, dependenciesDefinition);
}
github DevExpress / testcafe / src / custom-client-scripts / client-script.ts View on Github external
await this._loadFromPath(this.init);
        else {
            const { path: initPath, content: initContent, module: initModule, page: initPage } = this.init as ClientScript;

            if (initPath && initContent || initPath && initModule || initContent && initModule)
                throw new GeneralError(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 RequestFilterRule(initPage);
        }

        this._calculateHash();
        this._prepareUrl();
    }
github DevExpress / testcafe / src / api / request-hooks / request-mock.js View on Github external
respond (body, statusCode, headers) {
        if (!this.pendingRequestFilterRuleInit)
            throw new APIError('respond', RUNTIME_ERRORS.requestHookConfigureAPIError, RequestMock.name, "The 'onRequestTo' method was not called before 'respond'. You must call the 'onRequestTo' method to provide the URL requests to which are mocked.");

        const mock = new ResponseMock(body, statusCode, headers);
        const rule = new RequestFilterRule(this.pendingRequestFilterRuleInit);

        this.requestFilterRules.push(rule);
        this.mocks.set(rule, mock);
        this.pendingRequestFilterRuleInit = null;

        return this;
    }
}
github DevExpress / testcafe / src / api / request-hooks / hook.js View on Github external
this.requestFilterRules.forEach(rule => {
            const instantiatedRule = rule instanceof RequestFilterRule ? rule : new RequestFilterRule(rule);

            this._instantiatedRequestFilterRules.push(instantiatedRule);
        });
    }
github DevExpress / testcafe / src / custom-client-scripts / utils.ts View on Github external
contentGroups.forEach(contentGroup => {
        const pageGroups = getScriptGroupValues(contentGroup as ClientScript[], (s: ClientScript) => s.page.toString());

        if (pageGroups.length === 1 && RequestFilterRule.isANY((pageGroups[0][0] as ClientScript).page)) { /*eslint-disable-line no-extra-parens*/
            duplicatedScripts.push(pageGroups[0][0] as ClientScript);

            return;
        }

        const forAllPagesGroup = pageGroups.find(pg => RequestFilterRule.isANY((pg[0] as ClientScript).page)); /*eslint-disable-line no-extra-parens*/

        if (forAllPagesGroup) {
            pageGroups
                .filter(pg => !RequestFilterRule.isANY((pg[0] as ClientScript).page)) /*eslint-disable-line no-extra-parens*/
                .forEach(pg => {
                    duplicatedScripts.push(pg[0] as ClientScript);
                });
        }
        else {
            pageGroups
github DevExpress / testcafe / src / custom-client-scripts / utils.ts View on Github external
                .filter(pg => !RequestFilterRule.isANY((pg[0] as ClientScript).page)) /*eslint-disable-line no-extra-parens*/
                .forEach(pg => {
github DevExpress / testcafe / src / custom-client-scripts / utils.ts View on Github external
        const forAllPagesGroup = pageGroups.find(pg => RequestFilterRule.isANY((pg[0] as ClientScript).page)); /*eslint-disable-line no-extra-parens*/
github DevExpress / testcafe / src / compiler / legacy / compiler.js View on Github external
Compiler.prototype._getRemainderCode = function (ast) {
    var remainderAst = Ast.getRemainderAst(ast);

    if (remainderAst) {
        CallAnalyzer.run(remainderAst, this.filename, this.errs, true, this.sourceIndex, this.src);

        if (this.ok) {
            var remainderCode = astProcessor.gen_code(remainderAst, {beautify: true});

            return Hammerhead.wrapDomAccessors(remainderCode, true);
        }
    }

    return '';
};
github DevExpress / testcafe / src / compiler / legacy / compiler.js View on Github external
Compiler.prototype._addOutputTestStepData = function (testName, testStepData) {
    var js = astProcessor.gen_code(['array', testStepData.asts], {beautify: true});

    this.out.testsStepData[testName] = {
        names: testStepData.names,
        js: Hammerhead.wrapDomAccessors(js, true)
    };
};
github DevExpress / testcafe / src / compiler / legacy / analysis / require_analyzer.js View on Github external
Ast.construct(requireFilename, ownerFilename, function (parsingErr, requireAst, srcCode) {
        if (parsingErr)
            errs.push(parsingErr);

        else if (requireAst) {
            descriptor.jsCode = srcCode;
            analyzeRequireCode(requireAst, descriptor, errs, sourceIndex);
        }

        if (!errs.length)
            descriptor.jsCode = Hammerhead.wrapDomAccessors(descriptor.jsCode, true);

        //NOTE: User can forget ';' at the end of the require js file. In this case, an js exception may occure after
        //requires merging. So we add ';' at the end of the require code manually
        if (descriptor.jsCode && descriptor.jsCode[descriptor.jsCode.length - 1] !== ';')
            descriptor.jsCode += ';';

        descriptor.hasErrs = !!errs.length;

        callback(errs, descriptor);
    });
};

testcafe-hammerhead

A powerful web-proxy used as a core for the TestCafe testing framework (https://github.com/DevExpress/testcafe).

MIT
Latest version published 4 months ago

Package Health Score

80 / 100
Full package analysis

Similar packages