From 39b3a9a54e80f7344a7bc7fa3368548af1104173 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Thu, 5 Nov 2020 11:49:27 -0500 Subject: [PATCH] test stack trace lines with full error --- .../fixtures/cy_command_failed_error.json | 43 +++++++++++++++++ .../cypress/integration/test_errors_spec.js | 46 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 packages/reporter/cypress/fixtures/cy_command_failed_error.json diff --git a/packages/reporter/cypress/fixtures/cy_command_failed_error.json b/packages/reporter/cypress/fixtures/cy_command_failed_error.json new file mode 100644 index 000000000000..0b31e3126686 --- /dev/null +++ b/packages/reporter/cypress/fixtures/cy_command_failed_error.json @@ -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" + } +} diff --git a/packages/reporter/cypress/integration/test_errors_spec.js b/packages/reporter/cypress/integration/test_errors_spec.js index 25c6752caadc..9f4542bafb35 100644 --- a/packages/reporter/cypress/integration/test_errors_spec.js +++ b/packages/reporter/cypress/integration/test_errors_spec.js @@ -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') + }) +})