From b96af0fe87cfaeed2648f9116a0f55544bec5eb5 Mon Sep 17 00:00:00 2001 From: "blake.vandercar" Date: Wed, 30 Mar 2022 12:31:53 -0600 Subject: [PATCH] test outputConsoleLogs --- .../integration/outputCompactLogs.spec.js | 12 ++++++ test/cypress/plugins/index.js | 6 +++ test/specs/outputCompactLogs.spec.js | 38 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 test/cypress/integration/outputCompactLogs.spec.js create mode 100644 test/specs/outputCompactLogs.spec.js diff --git a/test/cypress/integration/outputCompactLogs.spec.js b/test/cypress/integration/outputCompactLogs.spec.js new file mode 100644 index 0000000..fa9375a --- /dev/null +++ b/test/cypress/integration/outputCompactLogs.spec.js @@ -0,0 +1,12 @@ +/// + +describe('Output compact logs', ()=>{ + // create logs to check that using outputCompactLogs overrides compactLogs for output file + it('Output compact logs', ()=>{ + for (let i = 0; i <20 ; i++) { + expect(1).to.equal(1) + } + + expect(1).to.equal(0) + }) +}) \ No newline at end of file diff --git a/test/cypress/plugins/index.js b/test/cypress/plugins/index.js index acaddee..6064148 100755 --- a/test/cypress/plugins/index.js +++ b/test/cypress/plugins/index.js @@ -52,6 +52,12 @@ module.exports = (on, config) => { if (config.env.compactLogs == "1") { options.compactLogs = 1; } + if (config.env.outputCompactLogs == "1") { + options.outputCompactLogs = 5; + options.compactLogs = 1; + options.outputRoot = config.projectRoot + '/output/'; + options.outputTarget = { 'out.txt': 'txt', }; + } if (config.env.pluginBadConfig == '1') { options = { outputRoot: 0, diff --git a/test/specs/outputCompactLogs.spec.js b/test/specs/outputCompactLogs.spec.js new file mode 100644 index 0000000..da96449 --- /dev/null +++ b/test/specs/outputCompactLogs.spec.js @@ -0,0 +1,38 @@ +import { + ICONS, + runTest, + commandBase, + logLastRun, + clean +} from "../utils"; + +const {expect} = require('chai'); +const fs = require('fs'); +const path = require('path'); + +describe('Output compact logs.', () => { + + afterEach(function () { + if (this.currentTest.state == 'failed') { + logLastRun(); + } + }); + + it('Should compact output file logs to length specified by outputCompactLogs', 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 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 ... ]`); + }); + }).timeout(60000); +});