JSON-Path

 view release on metacpan or  search on metacpan

jsonpath-compliance-test-suite/build.js  view on Meta::CPAN

// @ts-check

const fs = require('fs');
const path = require('path');
/**
 * The file extension of test files.
 * @type {string}
 */
const fileExtension = '.json';
/**
 * The number of spaces to use for indentation in the output.
 * @type {number}
 */
const jsonIndent = 2;
/**
 * The separator to use when combining test names.
 * @type {string}
 */
const testNameSeparator = ', ';

/**
 * The description of the test suite.
 * @type {string}
 */
const description = 'JSONPath Compliance Test Suite. This file is autogenerated, do not edit.';

build();

/**
 * Build a combined test suite from a directory of test files.
 * The output is written to stdout.
 */
function build() {
    if (process.argv.length < 3) {
        console.error('Usage: node build.js <test-folder-path>');
        process.exit(1);
    }

    const testsFolder = process.argv[2];
    const tests = readTestsFromDir(testsFolder);
    const cts = {'description': description, 'tests': tests};
    console.log(JSON.stringify(cts, null, jsonIndent));
    console.error(`Wrote ${tests.length} tests to stdout.`);
}


/**
 * Read all test files from a directory and its subdirectories.
 * The directory name is prepended to the test name.
 * @param dir {string} - The directory to read.
 * @param relativePath {string[]} - The path to the directory.
 * @returns {*[]} - An array of test objects.
 */
function readTestsFromDir(dir, relativePath = []) {
    const files = fs.readdirSync(dir);
    files.sort(filesBeforeDirs);
    return files.reduce(addTestsFromFile, []);

    /**
     * Add tests from a file to the list of all tests.
     * @param allTests - The list of all tests.
     * @param file - The file to read.
     * @returns {*} - The updated list of all tests.
     */



( run in 0.987 second using v1.01-cache-2.11-cpan-39bf76dae61 )