From a4fcd736367114949a6fde48c0941374858f4a2e Mon Sep 17 00:00:00 2001 From: "blake.vandercar" Date: Thu, 31 Mar 2022 09:24:50 -0600 Subject: [PATCH] allow outputCompactLogs to be set to -1 to allow for overriding compactLogs to allow for no compacting in output file --- README.md | 1 + src/installLogsPrinter.js | 14 +++++-- src/installLogsPrinter.schema.json | 2 +- test/cypress/plugins/index.js | 13 ++++++- test/specs/outputCompactLogs.spec.js | 58 ++++++++++++++++++++-------- 5 files changed, 65 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 81c0a36..6cb41f9 100755 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ for tests that don't have any `severity=error` logs nothing will be printed. integer?; default: null; Overrides `options.compactLogs` for the file log output specifically, when `options.outputTarget` is specified. Allows compacting of the terminal and the file output logs to different levels. If `options.outputCompactLogs` is unspecified, file output will use `options.compactLogs`. +If set to -1, output file logs will not compact even if `options.compactLogs` is set. #### `options.outputRoot` string; default: null; Required if `options.outputTarget` provided. [More details](#logging-to-files). diff --git a/src/installLogsPrinter.js b/src/installLogsPrinter.js index ce5b3a6..271cbb9 100755 --- a/src/installLogsPrinter.js +++ b/src/installLogsPrinter.js @@ -74,10 +74,16 @@ function installLogsPrinter(on, options = {}) { options.printLogsToFile === "always" || isHookAndShouldLog ) { - const outputFileMessages = - typeof options.outputCompactLogs === 'number' && options.outputCompactLogs >= 0 - ? compactLogs(messages, options.outputCompactLogs) - : terminalMessages; + let outputFileMessages + if (typeof options.outputCompactLogs === 'number' ) { + if (options.outputCompactLogs >= 0){ + outputFileMessages = compactLogs(messages, options.outputCompactLogs) + } else { + outputFileMessages = messages // if -1, override compactLogs, don't compact + } + } else{ + outputFileMessages = terminalMessages // if unspecified, go with compactLogs + } writeToFileMessages[data.spec] = writeToFileMessages[data.spec] || {}; writeToFileMessages[data.spec][data.test] = outputFileMessages; diff --git a/src/installLogsPrinter.schema.json b/src/installLogsPrinter.schema.json index bddac48..52ddc29 100644 --- a/src/installLogsPrinter.schema.json +++ b/src/installLogsPrinter.schema.json @@ -35,7 +35,7 @@ }, "outputCompactLogs": { "type": "number", - "minimum": 0 + "minimum": -1 }, "outputRoot": { "type": "string" diff --git a/test/cypress/plugins/index.js b/test/cypress/plugins/index.js index 6064148..7e93ecb 100755 --- a/test/cypress/plugins/index.js +++ b/test/cypress/plugins/index.js @@ -53,8 +53,19 @@ module.exports = (on, config) => { options.compactLogs = 1; } if (config.env.outputCompactLogs == "1") { - options.outputCompactLogs = 5; options.compactLogs = 1; + options.outputCompactLogs = 5; + options.outputRoot = config.projectRoot + '/output/'; + options.outputTarget = { 'out.txt': 'txt', }; + } + if (config.env.outputCompactLogs == "2") { + options.outputCompactLogs = 5; + options.outputRoot = config.projectRoot + '/output/'; + options.outputTarget = { 'out.txt': 'txt', }; + } + if (config.env.outputCompactLogs == "3") { + options.compactLogs = 5; + options.outputCompactLogs = -1; options.outputRoot = config.projectRoot + '/output/'; options.outputTarget = { 'out.txt': 'txt', }; } diff --git a/test/specs/outputCompactLogs.spec.js b/test/specs/outputCompactLogs.spec.js index da96449..97d238f 100644 --- a/test/specs/outputCompactLogs.spec.js +++ b/test/specs/outputCompactLogs.spec.js @@ -1,15 +1,16 @@ -import { - ICONS, - runTest, - commandBase, - logLastRun, - clean -} from "../utils"; +import { runTest, commandBase, logLastRun, clean } from "../utils"; const {expect} = require('chai'); const fs = require('fs'); const path = require('path'); +function getOutputFileContents() { + const outputFile = path.join(__dirname, '../output/out.txt'); + expect(fs.existsSync(outputFile), `Expected output file ${outputFile} to exist.`).to.be.true; + const valueBuffer = fs.readFileSync(outputFile); + return clean(valueBuffer.toString()); +} + describe('Output compact logs.', () => { afterEach(function () { @@ -18,21 +19,44 @@ describe('Output compact logs.', () => { } }); - it('Should compact output file logs to length specified by outputCompactLogs', async () => { + it('Should compact logs to length specified by compactLogs and outputCompactLogs - compactLogs=1, outputCompactLogs=5', async () => { await runTest(commandBase(['outputCompactLogs=1'], ['outputCompactLogs.spec.js']), (error, stdout, stderr) => { // failure occurs on 21st log, compactLogs=1, outputCompactLogs=5 - // test console is correct - expect(stdout).to.contain(`[ ... 19 omitted logs ... ]`); - expect(stdout).to.not.contain(`[ ... 15 omitted logs ... ]`); + // test terminal is correct + expect(stdout, 'compactLogs compacts terminal logs to correct val (1)' ).to.contain( `[ ... 19 omitted logs ... ]`); + expect(stdout, 'compactLogs does not compact terminal to outputCompactLogs val (5)' ).to.not.contain(`[ ... 15 omitted logs ... ]`); + + // test output log is correct + const fileContents = getOutputFileContents(); + expect(fileContents, 'outputCompactLogs compacts output file logs to correct val (5)').to.contain( `[ ... 15 omitted logs ... ]` ); + expect(fileContents, 'outputCompactLogs does not compact output file logs to compactLogs val (1)').to.not.contain(`[ ... 19 omitted logs ... ]`); + }); + }).timeout(60000); + + it('Should compact logs to length specified by compactLogs and outputCompactLogs - compactLogs=unspecified, outputCompactLogs=5', async () => { + await runTest(commandBase(['outputCompactLogs=2'], ['outputCompactLogs.spec.js']), (error, stdout, stderr) => { + // failure occurs on 21st log, compactLogs=unspecified (default), outputCompactLogs=5 + + // test terminal is correct + expect(stdout, 'not specifying compactLogs results in uncompacted terminal output even if outputCompactLogs>=0 specified' ).to.not.contain(`omitted logs`); + + // test output log is correct + const fileContents = getOutputFileContents(); + expect(fileContents, 'outputCompactLogs>=0 compacts terminal even if compactLogs not specified' ).to.contain(`[ ... 15 omitted logs ... ]`); + }); + }).timeout(60000); + + it('Should compact logs to length specified by compactLogs and outputCompactLogs - compactLogs=5, outputCompactLogs=-1', async () => { + await runTest(commandBase(['outputCompactLogs=3'], ['outputCompactLogs.spec.js']), (error, stdout, stderr) => { + // failure occurs on 21st log, compactLogs=5, outputCompactLogs=-1 + + // test terminal is correct + expect(stdout, 'compactLogs compacts terminal logs to correct val (5)').to.contain( `[ ... 15 omitted logs ... ]`); // test output log is correct - const outputFile = path.join(__dirname, '../output/out.txt'); - expect(fs.existsSync(outputFile), `Expected output file ${outputFile} to exist.`).to.be.true; - const valueBuffer = fs.readFileSync(outputFile); - let value = clean(valueBuffer.toString()); - expect(value).to.contain(`[ ... 15 omitted logs ... ]`); - expect(value).to.not.contain(`[ ... 19 omitted logs ... ]`); + const fileContents = getOutputFileContents(); + expect(fileContents, 'outputCompactLogs=-1 causes terminal to not compact even if compactLogs specified' ).to.not.contain(`omitted logs`); }); }).timeout(60000); });