|
| 1 | +import type { InvocationDetails } from '../../../src/cypress/stack_utils' |
| 2 | + |
| 3 | +// Create a custom it function that will add additional stack frames that need to be trimmed correctly |
| 4 | +function myIt (name: string, optionsOrFn: any, fn?: () => void) { |
| 5 | + if (fn) { |
| 6 | + it(name, optionsOrFn, fn) |
| 7 | + } else { |
| 8 | + it(name, optionsOrFn) |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +// Note: the tests in this spec assert against their own invocation details. So if any of the line numbers change in this file, the assertions will need to be updated. |
| 13 | +it('has correct invocation details for a test at root level', () => { |
| 14 | + const details = Cypress.state('test').invocationDetails as InvocationDetails |
| 15 | + const isChromium = Cypress.isBrowser({ family: 'chromium' }) |
| 16 | + const isFirefox = Cypress.isBrowser({ family: 'firefox' }) |
| 17 | + |
| 18 | + expect(details.absoluteFile).to.satisfy((file: string) => { |
| 19 | + return file.endsWith('cypress/packages/driver/cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 20 | + }) |
| 21 | + |
| 22 | + expect(details.fileUrl).to.equal('http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 23 | + expect(details.originalFile).to.equal('webpack://@packages/driver/./cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 24 | + expect(details.relativeFile).to.equal('cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 25 | + expect(details.line).to.equal(13) // the line number should be the line number of the invocation of this test |
| 26 | + |
| 27 | + if (isChromium) { |
| 28 | + expect(details.column).to.equal(0) |
| 29 | + expect(details.function).to.equal('eval') |
| 30 | + expect(details.stack).to.equal(`Error |
| 31 | + at eval (http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts:16:1) |
| 32 | + at eval (http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts:155:12) |
| 33 | + at eval (<anonymous>) |
| 34 | + at eval (cypress:///../driver/src/cypress/script_utils.ts:38:23) |
| 35 | + at tryCatcher (cypress:///../../node_modules/bluebird/js/release/util.js:17:23)`) |
| 36 | + } else if (isFirefox) { |
| 37 | + expect(details.column).to.equal(3) |
| 38 | + expect(details.function).to.equal('<unknown>') |
| 39 | + |
| 40 | + // the firefox traces are really long, so just validate the first line |
| 41 | + const firstLine = details.stack.split('\n')[0] |
| 42 | + |
| 43 | + expect(firstLine).to.equal('@http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts:16:3') |
| 44 | + } |
| 45 | +}) |
| 46 | + |
| 47 | +myIt('has correct invocation details for myIt test at root level', function () { |
| 48 | + const details = Cypress.state('test').invocationDetails as InvocationDetails |
| 49 | + const isChromium = Cypress.isBrowser({ family: 'chromium' }) |
| 50 | + const isFirefox = Cypress.isBrowser({ family: 'firefox' }) |
| 51 | + |
| 52 | + expect(details.absoluteFile).to.satisfy((file: string) => { |
| 53 | + return file.endsWith('cypress/packages/driver/cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 54 | + }) |
| 55 | + |
| 56 | + expect(details.fileUrl).to.equal('http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 57 | + expect(details.originalFile).to.equal('webpack://@packages/driver/./cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 58 | + expect(details.relativeFile).to.equal('cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 59 | + expect(details.line).to.equal(47) // the line number should be the line number of the invocation of this test |
| 60 | + |
| 61 | + if (isChromium) { |
| 62 | + expect(details.function).to.equal('eval') |
| 63 | + expect(details.column).to.equal(0) |
| 64 | + expect(details.stack).to.equal(`Error |
| 65 | + at eval (http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts:50:1) |
| 66 | + at eval (http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts:155:12) |
| 67 | + at eval (<anonymous>) |
| 68 | + at eval (cypress:///../driver/src/cypress/script_utils.ts:38:23)`) |
| 69 | + } else if (isFirefox) { |
| 70 | + expect(details.column).to.equal(5) |
| 71 | + expect(details.function).to.equal('<unknown>') |
| 72 | + |
| 73 | + // the firefox traces are really long, so just validate the first line |
| 74 | + const firstLine = details.stack.split('\n')[0] |
| 75 | + |
| 76 | + expect(firstLine).to.equal('@http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts:50:5') |
| 77 | + } |
| 78 | +}) |
| 79 | + |
| 80 | +describe('outer describe block', () => { |
| 81 | + context('inner context block', () => { |
| 82 | + it('has correctinvocation details', function () { |
| 83 | + // Get invocation details from Cypress object |
| 84 | + const details = Cypress.state('test').invocationDetails as InvocationDetails |
| 85 | + const isChromium = Cypress.isBrowser({ family: 'chromium' }) |
| 86 | + const isFirefox = Cypress.isBrowser({ family: 'firefox' }) |
| 87 | + |
| 88 | + expect(details.absoluteFile).to.satisfy((file: string) => { |
| 89 | + return file.endsWith('cypress/packages/driver/cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 90 | + }) |
| 91 | + |
| 92 | + expect(details.fileUrl).to.equal('http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 93 | + expect(details.originalFile).to.equal('webpack://@packages/driver/./cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 94 | + expect(details.relativeFile).to.equal('cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 95 | + expect(details.line).to.equal(82) // the line number should be the line number of the invocation of this test |
| 96 | + |
| 97 | + if (isChromium) { |
| 98 | + expect(details.function).to.equal('Suite.eval') |
| 99 | + expect(details.column).to.equal(4) |
| 100 | + expect(details.stack).to.equal(`Error |
| 101 | + at Suite.eval (http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts:85:5) |
| 102 | + at Object.create (cypress:///../driver/node_modules/mocha/lib/interfaces/common.js:141:19) |
| 103 | + at context.describe.context.context (cypress:///../driver/node_modules/mocha/lib/interfaces/bdd.js:42:27) |
| 104 | + at createRunnable (cypress:///../driver/src/cypress/mocha.ts:128:31) |
| 105 | + at eval (cypress:///../driver/src/cypress/mocha.ts:189:14)`) |
| 106 | + } else if (isFirefox) { |
| 107 | + expect(details.column).to.equal(7) |
| 108 | + expect(details.function).to.equal('<unknown>') |
| 109 | + |
| 110 | + // the firefox traces are really long, so just validate the first line |
| 111 | + const firstLine = details.stack.split('\n')[0] |
| 112 | + |
| 113 | + expect(firstLine).to.equal('@http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts:85:7') |
| 114 | + } |
| 115 | + }) |
| 116 | + |
| 117 | + myIt('has correct invocation details for myIt test', function () { |
| 118 | + const details = Cypress.state('test').invocationDetails as InvocationDetails |
| 119 | + const isChromium = Cypress.isBrowser({ family: 'chromium' }) |
| 120 | + const isFirefox = Cypress.isBrowser({ family: 'firefox' }) |
| 121 | + |
| 122 | + expect(details.absoluteFile).to.satisfy((file: string) => { |
| 123 | + return file.endsWith('cypress/packages/driver/cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 124 | + }) |
| 125 | + |
| 126 | + expect(details.fileUrl).to.equal('http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 127 | + expect(details.originalFile).to.equal('webpack://@packages/driver/./cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 128 | + expect(details.relativeFile).to.equal('cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts') |
| 129 | + expect(details.line).to.equal(117) // the line number should be the line number of the invocation of this test |
| 130 | + |
| 131 | + if (isChromium) { |
| 132 | + expect(details.function).to.equal('Suite.eval') |
| 133 | + expect(details.column).to.equal(4) |
| 134 | + expect(details.stack).to.equal(`Error |
| 135 | + at Suite.eval (http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts:120:5) |
| 136 | + at Object.create (cypress:///../driver/node_modules/mocha/lib/interfaces/common.js:141:19) |
| 137 | + at context.describe.context.context (cypress:///../driver/node_modules/mocha/lib/interfaces/bdd.js:42:27) |
| 138 | + at createRunnable (cypress:///../driver/src/cypress/mocha.ts:128:31)`) |
| 139 | + } else if (isFirefox) { |
| 140 | + expect(details.column).to.equal(9) |
| 141 | + |
| 142 | + // the firefox traces are really long, so just validate the first line |
| 143 | + const firstLine = details.stack.split('\n')[0] |
| 144 | + |
| 145 | + expect(firstLine).to.equal('@http://localhost:3500/__cypress/tests?p=cypress/e2e/cypress/stack_utils-invocationDetails.cy.ts:120:9') |
| 146 | + } |
| 147 | + }) |
| 148 | + }) |
| 149 | +}) |
0 commit comments