Repository: eslint/eslint
File: tools/fuzzer-runner.js (JavaScript)

Code before:
const CRASH_AUTOFIX_TEST_COUNT_RATIO = 3;

//------------------------------------------------------------------------------
// Public API
//------------------------------------------------------------------------------

/**
 * Runs the fuzzer and outputs a progress bar
 * @param {Object} [options] Options for the fuzzer
 * @param {number} [options.amount=300] A positive integer indicating how much testing to do. Larger values result in a higher
 * chance of finding bugs, but cause the testing to take longer (linear increase). With the default value, the fuzzer
 * takes about 15 seconds to run.
 * @param {boolean} [options.fuzzBrokenAutofixes=true] true if the fuzzer should look for invalid autofixes in addition to rule crashes
 * @returns {Object[]} A list of objects, where each object represents a problem detected by the fuzzer. The objects have the same
 * schema as objects returned from eslint-fuzzer.
 */
function run({ amount = 300, fuzzBrokenAutofixes = true } = {}) {
    const crashTestCount = amount * CRASH_AUTOFIX_TEST_COUNT_RATIO;
    const autofixTestCount = fuzzBrokenAutofixes ? amount : 0;

    /*
     * To keep the progress bar moving at a roughly constant speed, apply a different weight for finishing
     * a crash-only fuzzer run versus an autofix fuzzer run.
     */
    const progressBar = new ProgressBar(
        "Fuzzing rules [:bar] :percent, :elapsed elapsed, eta :etas, errors so far: :elapsedErrors",
        { width: 30, total: crashTestCount + autofixTestCount * ESTIMATED_CRASH_AUTOFIX_PERFORMANCE_RATIO }
    );

    // Start displaying the progress bar.
    progressBar.tick(0, { elapsedErrors: 0 });

    const crashTestResults = fuzz({
        linter,
        count: crashTestCount,
        checkAutofixes: false,
        progressCallback(elapsedErrors) {
            progressBar.tick(1, { elapsedErrors });
            progressBar.render();
        }
    });

    const autofixTestResults = fuzz({
        linter,
        count: autofixTestCount,
        checkAutofixes: true,
        progressCallback(elapsedErrors) {
            progressBar.tick(ESTIMATED_CRASH_AUTOFIX_PERFORMANCE_RATIO, { elapsedErrors: crashTestResults.length + elapsedErrors });
            progressBar.render();
        }
    });

Review comment (suggestion):
```suggestion
        "Fuzzing rules [:bar] :percent, :elapseds elapsed, eta :etas, errors so far: :elapsedErrors",
```

This was intentional, to print `s` (as short for seconds) after [`:elapsed`](https://github.com/visionmedia/node-progress#tokens). For example, `19.7s elapsed`

Code after:
const CRASH_AUTOFIX_TEST_COUNT_RATIO = 3;

//------------------------------------------------------------------------------
// Public API
//------------------------------------------------------------------------------

/**
 * Runs the fuzzer and outputs a progress bar
 * @param {Object} [options] Options for the fuzzer
 * @param {number} [options.amount=300] A positive integer indicating how much testing to do. Larger values result in a higher
 * chance of finding bugs, but cause the testing to take longer (linear increase). With the default value, the fuzzer
 * takes about 15 seconds to run.
 * @param {boolean} [options.fuzzBrokenAutofixes=true] true if the fuzzer should look for invalid autofixes in addition to rule crashes
 * @returns {Object[]} A list of objects, where each object represents a problem detected by the fuzzer. The objects have the same
 * schema as objects returned from eslint-fuzzer.
 */
function run({ amount = 300, fuzzBrokenAutofixes = true } = {}) {
    const crashTestCount = amount * CRASH_AUTOFIX_TEST_COUNT_RATIO;
    const autofixTestCount = fuzzBrokenAutofixes ? amount : 0;

    /*
     * To keep the progress bar moving at a roughly constant speed, apply a different weight for finishing
     * a crash-only fuzzer run versus an autofix fuzzer run.
     */
    const progressBar = new ProgressBar(
        "Fuzzing rules [:bar] :percent, :elapseds elapsed, eta :etas, errors so far: :elapsedErrors",
        { width: 30, total: crashTestCount + autofixTestCount * ESTIMATED_CRASH_AUTOFIX_PERFORMANCE_RATIO }
    );

    // Start displaying the progress bar.
    progressBar.tick(0, { elapsedErrors: 0 });

    const crashTestResults = fuzz({
        linter,
        count: crashTestCount,
        checkAutofixes: false,
        progressCallback(elapsedErrors) {
            progressBar.tick(1, { elapsedErrors });
            progressBar.render();
        }
    });

    const autofixTestResults = fuzz({
        linter,
        count: autofixTestCount,
        checkAutofixes: true,
        progressCallback(elapsedErrors) {
            progressBar.tick(ESTIMATED_CRASH_AUTOFIX_PERFORMANCE_RATIO, { elapsedErrors: crashTestResults.length + elapsedErrors });
            progressBar.render();
        }
    });