Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:DevExpress Testcafe TestFileParserBase

From Leeroopedia
Knowledge Sources
Domains Compiler, Test Discovery
Last Updated 2026-02-12 12:00 GMT

Overview

TestFileParserBase is the abstract base class responsible for extracting fixture and test definitions from parsed AST (Abstract Syntax Tree) representations of test source files.

Description

TestFileParserBase lives in src/compiler/test-file/test-file-parser-base.js and provides the common infrastructure for walking AST nodes produced by different language parsers (Babel for ES-next, TypeScript compiler, CoffeeScript compiler). It defines a set of abstract methods (e.g. isAsyncFn, getRValue, getFunctionBody, analyzeFnCall, parse) that concrete subclasses must implement. Its concrete logic handles:

  • Token analysis -- the analyzeToken method dispatches on AST node type (expression statements, function declarations, variable declarations, call expressions, tagged template expressions, return statements) and recursively processes the tree.
  • TestCafe API call collection -- collectTestCafeCalls iterates over the AST body and aggregates all discovered fixture() and test() invocations.
  • Fixture/test assembly -- analyze organizes collected calls into Fixture and Test data objects, respecting skip propagation (a skipped fixture marks all its tests as skipped).
  • Meta extraction -- getMetaInfo and processMetaArgs extract .meta() chain call arguments into key-value metadata objects.
  • Computed names -- formatComputedName produces placeholder names like <computed name>(line: 42) for dynamically named fixtures/tests.

The module also exports two lightweight data classes, Fixture and Test, which hold name, location, meta, and skip state for each discovered definition.

Usage

This class is never instantiated directly. It is subclassed by language-specific parsers (e.g. the ES-next parser, TypeScript parser, CoffeeScript parser) which implement the abstract methods for their respective AST formats. The compiler pipeline calls getTestList(filePath) or getTestListFromCode(code) to obtain the list of fixtures and tests in a file without executing it.

Code Reference

Source Location

src/compiler/test-file/test-file-parser-base.js (296 lines)

Signature

export class Fixture {
    constructor (name, start, end, loc, meta, isSkipped)
}

export class Test {
    constructor (name, start, end, loc, meta, isSkipped)
}

export class TestFileParserBase {
    constructor (tokenType)

    static formatComputedName (line)
    static isSkipped (originalToken, token = originalToken)

    // Abstract methods (must be overridden by subclasses)
    isAsyncFn (/* token */)
    getRValue (/* token */)
    getFunctionBody (/* token */)
    formatFnData (/* name, value, token */)
    analyzeMemberExp (/* token */)
    formatFnArg (/* arg */)
    getFnCall (/* token */)
    getTaggedTemplateExp (/* token */)
    analyzeFnCall (/* token */)
    parse (/* filePath, code */)
    getTokenType (/* token */)
    getCalleeToken (/* token */)
    getMemberFnName ()
    getKeyValue ()
    getStringValue ()

    // Concrete methods
    isApiFn (fn)
    serializeObjExp (token)
    processMetaArgs (token)
    getMetaInfo (callStack)
    checkExpDefineTargetName (type, apiFn)
    analyzeToken (token)
    collectTestCafeCalls (astBody)
    analyze (astBody)
    async readFile (filePath)
    async getTestList (filePath)
    getTestListFromCode (code)
}

Import

import { TestFileParserBase, Fixture, Test } from '../../compiler/test-file/test-file-parser-base';

I/O Contract

Inputs

Parameter Type Description
tokenType Object An enum-like object mapping token names (e.g. CallExpression, Identifier, PropertyAccessExpression) to values used for AST node type dispatch.
filePath (for getTestList) string Absolute path to the test source file to be read and parsed.
code (for getTestListFromCode) string Raw source code string to be parsed directly.
astBody (for analyze) Array Top-level AST body nodes produced by the language-specific parser.

Outputs

Method Return Type Description
getTestList(filePath) Promise<Fixture[]> Array of Fixture objects, each containing a tests array of Test objects.
getTestListFromCode(code) Fixture[] Same structure returned synchronously.
analyze(astBody) Fixture[] Organized fixture/test structure from raw AST calls.
collectTestCafeCalls(astBody) Array Flat array of call descriptor objects with properties: fnName, value, start, end, loc, meta, isSkipped.

Usage Examples

Subclassing for a specific parser:

import { TestFileParserBase } from './test-file-parser-base';

class ESNextTestFileParser extends TestFileParserBase {
    constructor () {
        super(esNextTokenTypes);
    }

    parse (code) {
        const ast = babelParse(code);
        return this.analyze(ast.program.body);
    }

    // ... implement all abstract methods for Babel AST nodes
}

Getting the test list from a file:

const parser = new ESNextTestFileParser();
const fixtures = await parser.getTestList('/path/to/test.js');

fixtures.forEach(fixture => {
    console.log(fixture.name, fixture.isSkipped);
    fixture.tests.forEach(test => {
        console.log('  ', test.name, test.isSkipped);
    });
});

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment