Skip to content

Commit

Permalink
#240: Fix commandTimings failing when before hooks are logged.
Browse files Browse the repository at this point in the history
  • Loading branch information
archfz committed May 1, 2024
1 parent 2a5d077 commit 6edf202
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ directory. You should add `it.only` to the test case you are working on to speed
## Release Notes

- Fix `never` on `printLogsToConsole` works in all cases. [issue](https://github.com/archfz/cypress-terminal-report/issues/241)
- Fix `commandTimings` failing when before hooks are logged. [issue](https://github.com/archfz/cypress-terminal-report/issues/240)
- `commandTimings` now log the time elapsed since the suite / spec start instead of the time since the test start.

#### 6.0.1

Expand Down
6 changes: 3 additions & 3 deletions src/collector/LogCollectorState.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class LogCollectorState {
this.beforeHookIndexes = [];
this.afterHookIndexes = [];
this.isStrict = false;
this.testStartTime = null;
this.suiteStartTime = null;
}

setStrict(strict) {
Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports = class LogCollectorState {
if (this.config.commandTimings == 'timestamp') {
structuredEntry.timeString = Date.now() + "";
} else if (this.config.commandTimings == 'seconds') {
structuredEntry.timeString = (Date.now() - this.testStartTime.getTime()) / 1000 + "s";
structuredEntry.timeString = (Date.now() - this.suiteStartTime.getTime()) / 1000 + "s";
}
}
if (xhrIdOfLoggedResponse) {
Expand Down Expand Up @@ -155,6 +155,7 @@ module.exports = class LogCollectorState {
if (this.config.debug) {
console.log(CONSTANTS.DEBUG_LOG_PREFIX + 'starting suite');
}
this.suiteStartTime = new Date();
this.xhrIdsOfLoggedResponses = [];
this.beforeHookIndexes.unshift(0);
this.afterHookIndexes.unshift(0);
Expand All @@ -172,7 +173,6 @@ module.exports = class LogCollectorState {
}
this.setCurrentTest(test);
this.xhrIdsOfLoggedResponses = [];
this.testStartTime = new Date();

this.addNewLogStack();

Expand Down
13 changes: 6 additions & 7 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 @@ -28,7 +28,7 @@
"@bahmutov/cypress-esbuild-preprocessor": "^2.2.0",
"babel-loader": "^9.1.3",
"chai": "^4.2.0",
"cypress": "13.6.1",
"cypress": "13.8.1",
"@cypress/grep": "^4.0.1",
"fs-extra": "^10.1.0",
"glob": "^8.0.3",
Expand Down
6 changes: 6 additions & 0 deletions test/specs/misc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@ describe('Misc.', () => {
});
}).timeout(60000);

it('Should log command times in seconds with extended collector and before hooks.', async function () {
await runTest(commandBase(['commandTimings=seconds', 'enableExtendedCollector=1'], ['beforeLogs.spec.js']), (error, stdout, stderr) => {
expect(clean(stdout, true)).to.match(/Time: \d+\.\d{3}s\n cy:command/);
});
}).timeout(60000);

});

0 comments on commit 6edf202

Please sign in to comment.