Skip to content

Commit

Permalink
Merge pull request #126 from Autre31415/karmaTesting
Browse files Browse the repository at this point in the history
Automate client tests with karma
  • Loading branch information
kethinov authored May 3, 2017
2 parents fc78793 + fe19d48 commit 67fe52d
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 297 deletions.
2 changes: 2 additions & 0 deletions .istanbul.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
reporting:
dir: ./coverage/server
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
language: node_js
node_js:
- "node"
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
after_success:
- istanbul cover ./node_modules/mocha/bin/_mocha
- cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
- karma start
- lcov-result-merger 'coverage/**/lcov.info' 'coverage/fullCoverage.info'
- cat ./coverage/fullCoverage.info | ./node_modules/.bin/coveralls
67 changes: 67 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Karma configuration

module.exports = function(config) {
var configuration = {
basePath: '',
frameworks: ['mocha'],
files: [
'teddy.js',
'test/models/*.js',
'node_modules/chai/chai.js',
'node_modules/chai-string/chai-string.js',
'test/templates/**/*',
'test/*.js',
'test/client.html'
],
reporters: ['spec', 'coverage'],
port: 8000,
proxies: {
'/templates/': '/base/test/templates/',
},
preprocessors: {
'teddy.js': ['coverage'],
'test/templates/**/*': ['html2js']
},
html2JsPreprocessor: {
stripPrefix: 'test/templates/'
},
specReporter: {
maxLogLines: 5,
suppressErrorSummary: false,
suppressFailed: false,
suppressPassed: false,
suppressSkipped: false,
showSpecTiming: true
},
coverageReporter: {
type: 'lcov',
dir: 'coverage/',
subdir: function(browser) {
return browser.toLowerCase().split(/[ /-]/)[0];
}
},
client: {
mocha: {
reporter: 'html'
}
},
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
singleRun: true,
browsers: ['Chrome'],
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
concurrency: 1
};

if (process.env.TRAVIS) {
configuration.browsers = ['Chrome_travis_ci'];
}

config.set(configuration);
};
22 changes: 17 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@
"dependencies": {
},
"devDependencies": {
"eslint": "3.13.1",
"eslint": "3.19.0",
"mocha": "3.2.0",
"chai": "3.5.0",
"chai-string": "1.3.0",
"istanbul": "0.4.5",
"mocha-lcov-reporter": "1.3.0",
"coveralls": "2.12.0",
"cross-env": "4.0.0"
"coveralls": "2.13.0",
"cross-env": "4.0.0",
"karma": "1.6.0",
"karma-cli": "1.0.1",
"karma-mocha": "1.3.0",
"karma-coverage": "1.1.1",
"karma-chrome-launcher": "2.0.0",
"karma-coverage-allsources": "0.0.4",
"lcov-result-merger": "^1.2.0",
"karma-html2js-preprocessor": "1.1.0",
"karma-spec-reporter": "0.0.31"
},
"eslintConfig": {
"env": {
Expand Down Expand Up @@ -54,9 +63,12 @@
}
},
"scripts": {
"test": "cross-env NODE_ENV=test mocha --recursive test",
"test": "cross-env NODE_ENV=test npm run test-server && npm run test-client",
"test-server": "cross-env NODE_ENV=test mocha --recursive test",
"test-client": "karma start",
"eslint": "eslint .",
"cover": "cross-env NODE_ENV=cover istanbul cover _mocha --recursive test"
"cover": "cross-env NODE_ENV=cover istanbul cover _mocha --recursive test",
"coverage": "npm run cover"
},
"pre-commit": [
"test",
Expand Down
45 changes: 33 additions & 12 deletions teddy.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,7 @@
*/

// default values for parameters sent to teddy
params: {
verbosity: 1,
templateRoot: './',
cacheRenders: false,
defaultCaches: 1,
templateMaxCaches: {},
cacheWhitelist: false,
cacheBlacklist: [],
compileAtEveryRender: false,
minify: false,
maxPasses: 25000
},
params: {},

// compiled templates are stored as object collections, e.g. { "myTemplate.html": "<p>some markup</p>"}
templates: {},
Expand All @@ -102,6 +91,20 @@
* mutator methods for public member vars
*/

// sets all params to their default values
setDefaultParams: function() {
teddy.params.verbosity = 1;
teddy.params.templateRoot = './';
teddy.params.cacheRenders = false;
teddy.params.defaultCaches = 1;
teddy.params.templateMaxCaches = {};
teddy.params.cacheWhitelist = false;
teddy.params.cacheBlacklist = [];
teddy.params.compileAtEveryRender = false;
teddy.params.minify = false;
teddy.params.maxPasses = 25000;
},

// mutator method to set verbosity param. takes human-readable string argument and converts it to an integer for more efficient checks against the setting
setVerbosity: function(v) {
switch (v) {
Expand Down Expand Up @@ -225,6 +228,12 @@
}
}
}
else {
if (teddy.templates[template]) {
template = teddy.templates[template];
register = true;
}
}

// remove {! comments !} and (optionally) unnecessary whitespace
do {
Expand Down Expand Up @@ -257,6 +266,15 @@
// invalidates cache of a given template and model combination
// if no model is supplied, deletes all caches of the given template
flushCache: function(template, model) {

// ensure template is a string
if (typeof template !== 'string') {
if (teddy.params.verbosity > 1) {
teddy.console.warn('teddy.flushCache attempted to invalidate cache of template that is not a string');
}
return '';
}

// append extension if not present
if (template.slice(-5) !== '.html') {
template += '.html';
Expand Down Expand Up @@ -1174,6 +1192,9 @@
}
};

// set params to default values
teddy.setDefaultParams();

/**
* private utility methods
*/
Expand Down
Loading

0 comments on commit 67fe52d

Please sign in to comment.