Skip to content

Commit

Permalink
test outputConsoleLogs
Browse files Browse the repository at this point in the history
  • Loading branch information
bvandercar-vt committed Mar 30, 2022
1 parent 4709413 commit b96af0f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/cypress/integration/outputCompactLogs.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="cypress" />

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)
})
})
6 changes: 6 additions & 0 deletions test/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 38 additions & 0 deletions test/specs/outputCompactLogs.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit b96af0f

Please sign in to comment.