This repository has been archived by the owner on Aug 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Run and show test results in the editor #8
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
eb14239
Runner skeleton
jacobmendoza 4d02424
Foundations of test runner
jacobmendoza ca43e68
First version of working UI without format
jacobmendoza f58fde7
Assigning x as key for running tests
jacobmendoza d1ac430
Conversion of main.js to ES6
jacobmendoza 7986bbd
Conversion of panel.js to ES6
jacobmendoza 7d8bec9
Conversion of test-runner-process.js to ES6
jacobmendoza b872b85
Conversion of test-runner-process.js to ES6
jacobmendoza 77e54ee
Small redesign on runner process events
jacobmendoza 596f5e5
Dependencies updated
jacobmendoza 4fabeec
TestRunnerProcess emits events now with EventEmitter
jacobmendoza ddc1f8e
Conversion of terminal-command-executor to ES6
jacobmendoza af98d9a
TerminalCommandExecutor emits events now with EventEmitter
jacobmendoza 469e2bf
Cancellation mechanism when the user toggles the package
jacobmendoza 054827a
event-kit dependency removed
jacobmendoza c9ea899
Initial cancellation mechanism
jacobmendoza 3955950
Toggling the plugin launches the test runner process
jacobmendoza 2f5319d
Addressing issues marked by xo
jacobmendoza 86b5ed2
Files use now /** @babel */ header
jacobmendoza f71d3ab
Items separated by lines in the environments for xo
jacobmendoza f35825a
Keymap uses now JSON
jacobmendoza f8675ed
Using new ES2015 import syntax
jacobmendoza 33d8d6e
Fixing double quotes in ava.less
jacobmendoza 90b97ad
Changing from spaces to tabs
jacobmendoza ec2f444
Removing cancelling process
jacobmendoza b4868b2
Fixing trailing spaces error
jacobmendoza e6a3385
Trying to fix errors due to outdated xo version
jacobmendoza b9a7069
Initial implementation of current execution check before running tests
jacobmendoza e7fe057
First step towards new rendering infrastructure
jacobmendoza bc8a08b
Refactoring the creation of the parser to a factory
jacobmendoza f8135c1
Initial extraction of test running logic from the panel
jacobmendoza dbe0a32
UI improvements
jacobmendoza 83c0d2c
Injecting Panel dependency
jacobmendoza 267805e
Update file-name header
jacobmendoza 27304ac
Trying to fix xo errors that werent catch by my local version
jacobmendoza 4059434
Initial extraction of template for the panel view
jacobmendoza 87ce941
Initial changes in the UI towards supporting multiple files
jacobmendoza 786465a
New loading indicator
jacobmendoza a35c73d
Removing the dependency on the status code
jacobmendoza dc5cc76
Adapting tests to new test runner api
jacobmendoza 4458a8a
Solved error in the template: both columns had passed as text
jacobmendoza b2d0b8b
Chaging the close icon
jacobmendoza 6d6449a
TODO and SKIP tests are not taken as failed/passed
jacobmendoza 7d3aa5e
Fixes in the styles towards supporting better themes
jacobmendoza 099a5ff
Preventing crashes when the user does not have an window with active …
jacobmendoza 2bd121b
Fixed some discrepancy in the summary when the suite has skip/todo tests
jacobmendoza 71b5372
AVA logo served from local asset
jacobmendoza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"atom-workspace": { | ||
"ctrl-alt-r": "ava:run", | ||
"ctrl-alt-a": "ava:toggle" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** @babel */ | ||
|
||
class HtmlRendererHelper { | ||
createContainer(cssClass = null, textContent = null) { | ||
const element = document.createElement('div'); | ||
if (cssClass) { | ||
element.classList.add(cssClass); | ||
} | ||
if (textContent) { | ||
element.textContent = textContent; | ||
} | ||
return element; | ||
} | ||
|
||
createImage(src, cssClass = null) { | ||
const img = document.createElement('img'); | ||
img.src = src; | ||
img.classList.add(cssClass); | ||
return img; | ||
} | ||
} | ||
|
||
module.exports = HtmlRendererHelper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** @babel */ | ||
|
||
import path from 'path'; | ||
import {CompositeDisposable} from 'atom'; | ||
import Panel from './panel.js'; | ||
import TestRunnerProcess from './test-runner-process'; | ||
|
||
module.exports = { | ||
activate(state) { | ||
this.initRunnerProcess(); | ||
this.initUI(state); | ||
|
||
this.subscriptions = new CompositeDisposable(); | ||
|
||
this.subscriptions.add( | ||
atom.commands.add('atom-workspace', 'ava:toggle', () => this.toggle())); | ||
|
||
this.subscriptions.add( | ||
atom.commands.add('atom-workspace', 'ava:run', () => this.run())); | ||
}, | ||
initRunnerProcess() { | ||
this.testRunnerProcess = new TestRunnerProcess(); | ||
this.testRunnerProcess.on('assert', result => this.panel.renderAssert(result)); | ||
this.testRunnerProcess.on('complete', results => this.panel.renderFinalReport(results)); | ||
}, | ||
initUI() { | ||
this.panel = new Panel(this); | ||
this.panel.renderBase(); | ||
this.atomPanel = atom.workspace.addRightPanel({item: this.panel, visible: false}); | ||
}, | ||
canRun() { | ||
return (atom.workspace.getActiveTextEditor() && this.testRunnerProcess.canRun()); | ||
}, | ||
run() { | ||
if (!this.atomPanel.isVisible()) { | ||
this.toggle(); | ||
} | ||
if (!this.canRun()) { | ||
return; | ||
} | ||
|
||
const editor = atom.workspace.getActiveTextEditor(); | ||
const currentFileName = editor.buffer.file.path; | ||
const folder = path.dirname(currentFileName); | ||
const file = path.basename(currentFileName); | ||
|
||
this.panel.renderStartProcess(file); | ||
this.testRunnerProcess.run(folder, file); | ||
}, | ||
toggle() { | ||
if (this.atomPanel.isVisible()) { | ||
this.atomPanel.hide(); | ||
} else { | ||
this.atomPanel.show(); | ||
this.run(); | ||
} | ||
}, | ||
closePanel() { | ||
this.atomPanel.hide(); | ||
}, | ||
deactivate() { | ||
this.subscriptions.dispose(); | ||
this.panel.destroy(); | ||
}, | ||
serialize() { | ||
this.atomAva = this.panel.serialize(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** @babel */ | ||
/* global __dirname */ | ||
|
||
import path from 'path'; | ||
import fs from 'fs'; | ||
import HtmlRendererHelper from './html-renderer-helper'; | ||
|
||
class Panel { | ||
constructor(pluginInstance, htmlRendererHelper = new HtmlRendererHelper()) { | ||
this.htmlRendererHelper = htmlRendererHelper; | ||
this.pluginInstance = pluginInstance; | ||
this.loadingSelector = 'sk-three-bounce'; | ||
} | ||
|
||
renderBase() { | ||
this.element = document.createElement('div'); | ||
this.element.classList.add('ava'); | ||
|
||
const resolvedPath = path.resolve(__dirname, '../views/panel.html'); | ||
this.element.innerHTML = fs.readFileSync(resolvedPath); | ||
|
||
this.testsContainer = this.element.getElementsByClassName('tests-container')[0]; | ||
const closeIcon = this.element.getElementsByClassName('close-icon')[0]; | ||
closeIcon.addEventListener('click', e => this.pluginInstance.closePanel(e), false); | ||
} | ||
|
||
renderAssert(assertResult) { | ||
const assert = assertResult.assert; | ||
|
||
const newTest = this.htmlRendererHelper.createContainer('test'); | ||
newTest.classList.add(this._getCssClassForAssert(assert)); | ||
newTest.textContent = `${assert.name}`; | ||
this.testsContainer.appendChild(newTest); | ||
|
||
this._updateTestStatisticSection(assertResult); | ||
} | ||
|
||
_getCssClassForAssert(assert) { | ||
if (assert.ok) { | ||
return (assert.skip) ? 'skipped' : 'ok'; | ||
} | ||
return (assert.todo) ? 'todo' : 'ko'; | ||
} | ||
|
||
renderFinalReport(results) { | ||
this.hideExecutingIndicator(); | ||
|
||
const summary = this.htmlRendererHelper.createContainer('summary'); | ||
const passed = results.pass - (results.skip ? results.skip : 0); | ||
const percentage = Math.round((passed / results.count) * 100); | ||
summary.textContent = `${results.count} total - ${percentage}% passed`; | ||
|
||
this.testsContainer.appendChild(summary); | ||
} | ||
|
||
cleanTestsContainer() { | ||
this.testsContainer.innerHTML = ''; | ||
} | ||
|
||
renderStartProcess(fileName) { | ||
const fileHeader = document.getElementById('file-header'); | ||
fileHeader.textContent = fileName; | ||
|
||
this.displayExecutingIndicator(); | ||
this.cleanTestsContainer(); | ||
} | ||
|
||
displayExecutingIndicator() { | ||
const executing = document.getElementById(this.loadingSelector); | ||
if (executing) { | ||
executing.style.display = 'block'; | ||
} | ||
} | ||
|
||
hideExecutingIndicator() { | ||
const executing = document.getElementById(this.loadingSelector); | ||
if (executing) { | ||
executing.style.display = 'none'; | ||
} | ||
} | ||
|
||
_updateTestStatisticSection(assertResult) { | ||
const passedContainer = document.getElementById('passed'); | ||
const failedContainer = document.getElementById('failed'); | ||
passedContainer.textContent = assertResult.currentExecution.passed; | ||
failedContainer.textContent = assertResult.currentExecution.failed; | ||
} | ||
|
||
serialize() { } | ||
|
||
destroy() { | ||
this.element.remove(); | ||
} | ||
} | ||
|
||
module.exports = Panel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** @babel */ | ||
|
||
import parser from 'tap-parser'; | ||
|
||
class ParserFactory { | ||
getParser() { | ||
return parser(); | ||
} | ||
} | ||
|
||
module.exports = ParserFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** @babel */ | ||
|
||
import EventEmitter from 'events'; | ||
import ChildProcess from 'child_process'; | ||
|
||
class TerminalCommandExecutor extends EventEmitter { | ||
constructor() { | ||
super(); | ||
EventEmitter.call(this); | ||
|
||
this.dataReceivedEventName = 'dataReceived'; | ||
this.dataFinishedEventName = 'dataFinished'; | ||
} | ||
|
||
run(command, destinyFolder = null) { | ||
this.command = command; | ||
this.destinyFolder = destinyFolder; | ||
|
||
const spawn = ChildProcess.spawn; | ||
|
||
this.terminal = spawn('bash', ['-l']); | ||
this.terminal.on('close', statusCode => this._streamClosed(statusCode)); | ||
this.terminal.stdout.on('data', data => this._stdOutDataReceived(data)); | ||
this.terminal.stderr.on('data', data => this._stdErrDataReceived(data)); | ||
|
||
const terminalCommand = this.destinyFolder ? | ||
`cd \"${this.destinyFolder}\" && ${this.command}\n` : | ||
`${this.command}\n`; | ||
|
||
this.terminal.stdin.write(terminalCommand); | ||
this.terminal.stdin.write('exit\n'); | ||
} | ||
|
||
_stdOutDataReceived(newData) { | ||
this.emit(this.dataReceivedEventName, newData.toString()); | ||
} | ||
|
||
_stdErrDataReceived(newData) { | ||
this.emit(this.dataReceivedEventName, newData.toString()); | ||
} | ||
|
||
_streamClosed(code) { | ||
this.emit(this.dataFinishedEventName, code); | ||
} | ||
} | ||
|
||
module.exports = TerminalCommandExecutor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** @babel */ | ||
|
||
import EventEmitter from 'events'; | ||
import TerminalCommandExecutor from './terminal-command-executor'; | ||
import ParserFactory from './parser-factory'; | ||
|
||
class TestRunnerProcess extends EventEmitter { | ||
constructor( | ||
executor = new TerminalCommandExecutor(), | ||
parserFactory = new ParserFactory()) { | ||
super(); | ||
|
||
this.eventHandlers = {}; | ||
this.terminalCommandExecutor = executor; | ||
this.parserFactory = parserFactory; | ||
|
||
this.terminalCommandExecutor.on('dataReceived', data => this._addAvaOutput(data)); | ||
this.terminalCommandExecutor.on('dataFinished', () => this._endAvaOutput()); | ||
|
||
EventEmitter.call(this); | ||
} | ||
|
||
canRun() { | ||
return !this.isRunning; | ||
} | ||
|
||
run(folder, file) { | ||
if (!this.canRun()) { | ||
return; | ||
} | ||
|
||
this.isRunning = true; | ||
this.currentExecution = {passed: 0, failed: 0}; | ||
|
||
this.parser = this.parserFactory.getParser(); | ||
this._setHandlersOnParser(this.parser); | ||
|
||
const command = `ava ${file} --tap`; | ||
|
||
this.terminalCommandExecutor.run(command, folder); | ||
} | ||
|
||
_setHandlersOnParser(parser) { | ||
const instance = this; | ||
parser.on('assert', assert => { | ||
instance._updateCurrentExecution(assert); | ||
const result = { | ||
currentExecution: this.currentExecution, assert | ||
}; | ||
instance.emit('assert', result); | ||
}); | ||
|
||
parser.on('complete', results => this.emit('complete', results)); | ||
} | ||
|
||
_updateCurrentExecution(assert) { | ||
if (assert.ok) { | ||
if (!assert.skip) { | ||
this.currentExecution.passed++; | ||
} | ||
} else if (!assert.todo) { | ||
this.currentExecution.failed++; | ||
} | ||
} | ||
|
||
_addAvaOutput(data) { | ||
this.parser.write(data); | ||
} | ||
|
||
_endAvaOutput() { | ||
this.parser.end(); | ||
this.isRunning = false; | ||
} | ||
|
||
destroy() { | ||
this.isRunning = false; | ||
this.terminalCommandExecutor.destroy(); | ||
} | ||
} | ||
|
||
module.exports = TestRunnerProcess; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just rename
main.js
toindex.js
and use"main": "lib",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not working for me... not sure if I'm missing something.