Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: format time durations under 5 seconds as milliseconds #11

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions cypress/e2e/spec.cy.js → cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@ it('warns about time limit', () => {
.timeSince('start', 200)
})

it('duration under 5 seconds', () => {
// should show time in milliseconds
cy.spy(cy, 'log').as('log')
cy.timeMark('start').wait(4000).timeSince('start')
cy.get('@log')
.should('be.calledTwice')
.invoke('getCalls')
.should('have.length', 2)
.invoke('map', (c: any) => c.args[0])
.invoke({ timeout: 0 }, 'find', (msg: string) =>
msg.match(/\s\d+ms since \*\*start\*\*/),
)
.should('be.an', 'string')
})

it('duration above 5 seconds', () => {
// should show time in seconds
cy.spy(cy, 'log').as('log')
cy.timeMark('start').wait(5000).timeSince('start')
cy.get('@log')
.should('be.calledTwice')
.invoke('getCalls')
.should('have.length', 2)
.invoke('map', (c: any) => c.args[0])
.invoke({ timeout: 0 }, 'find', (msg: string) =>
msg.match(/\s00:05 since \*\*start\*\*/),
)
.should('be.an', 'string')
})

// confirm the failing test when the time limit has been exceeded
describe.skip('fails the test', () => {
it('fails the test if the elapsed time is above the limit', () => {
Expand Down
2 changes: 1 addition & 1 deletion 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",
"license": "MIT",
"devDependencies": {
"cypress": "^13.5.1",
"cypress": "^13.6.4",
"prettier": "^3.1.0",
"semantic-release": "^19.0.5",
"stop-only": "^3.1.2",
Expand Down
3 changes: 1 addition & 2 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
"excludePackagePatterns": ["cypress", "debug"],
"enabled": false
}
],
"ignorePaths": ["**/node_modules/**", "cypress-v9/**"]
]
}
16 changes: 9 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Cypress.Commands.add(
)

function formatDurationMs(ms) {
if (ms < 2000) {
if (ms < 5000) {
return ms + 'ms'
} else {
return format(ms, { leading: true })
Expand Down Expand Up @@ -51,12 +51,14 @@ Cypress.Commands.add(
timeLimit = label
label = undefined
}
console.log({
name,
label,
timeLimit,
throwError,
})

// for debugging only
// console.log({
// name,
// label,
// timeLimit,
// throwError,
// })

if (label) {
if (typeof label !== 'string') {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": ["./cypress/e2e/*.js"]
"include": ["./cypress/e2e/*.js", "cypress/e2e/spec.cy.ts"]
}