diff --git a/README.md b/README.md index b3d7324..67154db 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/collector/LogCollectorState.js b/src/collector/LogCollectorState.js index 8db7161..d00dc99 100644 --- a/src/collector/LogCollectorState.js +++ b/src/collector/LogCollectorState.js @@ -11,7 +11,7 @@ module.exports = class LogCollectorState { this.beforeHookIndexes = []; this.afterHookIndexes = []; this.isStrict = false; - this.testStartTime = null; + this.suiteStartTime = null; } setStrict(strict) { @@ -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) { @@ -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); @@ -172,7 +173,6 @@ module.exports = class LogCollectorState { } this.setCurrentTest(test); this.xhrIdsOfLoggedResponses = []; - this.testStartTime = new Date(); this.addNewLogStack(); diff --git a/test/package-lock.json b/test/package-lock.json index c33d116..e5ea190 100644 --- a/test/package-lock.json +++ b/test/package-lock.json @@ -19,7 +19,7 @@ "@cypress/grep": "^4.0.1", "babel-loader": "^9.1.3", "chai": "^4.2.0", - "cypress": "13.6.1", + "cypress": "13.8.1", "fs-extra": "^10.1.0", "glob": "^8.0.3", "html-webpack-plugin": "^5.5.3", @@ -4230,20 +4230,19 @@ } }, "node_modules/cypress": { - "version": "13.6.1", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.6.1.tgz", - "integrity": "sha512-k1Wl5PQcA/4UoTffYKKaxA0FJKwg8yenYNYRzLt11CUR0Kln+h7Udne6mdU1cUIdXBDTVZWtmiUjzqGs7/pEpw==", + "version": "13.8.1", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.8.1.tgz", + "integrity": "sha512-Uk6ovhRbTg6FmXjeZW/TkbRM07KPtvM5gah1BIMp4Y2s+i/NMxgaLw0+PbYTOdw1+egE0FP3mWRiGcRkjjmhzA==", "hasInstallScript": true, "dependencies": { "@cypress/request": "^3.0.0", "@cypress/xvfb": "^1.2.4", - "@types/node": "^18.17.5", "@types/sinonjs__fake-timers": "8.1.1", "@types/sizzle": "^2.3.2", "arch": "^2.2.0", "blob-util": "^2.0.2", "bluebird": "^3.7.2", - "buffer": "^5.6.0", + "buffer": "^5.7.1", "cachedir": "^2.3.0", "chalk": "^4.1.0", "check-more-types": "^2.24.0", @@ -4261,7 +4260,7 @@ "figures": "^3.2.0", "fs-extra": "^9.1.0", "getos": "^3.2.1", - "is-ci": "^3.0.0", + "is-ci": "^3.0.1", "is-installed-globally": "~0.4.0", "lazy-ass": "^1.6.0", "listr2": "^3.8.3", diff --git a/test/package.json b/test/package.json index a8655f8..63b6409 100755 --- a/test/package.json +++ b/test/package.json @@ -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", diff --git a/test/specs/misc.spec.js b/test/specs/misc.spec.js index 25f5583..1a43260 100755 --- a/test/specs/misc.spec.js +++ b/test/specs/misc.spec.js @@ -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); + });