Skip to content

Commit

Permalink
#160: Fix compatibility with cypress-grep.
Browse files Browse the repository at this point in the history
  • Loading branch information
archfz committed Aug 12, 2022
1 parent 5dbc17d commit f6d3115
Show file tree
Hide file tree
Showing 14 changed files with 754 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ directory. You should add `it.only` to the test case you are working on to speed
## Release Notes
- Fix incorrectly required option props.
- Fix missing option `logToFilesOnAfterRun` in types. [issue](https://github.com/archfz/cypress-terminal-report/issues/161)
- Fix compatibility with `cypress-grep`. see [issue](https://github.com/archfz/cypress-terminal-report/issues/160)
#### 4.1.1
Expand Down
6 changes: 3 additions & 3 deletions src/collector/LogCollectBaseControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ module.exports = class LogCollectBaseControl {
parent = parent.parent;
}

return invocationDetails.relativeFile ||
(invocationDetails.fileUrl && invocationDetails.fileUrl.replace(/^[^?]+\?p=/, '')) ||
parent.file;
return parent.file || // Support for cypress-grep.
invocationDetails.relativeFile ||
(invocationDetails.fileUrl && invocationDetails.fileUrl.replace(/^[^?]+\?p=/, ''));
}
}
7 changes: 4 additions & 3 deletions src/collector/LogCollectSimpleControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ module.exports = class LogCollectSimpleControl extends LogCollectBaseControl {
});

// Logs commands if test was manually skipped.
Cypress.mocha.getRunner().on('pending', function (test) {
if (self.collectorState.getCurrentTest()) {
Cypress.mocha.getRunner().on('pending', function () {
let test = self.collectorState.getCurrentTest();
if (test && test.state === 'pending') {
// 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});
self.sendLogsToPrinter(self.collectorState.getCurrentLogStackIndex(), test, {noQueue: true});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
'LOCK', 'M-SEARCH', 'MERGE',
'MKACTIVITY', 'MKCALENDAR', 'MKCOL',
'MOVE', 'NOTIFY', 'OPTIONS',
'PATCH', 'POST', 'PROPFIND',
'PATCH', 'POST', 'PRI', 'PROPFIND',
'PROPPATCH', 'PURGE', 'PUT',
'REBIND', 'REPORT', 'SEARCH',
'SOURCE', 'SUBSCRIBE', 'TRACE',
Expand Down
8 changes: 7 additions & 1 deletion src/installLogsPrinter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ declare namespace installLogsPrinter {
* be printed from before and after hooks.
* @default false
*/
includeSuccessfulHookLogs?: boolean
includeSuccessfulHookLogs?: boolean;

/**
* When set to true it enables additional log write pass to files
* @default false
*/
logToFilesOnAfterRun?: boolean;

/**
* Callback to collect each test case's logs after its run.
Expand Down
4 changes: 4 additions & 0 deletions test/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ module.exports = defineConfig({
config.specPattern = 'cypress/integration/**/*.feature';
}

if (config.env.cypressGrep == '1') {
config.env.grep = "run only this"
}

if (config.env.failFast) {
require("cypress-fail-fast/plugin")(on, config);
}
Expand Down
9 changes: 9 additions & 0 deletions test/cypress/integration/cypressGrep.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('Cypress grep', () => {
it("run only this", () => {
cy.visit('/');
cy.contains('cypress', { timeout: 1 });
})
it("this should be skipped", () => {
cy.log('should not be logged');
})
})
4 changes: 4 additions & 0 deletions test/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import './commands';
import registerCypressGrep from "cypress-grep";

const env = Cypress.env();
let config = {};

if (env.failFast == '1') {
require("cypress-fail-fast");
}
if (env.cypressGrep == '1') {
registerCypressGrep();
}

if (env.ctrDebug == '1') {
config.debug = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Specs:
cypress/integration/cypressGrep.spec.js
16 changes: 16 additions & 0 deletions test/output_nested_cypress_grep_spec/json/cypressGrep.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"cypress/integration/cypressGrep.spec.js": {
"Cypress grep -> run only this": [
{
"type": "cy:command",
"severity": "success",
"message": "visit\t/"
},
{
"type": "cy:command",
"severity": "success",
"message": "contains\tcypress"
}
]
}
}
5 changes: 5 additions & 0 deletions test/output_nested_cypress_grep_spec/txt/cypressGrep.spec.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cypress/integration/cypressGrep.spec.js:
Cypress grep -> run only this
cy:command (K): visit /
cy:command (K): contains cypress

Loading

0 comments on commit f6d3115

Please sign in to comment.