Skip to content

Commit

Permalink
#150: Fix continuous test.
Browse files Browse the repository at this point in the history
  • Loading branch information
archfz committed Jul 8, 2022
1 parent a785736 commit 5e75032
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
1 change: 1 addition & 0 deletions test/cypress/integration/continuousLogging.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('continuous logging', () => {

it('logs many again', () => {
cy.log('log again 1');
cy.wait(100);
cy.wait(2000);
cy.log('log again 2');
});
Expand Down
29 changes: 16 additions & 13 deletions test/specs/misc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,22 @@ describe('Misc.', () => {

it('Should continuously log.', async function () {
let checksMade = 0;
await runTestContinuous(commandBase(['enableContinuousLogging=1'], ['continuousLogging.spec.js']), (data, elapsedTime) => {
if (elapsedTime > 5 && elapsedTime <= 6) {
++checksMade;
expect(clean(data)).to.contain(`cy:log ${ICONS.info} log 1`);
expect(clean(data)).to.contain(`cy:log ${ICONS.info} log 2`);
expect(clean(data)).to.not.contain(`cy:log ${ICONS.info} log 3`);
}
if (elapsedTime > 6 && elapsedTime <= 7) {
++checksMade;
expect(clean(data)).to.contain(`cy:log ${ICONS.info} log again 1`);
expect(clean(data)).to.not.contain(`cy:log ${ICONS.info} log again 2`);
}
});
await runTestContinuous(
commandBase(['enableContinuousLogging=1'], ['continuousLogging.spec.js']),
'continuous logging',
(data, elapsedTime) => {
if (elapsedTime > 0.5 && elapsedTime <= 1) {
++checksMade;
expect(clean(data)).to.contain(`cy:log ${ICONS.info} log 1`);
expect(clean(data)).to.contain(`cy:log ${ICONS.info} log 2`);
expect(clean(data)).to.not.contain(`cy:log ${ICONS.info} log 3`);
}
if (elapsedTime > 2.6 && elapsedTime <= 3) {
++checksMade;
expect(clean(data)).to.contain(`cy:log ${ICONS.info} log again 1`);
expect(clean(data)).to.not.contain(`cy:log ${ICONS.info} log again 2`);
}
});

expect(checksMade, "No checks where made. The process might have ended too early.").to.be.greaterThan(0)
}).timeout(60000);
Expand Down
14 changes: 10 additions & 4 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export const runTest = async (command, callback) => {
});
};

export const runTestContinuous = async (command, callback) => {
export const runTestContinuous = async (command, afterOutput, callback) => {
await new Promise(resolve => {
let allData = '';
const startTime = (new Date()).getTime();
let startTime;
const mainCommand = command.split(' ')[0];
const args = command.split(' ').map(arg => arg.replace(/^"/, '').replace(/"$/, ''));
args.shift();
Expand All @@ -72,8 +72,14 @@ export const runTestContinuous = async (command, callback) => {
child.on('close', resolve);

const dataCallback = (data) => {
allData += data.toString();
callback(allData, ((new Date()).getTime() - startTime) / 1000);
if (data.toString().includes(afterOutput)) {
startTime = (new Date()).getTime();
}

if (startTime) {
allData += data.toString();
callback(allData, ((new Date()).getTime() - startTime) / 1000);
}
};

child.stdout.setEncoding('utf8');
Expand Down

0 comments on commit 5e75032

Please sign in to comment.