Skip to content

Commit

Permalink
test stack trace lines with full error
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Nov 5, 2020
1 parent 70d8c1b commit 39b3a9a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/reporter/cypress/fixtures/cy_command_failed_error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "AssertionError",
"message": "Timed out retrying: Expected to find element: `.new-todo`, but never found it.",
"stack": "AssertionError: Timed out retrying: Expected to find element: `.new-todo`, but never found it.\n at getInputBox (http://localhost:8888/__cypress/tests?p=cypress/integration/spec.js:130:13)\n at Context.eval (http://localhost:8888/__cypress/tests?p=cypress/integration/spec.js:105:32)",
"sourceMappedStack": "AssertionError: Timed out retrying: Expected to find element: `.new-todo`, but never found it.\n at getInputBox (webpack:///cypress/integration/test-utils.js:2:13)\n at Context.eval (webpack:///cypress/integration/spec.js:7:5)",
"parsedStack": [
{
"message": "AssertionError: Timed out retrying: Expected to find element: `.new-todo`, but never found it.",
"whitespace": ""
},
{
"function": "getInputBox",
"fileUrl": "http://localhost:8888/__cypress/tests?p=cypress/integration/spec.js",
"originalFile": "webpack:///cypress/integration/test-utils.js",
"relativeFile": "cypress/integration/test-utils.js",
"absoluteFile": "/Users/gleb/git/cypress-example-todomvc/cypress/integration/test-utils.js",
"line": 2,
"column": 13,
"whitespace": " "
},
{
"function": "Context.eval",
"fileUrl": "http://localhost:8888/__cypress/tests?p=cypress/integration/spec.js",
"originalFile": "webpack:///cypress/integration/spec.js",
"relativeFile": "cypress/integration/spec.js",
"absoluteFile": "/Users/gleb/git/cypress-example-todomvc/cypress/integration/spec.js",
"line": 7,
"column": 5,
"whitespace": " "
}
],
"docsUrl": "",
"templateType": "",
"codeFrame": {
"line": 2,
"column": 13,
"originalFile": "cypress/integration/test-utils.js",
"relativeFile": "cypress/integration/test-utils.js",
"absoluteFile": "/Users/gleb/git/cypress-example-todomvc/cypress/integration/test-utils.js",
"frame": " 1 | export const getInputBox = () => {\n> 2 | return cy.get('.new-todo')\n | ^\n 3 | }\n 4 | ",
"language": "js"
}
}
46 changes: 46 additions & 0 deletions packages/reporter/cypress/integration/test_errors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,49 @@ describe('test error without file info', function () {
cy.contains('.err-stack-line', 'http://localhost:8888/js/utils.js:60:4')
})
})

describe('test error with good file info', function () {
beforeEach(function () {
cy.fixture('runnables_error').as('runnablesErr')
cy.fixture('cy_command_failed_error').as('commandErr')

this.setError = function (err) {
this.runnablesErr.suites[0].tests[0].err = err

cy.get('.reporter').then(() => {
this.runner.emit('runnables:ready', this.runnablesErr)

this.runner.emit('reporter:start', {})
})
}

this.runner = new EventEmitter()

cy.visit('cypress/support/index.html').then((win) => {
win.render({
runner: this.runner,
spec: {
name: 'foo.js',
relative: 'relative/path/to/foo.js',
absolute: '/absolute/path/to/foo.js',
},
config: {
projectRoot: '/root',
},
})
})
})

it('has open IDE links', function () {
this.setError(this.commandErr)
cy.contains('View stack trace').click()
cy.get('.runnable-err-stack-trace').should('be.visible')
// both files should be visible as clickable
cy.get('.runnable-err-stack-trace .runnable-err-file-path').should('have.length', 2)
cy.contains('.runnable-err-stack-trace .runnable-err-file-path', 'test-utils.js:2:13')
cy.contains('.runnable-err-stack-trace .runnable-err-file-path', 'spec.js:7:5')

// the code frame also has the open file path
cy.contains('.test-err-code-frame .runnable-err-file-path', 'test-utils.js:2:13')
})
})

0 comments on commit 39b3a9a

Please sign in to comment.