async function toJSON()

in apps/mountebank-mock/mountebank-source/src/models/imposterPrinter.js [83:115]


    async function toJSON (numberOfRequests, options = {}) {
        // I consider the order of fields represented important.  They won't matter for parsing,
        // but it makes a nicer user experience for developers viewing the JSON to keep the most
        // relevant information at the top. Some of the order of operations in this file represents
        // that (e.g. keeping the _links at the end), and is tested with some documentation tests.
        const result = createHeader(numberOfRequests, options);

        options = options || {};

        if (options.list) {
            addLinksTo(result);
            return result;
        }

        if (!options.replayable) {
            await addRequestsTo(result);
        }

        await addStubsTo(result, options);

        if (options.replayable) {
            removeNonEssentialInformationFrom(result);
        }
        else {
            addLinksTo(result);
        }

        if (options.removeProxies) {
            removeProxiesFrom(result);
        }

        return result;
    }