From 895f452bf591f08dfd8594a8d5b2616a6acab289 Mon Sep 17 00:00:00 2001 From: Lila Conlee Date: Wed, 13 Feb 2019 17:15:48 -0600 Subject: [PATCH 001/533] wip: add initial work for md in test error messages --- packages/reporter/src/errors/test-error.jsx | 33 ++++++++++ .../reporter/src/errors/test-error.spec.jsx | 65 +++++++++++++++++++ packages/reporter/src/lib/events.js | 4 ++ packages/reporter/src/test/test.jsx | 15 +---- packages/reporter/src/test/test.spec.jsx | 10 --- packages/runner/src/lib/event-manager.js | 4 ++ packages/server/lib/socket.coffee | 4 ++ 7 files changed, 113 insertions(+), 22 deletions(-) create mode 100644 packages/reporter/src/errors/test-error.jsx create mode 100644 packages/reporter/src/errors/test-error.spec.jsx diff --git a/packages/reporter/src/errors/test-error.jsx b/packages/reporter/src/errors/test-error.jsx new file mode 100644 index 000000000000..4898bf73ed9e --- /dev/null +++ b/packages/reporter/src/errors/test-error.jsx @@ -0,0 +1,33 @@ +import React, { Component } from 'react' +import Markdown from 'markdown-it' +import FlashOnClick from '../lib/flash-on-click' + +const md = new Markdown({ + linkify: true, +}) + +const formattedMessage = (message) => { + return message ? md.renderInline(message) : '' +} + +class TestError extends Component { + _onErrorClick = (e) => { + e.stopPropagation() + this.props.events.emit('show:error', this.props.model.id) + } + + render () { + const { displayMessage } = this.props.model.err + + return ( + +

+      
+ ) + } +} + +export default TestError diff --git a/packages/reporter/src/errors/test-error.spec.jsx b/packages/reporter/src/errors/test-error.spec.jsx new file mode 100644 index 000000000000..2873be5380db --- /dev/null +++ b/packages/reporter/src/errors/test-error.spec.jsx @@ -0,0 +1,65 @@ +import _ from 'lodash' +import React from 'react' +import { mount, shallow } from 'enzyme' +import sinon from 'sinon' + +import Hooks from '../hooks/hooks' + +import TestError from './test-error' + +const appStateStub = (props) => { + return _.extend({ + autoScrollingEnabled: true, + isRunning: true, + }, props) +} + +const eventsStub = () => ({ + emit: sinon.spy(), +}) + +const model = (props) => { + return _.extend({ + commands: [], + err: {}, + id: 't1', + isActive: true, + level: 1, + state: 'passed', + type: 'test', + shouldRender: true, + title: 'some title', + }, props) +} + +describe('', () => { + context('errors', () => { + it('emits show:error event and stops propagation when error is clicked', () => { + const events = eventsStub() + const component = shallow() + const e = { stopPropagation: sinon.spy() } + + component.find('FlashOnClick').simulate('click', e) + expect(events.emit).to.have.been.calledWith('show:error', 't1') + expect(e.stopPropagation).to.have.been.called + }) + + it('renders markdown', () => { + const component = shallow() + + expect(component.find('.test-error').prop('dangerouslySetInnerHTML').__html).to.include('markdown') + }) + + // TODO: this should be done in a cypress test once #3188 is merged in + it.skip('emits external:open and prevents default when link in error message is clicked', () => { + const events = eventsStub() + const url = 'http://example.com' + const component = shallow() + const e = { preventDefault: sinon.spy() } + + // component.find('a').simulate('click', e) + // expect(events.emit).to.have.been.calledWith('external:open', url) + // expect(e.preventDefault).to.have.been.called + }) + }) +}) diff --git a/packages/reporter/src/lib/events.js b/packages/reporter/src/lib/events.js index 34d646e3e1f4..380174852460 100644 --- a/packages/reporter/src/lib/events.js +++ b/packages/reporter/src/lib/events.js @@ -143,6 +143,10 @@ export default { autoScrollingEnabled: appState.autoScrollingEnabled, }) }) + + localBus.on('external:open', (url) => { + runner.emit('external:open', url) + }) }, emit (event, ...args) { diff --git a/packages/reporter/src/test/test.jsx b/packages/reporter/src/test/test.jsx index 9faf3301f9cf..feac6d16e654 100644 --- a/packages/reporter/src/test/test.jsx +++ b/packages/reporter/src/test/test.jsx @@ -13,7 +13,7 @@ import scroller from '../lib/scroller' import Hooks from '../hooks/hooks' import Agents from '../agents/agents' import Routes from '../routes/routes' -import FlashOnClick from '../lib/flash-on-click' +import TestError from '../errors/test-error' const NoCommands = observer(() => (