Skip to content

Commit

Permalink
Merge pull request #118 from arobson/master
Browse files Browse the repository at this point in the history
Programmatic control of testem
  • Loading branch information
airportyh committed Dec 11, 2012
2 parents c39abf1 + 4cdcc11 commit 4e4913e
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
86 changes: 86 additions & 0 deletions lib/api.js
@@ -0,0 +1,86 @@
var log = require('winston'),
Config = require('./config'),
catchem = require('./catchem'),
_ = require('underscore'),
Backbone = require('backbone'),
ProcessRunner = require('./runners').ProcessRunner;

/*
progOptions:
file: test file
port: 7357
launch: list of launchers to use
skip: list of launchers to skip
test_page: the page to use to run tests
timeout: timeout for a browser
framework: test framework to use
src_files: list of files or file patterns
*/


var EventLogger = Backbone.Model.extend({
initialize: function(attrs){
this.set({
name: attrs.name
, allPassed: true
, messages: new Backbone.Collection()
})
},
clear: function() {
this.get('messages').reset([])
},
hasMessages: function() {
var messages = this.get('messages')
return messages.length > 0
},
hasResults: function() { return false; },
addMessage: function( type, message, color ){
var messages = this.get('messages')
messages.push({ type: type, text: message, color: color })
},
startTests: function() {}
} )


catchem.on('err', function(e){
log.error(e.message)
log.error(e.stack)
})

var Api = function() {
_.bindAll( this )
}

Api.prototype.setup = function(mode, dependency){
var self = this,
App = require(dependency),
config = new Config(mode, this.options)
config.read(function() {
self.app = new App(config)
})
}

Api.prototype.startDev = function(options){
this.options = options
this.setup('dev', './dev_mode_app.js')
}

Api.prototype.restart = function() {
this.app.startTests( function() {} )
}

Api.prototype.startCI = function(options){
this.options = options
this.setup('ci', './ci_mode_app.js')
}

Api.prototype.getLogger = function( name ) {
var logger = new EventLogger({ name: name })
return logger
}

Api.prototype.addTab = function( logger ) {
this.app.runners.push( logger )
}

module.exports = Api
2 changes: 1 addition & 1 deletion lib/ui/split_log_panel.js
Expand Up @@ -220,7 +220,7 @@ var SplitLogPanel = module.exports = View.extend({
messages.forEach(function(message){
var type = message.get('type')
var text = message.get('text')
var color = type === 'error' ? 'red' : 'yellow'
var color = message.get('color') || ( type === 'error' ? 'red' : 'yellow' )
retval = retval.concat(StyledString(text, {foreground: color}))
})
return retval
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -67,6 +67,7 @@
"bin": {
"testem": "./testem.js"
},
"main": "./lib/api.js",
"bundleDependencies": [
"tap"
],
Expand Down

0 comments on commit 4e4913e

Please sign in to comment.