UNPKG

@salesforce/apex-node

Version:

Salesforce JS library for Apex

78 lines 3.25 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TapFormatTransformer = void 0; /* * Copyright (c) 2024, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ const core_1 = require("@salesforce/core"); const node_stream_1 = require("node:stream"); const utils_1 = require("../utils"); const buildTapDiagnostics_1 = require("./buildTapDiagnostics"); class TapFormatTransformer extends node_stream_1.Readable { logger; testResult; epilogue; buffer; bufferSize; constructor(testResult, epilogue, options) { super(options); this.testResult = testResult; this.epilogue = epilogue; this.logger = core_1.Logger.childFromRoot('TapFormatTransformer'); this.buffer = ''; this.bufferSize = options?.bufferSize || 256; // Default buffer size is 256 } pushToBuffer(chunk) { this.buffer += chunk; if (this.buffer.length >= this.bufferSize) { this.push(this.buffer); this.buffer = ''; } } _read() { this.logger.trace('starting format'); utils_1.HeapMonitor.getInstance().checkHeapSize('TapFormatTransformer._read'); this.format(); if (this.buffer.length > 0) { this.push(this.buffer); } this.push(null); // Signal the end of the stream this.logger.trace('finishing format'); utils_1.HeapMonitor.getInstance().checkHeapSize('TapFormatTransformer._read'); } format() { const testPointCount = this.testResult.tests.length; this.pushToBuffer(`1..${testPointCount}\n`); this.buildTapResults(); this.epilogue?.forEach((c) => { this.pushToBuffer(`# ${c}\n`); }); } buildTapResults() { this.testResult.tests.forEach((test, index) => { const testNumber = index + 1; const outcome = test.outcome === "Pass" /* ApexTestResultOutcome.Pass */ ? 'ok' : 'not ok'; this.pushToBuffer(`${outcome} ${testNumber} ${test.fullName}\n`); (0, buildTapDiagnostics_1.buildTapDiagnostics)(test).forEach((s) => { this.pushToBuffer(`# ${s}\n`); }); }); } } exports.TapFormatTransformer = TapFormatTransformer; __decorate([ (0, utils_1.elapsedTime)() ], TapFormatTransformer.prototype, "format", null); __decorate([ (0, utils_1.elapsedTime)() ], TapFormatTransformer.prototype, "buildTapResults", null); //# sourceMappingURL=tapFormatTransform.js.map