Skip to content

Commit

Permalink
feat: support LiveScript configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
czchen authored and vojtajina committed Jan 19, 2014
1 parent df557ce commit 88deebe
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
68 changes: 68 additions & 0 deletions config.tpl.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Karma configuration
# Generated on %DATE%

module.exports = (config) ->
config.set do

# base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '%BASE_PATH%'


# frameworks to use
# available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: [%FRAMEWORKS%]


# list of files / patterns to load in the browser
files: [
%FILES%
]


# list of files to exclude
exclude: [
%EXCLUDE%
]


# preprocess matching files before serving them to the browser
# available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: %PREPROCESSORS%


# test results reporter to use
# possible values: 'dots', 'progress'
# available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress']


# web server port
port: 9876


# enable / disable colors in the output (reporters and logs)
colors: true


# level of logging
# possible values:
# - config.LOG_DISABLE
# - config.LOG_ERROR
# - config.LOG_WARN
# - config.LOG_INFO
# - config.LOG_DEBUG
logLevel: config.LOG_INFO


# enable / disable watching file and executing tests whenever any file changes
autoWatch: %AUTO_WATCH%


# satart these browsers
# available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [%BROWSERS%]


# Continuous Integration mode
# if true, Karma captures browsers, runs the tests and exits
singleRun: false
5 changes: 5 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ var constant = require('./constants');
// It's not directly used in this file.
require('coffee-script');

// LiveScript is required here to enable config files written in LiveScript.
// It's not directly used in this file.
try {
require('LiveScript');
} catch (e) {}

var Pattern = function(pattern, served, included, watched) {
this.pattern = pattern;
Expand Down
21 changes: 20 additions & 1 deletion lib/init/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ var util = require('util');
var JS_TEMPLATE_PATH = __dirname + '/../../config.tpl.js';
var COFFEE_TEMPLATE_PATH = __dirname + '/../../config.tpl.coffee';
var COFFEE_REGEXP = /\.coffee$/;
var LIVE_TEMPLATE_PATH = __dirname + '/../../config.tpl.ls';
var LIVE_REGEXP = /\.ls$/;


var isCoffeeFile = function(filename) {
return COFFEE_REGEXP.test(filename);
};

var isLiveFile = function(filename) {
return LIVE_REGEXP.test(filename);
};

var JavaScriptFormatter = function() {

Expand Down Expand Up @@ -87,10 +92,24 @@ var CoffeeFormatter = function() {
this.TEMPLATE_FILE_PATH = COFFEE_TEMPLATE_PATH;
};

var LiveFormatter = function() {
JavaScriptFormatter.call(this);

this.TEMPLATE_FILE_PATH = LIVE_TEMPLATE_PATH;
};

exports.JavaScript = JavaScriptFormatter;
exports.Coffee = CoffeeFormatter;
exports.Live = LiveFormatter;

exports.createForPath = function(path) {
return isCoffeeFile(path) ? new CoffeeFormatter() : new JavaScriptFormatter();
if (isCoffeeFile(path)) {
return new CoffeeFormatter();
}

if (isLiveFile(path)) {
return new LiveFormatter();
}

return new JavaScriptFormatter();
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@
"karma-ng-scenario": "*",
"karma-coffee-preprocessor": "*",
"karma-html2js-preprocessor": "*",
"karma-browserstack-launcher": "*"
"karma-browserstack-launcher": "*",
"LiveScript": "~1.2.0"
},
"main": "./lib/index",
"bin": {},
Expand Down

0 comments on commit 88deebe

Please sign in to comment.