Skip to content

Commit

Permalink
#113 #114 #116: Fix for skip tests and collect logs validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
archfz committed Aug 18, 2021
1 parent f182881 commit b64b6b1
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 21 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ directory. You should add `it.only` to the test case you are working on to speed
## Release Notes
- Fix issue `cy:intercept` not between the allowed configuration options. [issue](https://github.com/archfz/cypress-terminal-report/issues/113)
- Fix issue with plugin breaking cypress with skipped tests. [issue1](https://github.com/archfz/cypress-terminal-report/issues/116) [issue2](https://github.com/archfz/cypress-terminal-report/issues/114)
Update cypress to 8.3.0 in tests to confirm support.
#### 3.3.0
- Added support for logging command from skipped tests. [issue](https://github.com/archfz/cypress-terminal-report/issues/111)
Expand Down
6 changes: 5 additions & 1 deletion src/collector/LogCollectExtendedControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ module.exports = class LogCollectExtendedControl extends LogCollectBaseControl {
// Logs commands if test was manually skipped.
Cypress.mocha.getRunner().on('pending', function (test) {
if (self.collectorState.getCurrentTest()) {
sendLogsToPrinterForATest(self.collectorState.getCurrentTest());
// In case of fully skipped tests we might not yet have a log stack.
if (!self.collectorState.hasLogsCurrentStack()) {
self.collectorState.addNewLogStack();
}
sendLogsToPrinterForATest(test);
}
});
}
Expand Down
45 changes: 34 additions & 11 deletions src/collector/LogCollectSimpleControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,42 @@ module.exports = class LogCollectSimpleControl extends LogCollectBaseControl {
return this.prepareLogs(logStackIndex, {mochaRunnable, testState, testTitle, testLevel});
};

// Need to wait for command log update debounce.
cy.wait(wait, {log: false})
.then(() => {
cy.task(
CONSTANTS.TASK_NAME,
{
if (options.noQueue) {
Promise.resolve().then(() => {
Cypress.backend('task', {
task: CONSTANTS.TASK_NAME,
arg: {
spec: spec,
test: testTitle,
messages: prepareLogs(),
state: testState,
level: testLevel,
consoleTitle: options.consoleTitle,
isHook: options.isHook,
},
{log: false}
);
});
}
})
// For some reason cypress throws empty error although the task indeed works.
.catch((error) => {/* noop */})
}).catch(console.error);
} else {
// Need to wait for command log update debounce.
cy.wait(wait, {log: false})
.then(() => {
cy.task(
CONSTANTS.TASK_NAME,
{
spec: spec,
test: testTitle,
messages: prepareLogs(),
state: testState,
level: testLevel,
consoleTitle: options.consoleTitle,
isHook: options.isHook,
},
{log: false}
);
});
}
}

registerState() {
Expand Down Expand Up @@ -86,7 +105,11 @@ module.exports = class LogCollectSimpleControl extends LogCollectBaseControl {
// Logs commands if test was manually skipped.
Cypress.mocha.getRunner().on('pending', function (test) {
if (self.collectorState.getCurrentTest()) {
self.sendLogsToPrinter(self.collectorState.getCurrentLogStackIndex(), self.collectorState.getCurrentTest());
// In case of fully skipped tests we might not yet have a log stack.
if (!self.collectorState.hasLogsCurrentStack()) {
self.collectorState.addNewLogStack();
}
self.sendLogsToPrinter(self.collectorState.getCurrentLogStackIndex(), self.collectorState.getCurrentTest(), {noQueue: true});
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/installLogsCollector.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"cy:log",
"cy:xhr",
"cy:request",
"cy:intercept",
"cy:route",
"cy:command"
]
Expand Down
37 changes: 37 additions & 0 deletions test/cypress/integration/skipTest.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
describe('Describe 1', () => {
before(() => {
cy.visit(`https://www.google.co.uk`);
});

it.skip('Skipped test 1', () => {
cy.log('first skip');
});

it('Test 2', () => {
cy.log('test 2');
});
});

describe('Describe 2', () => {
beforeEach(() => {
cy.visit(`https://www.google.co.uk`);
});

// The tests gets hang here
it.skip('Skipped test 2', () => {
cy.log('Skipped test 2');
});

//This second skipped test seems to be the culprit
it.skip('Skipped test 3', () => {
cy.log('Skipped test 3');
});

it('Test 3', () => {
cy.log('Test 3');
});

it('Test 4', () => {
cy.log('Test 4');
});
});
5 changes: 5 additions & 0 deletions test/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ if (env.supportBadConfig == '1') {
shouldNotBeHere: ""
};
}
if (env.supportGoodConfig == '1') {
config = {
collectTypes: ['cons:log','cons:info', 'cons:warn', 'cons:error', 'cy:log', 'cy:xhr', 'cy:request', 'cy:route', 'cy:intercept', 'cy:command']
};
}
if (env.enableExtendedCollector == '1') {
config.enableExtendedCollector = true;
}
Expand Down
12 changes: 6 additions & 6 deletions test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.13.16",
"chai": "^4.2.0",
"cypress": "8.1.0",
"cypress": "8.3.0",
"cypress-cucumber-preprocessor": "^4.0.1",
"fs-extra": "^9.0.1",
"glob": "^7.1.6",
Expand Down
16 changes: 15 additions & 1 deletion test/specs/extendedController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('Extended controller.', () => {
});
}).timeout(60000);

it('Should work correctly with skip.', async function () {
it('Should work correctly with dynamic skip.', async function () {
await runTest(commandBase(['enableExtendedCollector=1'], ['dynamicSkip.spec.js']), (error, stdout, stderr) => {
expect(clean(stdout)).to.contain(`- test3
cy:log ${ICONS.info} before
Expand All @@ -200,4 +200,18 @@ describe('Extended controller.', () => {
cy:log ${ICONS.info} test3 3`);
});
}).timeout(60000);

it('Should work correctly with skipped tests.', async function () {
await runTest(commandBase(['enableExtendedCollector=1'], ['skipTest.spec.js']), (error, stdout, stderr) => {
expect(clean(stdout, true)).to.contain(` Describe 1
- Skipped test 1
✓ Test 2
Describe 2
- Skipped test 2
- Skipped test 3
✓ Test 3
✓ Test 4`);
});
}).timeout(60000);
});
16 changes: 15 additions & 1 deletion test/specs/misc.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
ICONS,
runTest,
commandBase, logLastRun,
commandBase, logLastRun, clean,
} from "../utils";

const {expect} = require('chai');
Expand Down Expand Up @@ -75,4 +75,18 @@ describe('Misc.', () => {
});
}).timeout(30000);

it('Should work correctly with skipped tests.', async function () {
await runTest(commandBase([''], ['skipTest.spec.js']), (error, stdout, stderr) => {
expect(clean(stdout, true)).to.contain(` Describe 1
- Skipped test 1
✓ Test 2
Describe 2
- Skipped test 2
- Skipped test 3
✓ Test 3
✓ Test 4`);
});
}).timeout(60000);

});
6 changes: 6 additions & 0 deletions test/specs/validation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ describe('Validation.', () => {
});
}).timeout(60000);

it('Should not fail with proper config.', async () => {
await runTest(commandBase(['supportGoodConfig=1'], ['happyFlow.spec.js']), (error, stdout, stderr) => {
expect(stdout).to.not.contain(`cypress-terminal-report: Invalid plugin install options:`);
});
}).timeout(60000);

it('Should print proper validation error on invalid support install options.', async () => {
await runTest(commandBase(['supportBadConfig=1'], ['happyFlow.spec.js']), (error, stdout, stderr) => {
expect(stdout).to.contain(`cypress-terminal-report: Invalid plugin install options:`);
Expand Down

0 comments on commit b64b6b1

Please sign in to comment.