Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from arobson/master
Programmatic control of testem
- Loading branch information
Showing
3 changed files
with
88 additions
and
1 deletion.
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,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 |
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
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 |
---|---|---|
|
@@ -67,6 +67,7 @@ | |
"bin": { | ||
"testem": "./testem.js" | ||
}, | ||
"main": "./lib/api.js", | ||
"bundleDependencies": [ | ||
"tap" | ||
], | ||
|