diff --git a/README.md b/README.md index a222c66..da090d2 100755 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/collector/LogCollectExtendedControl.js b/src/collector/LogCollectExtendedControl.js index fd35ef9..bd81a2c 100644 --- a/src/collector/LogCollectExtendedControl.js +++ b/src/collector/LogCollectExtendedControl.js @@ -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); } }); } diff --git a/src/collector/LogCollectSimpleControl.js b/src/collector/LogCollectSimpleControl.js index c4c0955..6ec9c84 100644 --- a/src/collector/LogCollectSimpleControl.js +++ b/src/collector/LogCollectSimpleControl.js @@ -40,12 +40,11 @@ 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(), @@ -53,10 +52,30 @@ module.exports = class LogCollectSimpleControl extends LogCollectBaseControl { 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() { @@ -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}); } }); } diff --git a/src/installLogsCollector.schema.json b/src/installLogsCollector.schema.json index bf4afba..f0b4e45 100644 --- a/src/installLogsCollector.schema.json +++ b/src/installLogsCollector.schema.json @@ -20,6 +20,7 @@ "cy:log", "cy:xhr", "cy:request", + "cy:intercept", "cy:route", "cy:command" ] diff --git a/test/cypress/integration/skipTest.spec.js b/test/cypress/integration/skipTest.spec.js new file mode 100644 index 0000000..35c2c6a --- /dev/null +++ b/test/cypress/integration/skipTest.spec.js @@ -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'); + }); +}); diff --git a/test/cypress/support/index.js b/test/cypress/support/index.js index 7bc7c55..826ef18 100755 --- a/test/cypress/support/index.js +++ b/test/cypress/support/index.js @@ -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; } diff --git a/test/package-lock.json b/test/package-lock.json index 5a066a3..215a06b 100644 --- a/test/package-lock.json +++ b/test/package-lock.json @@ -1232,9 +1232,9 @@ "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==" }, "async": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", - "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.1.tgz", + "integrity": "sha512-XdD5lRO/87udXCMC9meWdYiR+Nq6ZjUfXidViUZGu2F1MO4T3XwZ1et0hb2++BgLfhyJwy44BGB/yx80ABx8hg==" }, "async-each": { "version": "1.0.3", @@ -2456,9 +2456,9 @@ "integrity": "sha1-f1x7cACbwrZmWRv+ZIVFeL7e6Fo=" }, "cypress": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-8.1.0.tgz", - "integrity": "sha512-GXjlqPjY/6HPbQwAp3AvlA1Mk/NoJTAmqVSUhQsuM/1xDpd/FQHkxVuq5h6O6RrAoCXSgpZPXFsVtdqE+FwEJw==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-7.7.0.tgz", + "integrity": "sha512-uYBYXNoI5ym0UxROwhQXWTi8JbUEjpC6l/bzoGZNxoKGsLrC1SDPgIDJMgLX/MeEdPL0UInXLDUWN/rSyZUCjQ==", "requires": { "@cypress/request": "^2.88.5", "@cypress/xvfb": "^1.2.4", diff --git a/test/package.json b/test/package.json index 49a5044..c56890a 100755 --- a/test/package.json +++ b/test/package.json @@ -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", diff --git a/test/specs/extendedController.spec.js b/test/specs/extendedController.spec.js index 1a5486f..9a3d9ca 100755 --- a/test/specs/extendedController.spec.js +++ b/test/specs/extendedController.spec.js @@ -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 @@ -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); }); diff --git a/test/specs/misc.spec.js b/test/specs/misc.spec.js index 085a607..0046c7d 100755 --- a/test/specs/misc.spec.js +++ b/test/specs/misc.spec.js @@ -1,7 +1,7 @@ import { ICONS, runTest, - commandBase, logLastRun, + commandBase, logLastRun, clean, } from "../utils"; const {expect} = require('chai'); @@ -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); + }); diff --git a/test/specs/validation.spec.js b/test/specs/validation.spec.js index 085589b..3d3ef4c 100755 --- a/test/specs/validation.spec.js +++ b/test/specs/validation.spec.js @@ -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:`);