Browse Source

Add proper console output for jasmine tests and proper include. Creates new test for running with continuous integration or for local watch

pull/258/head
jlukic 11 years ago
parent
commit
eb6ed4befc
10 changed files with 1167 additions and 117 deletions
  1. 2
      .travis.yml
  2. 144
      Gruntfile.js
  3. 71
      package.json
  4. 320
      test/coverage/PhantomJS 1.9.2 (Linux)/index.html
  5. 1
      test/coverage/PhantomJS 1.9.2 (Linux)/prettify.css
  6. 1
      test/coverage/PhantomJS 1.9.2 (Linux)/prettify.js
  7. 1
      test/coverage/coverage-PhantomJS 1.9.2 (Linux)-20131014_005413.json
  8. 705
      test/helpers/jasmine-jquery.js
  9. 32
      test/karma.conf.js
  10. 7
      test/modules/modal.js

2
.travis.yml

@ -3,4 +3,4 @@ node_js:
- "0.10"
before_script:
- npm install -g grunt-cli
- grunt test
- grunt test --verbose

144
Gruntfile.js

@ -15,13 +15,16 @@ module.exports = function(grunt) {
'copy:srcToDocs',
// copies examples over to docs
'copy:examplesToDocs',
'copy:examplesToDocs'
],
testTasks = [
// compiles less to docs so phantomjs can read
'less:buildTestCSS',
// test components
'karma:test:run'
'karma:travis'
],
buildTasks = [
@ -85,7 +88,7 @@ module.exports = function(grunt) {
setWatchFiles = function(action, filePath) {
var
buildPath = filePath.replace('src/', 'docs/build/').replace('less', 'css')
buildPath = filePath.replace('../src/', '../docs/build/').replace('less', 'css')
;
if(filePath.search('.less') !== -1) {
grunt.config('less.buildDocsCSS.src', filePath);
@ -120,15 +123,15 @@ module.exports = function(grunt) {
},
scripts: {
files: [
'src/**/*.js'
'../src/**/*.js'
],
tasks : testTasks
tasks : ['karma:test:run']
},
src: {
files: [
'build/examples/**/*',
'src/**/*.less',
'src/**/*.js'
'../build/examples/**/*',
'../src/**/*.less',
'../src/**/*.js'
],
tasks : watchTasks
}
@ -143,6 +146,10 @@ module.exports = function(grunt) {
configFile : 'test/karma.conf.js',
background : true,
reporters: 'dots'
},
travis: {
configFile : 'test/karma.conf.js',
singleRun : true
}
},
@ -155,28 +162,28 @@ module.exports = function(grunt) {
force: true
},
build : [
'build/less',
'build/minified',
'build/packaged',
'build/uncompressed'
'../build/less',
'../build/minified',
'../build/packaged',
'../build/uncompressed'
],
release : [
'docs/build',
'docs',
'rtl'
'../docs/build',
'../docs',
'../rtl'
]
},
docco: {
generate: {
options: {
css : 'spec/assets/docco.css',
output : 'spec/docs/'
css : '../spec/assets/docco.css',
output : '../spec/docs/'
},
files: [
{
expand : true,
cwd : 'spec/',
cwd : '../spec/',
src : [
'**.commented.js'
]
@ -188,37 +195,47 @@ module.exports = function(grunt) {
cssjanus: {
rtl: {
expand : true,
cwd : 'build/',
cwd : '../build/',
src : [
'**/*.less',
'**/*.css',
],
dest : 'rtl'
dest : '../rtl'
},
},
less: {
options: {
paths : ['src'],
paths : ['../src'],
compress : false,
optimization : 2
},
// optimized for watch, src is built on watch task using callbacks
buildDocsCSS: {
src : 'src',
dest : 'docs/build/uncompressed/',
src : '../src',
dest : '../docs/build/uncompressed/',
rename : preserveFileExtensions
},
buildTestCSS: {
expand : true,
cwd : '../src',
src : [
'**/*.less'
],
dest : '../docs/build/uncompressed/',
rename: preserveFileExtensions
},
buildCSS: {
expand : true,
cwd : 'src',
cwd : '../src',
src : [
'**/*.less'
],
dest : 'build/uncompressed/',
dest : '../build/uncompressed/',
rename: preserveFileExtensions
}
},
@ -231,44 +248,44 @@ module.exports = function(grunt) {
// exact copy for less
{
expand : true,
cwd : 'src/**/*.less',
cwd : '../src/**/*.less',
src : [
'**/*'
],
dest : 'docs/build/less'
dest : '../docs/build/less'
},
// copy everything but less files for uncompressed release
{
expand : true,
cwd : 'src/',
cwd : '../src/',
src : [
'**/*.js',
'images/*',
'fonts/*'
],
dest : 'docs/build/uncompressed'
dest : '../docs/build/uncompressed'
},
// copy everything but less for minified release
{
expand : true,
cwd : 'src/',
cwd : '../src/',
src : [
'**/*.js',
'images/*',
'fonts/*'
],
dest : 'docs/build/minified'
dest : '../docs/build/minified'
},
// copy assets only for packaged version
{
expand : true,
cwd : 'src/',
cwd : '../src/',
src : [
'images/*',
'fonts/*'
],
dest : 'docs/build/packaged'
dest : '../docs/build/packaged'
}
]
},
@ -279,44 +296,44 @@ module.exports = function(grunt) {
// exact copy for less
{
expand : true,
cwd : 'src/',
cwd : '../src/',
src : [
'**/*'
],
dest : 'build/less'
dest : '../build/less'
},
// copy everything but less files for uncompressed release
{
expand : true,
cwd : 'src/',
cwd : '../src/',
src : [
'**/*.js',
'images/*',
'fonts/*'
],
dest : 'build/uncompressed'
dest : '../build/uncompressed'
},
// copy everything but less for minified release
{
expand : true,
cwd : 'src/',
cwd : '../src/',
src : [
'**/*.js',
'images/*',
'fonts/*'
],
dest : 'build/minified'
dest : '../build/minified'
},
// copy assets only for packaged version
{
expand : true,
cwd : 'src/',
cwd : '../src/',
src : [
'images/*',
'fonts/*'
],
dest : 'build/packaged'
dest : '../build/packaged'
}
]
},
@ -326,11 +343,11 @@ module.exports = function(grunt) {
files: [
{
expand : true,
cwd : 'build/',
cwd : '../build/',
src : [
'**'
],
dest : 'rtl'
dest : '../rtl'
}
]
},
@ -340,11 +357,11 @@ module.exports = function(grunt) {
files: [
{
expand : true,
cwd : 'build/',
cwd : '../build/',
src : [
'**'
],
dest : 'docs/build/'
dest : '../docs/build/'
}
]
},
@ -354,11 +371,11 @@ module.exports = function(grunt) {
files: [
{
expand : true,
cwd : 'spec',
cwd : '../spec',
src : [
'**'
],
dest : 'docs/spec/'
dest : '../docs/spec/'
}
]
},
@ -368,11 +385,11 @@ module.exports = function(grunt) {
files: [
{
expand : true,
cwd : 'build/examples',
cwd : '../build/examples',
src : [
'**'
],
dest : 'docs/examples/'
dest : '../docs/examples/'
}
]
}
@ -382,13 +399,13 @@ module.exports = function(grunt) {
compress: {
options: {
archive: 'docs/build/semantic.zip'
archive: '../docs/build/semantic.zip'
},
everything: {
files: [
{
expand : true,
cwd : 'build/',
cwd : '../build/',
src : [
'**'
]
@ -401,12 +418,12 @@ module.exports = function(grunt) {
options: {
},
concatenateCSS: {
src: ["build/uncompressed/**/*.css"],
dest: "build/packaged/css/semantic.css"
src: ["../build/uncompressed/**/*.css"],
dest: "../build/packaged/css/semantic.css"
},
concatenateJS: {
src: ["build/uncompressed/**/*.js"],
dest: "build/packaged/javascript/semantic.js"
src: ["../build/uncompressed/**/*.js"],
dest: "../build/packaged/javascript/semantic.js"
},
},
@ -415,11 +432,11 @@ module.exports = function(grunt) {
// copy minified css to minified release
minifyCSS: {
expand : true,
cwd : 'build/uncompressed',
cwd : '../build/uncompressed',
src : [
'**/*.css'
],
dest : 'build/minified',
dest : '../build/minified',
ext : '.min.css'
},
@ -441,8 +458,8 @@ module.exports = function(grunt) {
'*/\n'
},
files: {
'build/packaged/css/semantic.min.css': [
'build/uncompressed/**/*.css'
'../build/packaged/css/semantic.min.css': [
'../build/uncompressed/**/*.css'
]
}
}
@ -452,11 +469,11 @@ module.exports = function(grunt) {
minifyJS: {
expand : true,
cwd : 'build/uncompressed',
cwd : '../build/uncompressed',
src : [
'**/*.js'
],
dest : 'build/minified',
dest : '../build/minified',
ext : '.min.js',
banner : '' +
'/*' +
@ -492,8 +509,8 @@ module.exports = function(grunt) {
'*/\n'
},
files: {
'build/packaged/javascript/semantic.min.js': [
'build/uncompressed/**/*.js'
'../build/packaged/javascript/semantic.min.js': [
'../build/uncompressed/**/*.js'
]
}
}
@ -515,7 +532,6 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-karma');
grunt.initConfig(config);
grunt.registerTask('default', defaultTasks);
grunt.registerTask('build', buildTasks);
grunt.registerTask('test', testTasks);

71
package.json

@ -1,41 +1,42 @@
{
"name" : "semantic",
"title" : "Semantic UI",
"description" : "Semantic empowers designers and developers by creating a shared vocabulary for UI.",
"homepage" : "http://www.semantic-ui.com",
"author" : "Jack Lukic <jacklukic@gmail.com>",
"name": "semantic",
"title": "Semantic UI",
"description": "Semantic empowers designers and developers by creating a shared vocabulary for UI.",
"homepage": "http://www.semantic-ui.com",
"author": "Jack Lukic <jacklukic@gmail.com>",
"license": "MIT",
"dependencies" : {
"docpad" : "~6.53.4",
"docpad-plugin-eco" : "~2.0.2",
"docpad-plugin-ghpages" : "~2.4.0",
"docpad-plugin-partials" : "~2.8.0"
"dependencies": {
"docpad": "~6.53.4",
"docpad-plugin-eco": "~2.0.2",
"docpad-plugin-ghpages": "~2.4.0",
"docpad-plugin-partials": "~2.8.0"
},
"devDependencies": {
"grunt" : "~0.4.1",
"grunt-contrib-watch" : "~0.5.3",
"grunt-contrib-clean" : "~0.5.0",
"grunt-contrib-uglify" : "~0.2.2",
"grunt-contrib-cssmin" : "~0.6.1",
"grunt-contrib-less" : "~0.7.0",
"grunt-contrib-copy" : "~0.4.1",
"grunt-docco" : "~0.2.0",
"grunt-bower-task" : "~0.3.1",
"grunt-css" : "~0.5.4",
"grunt-contrib-compress" : "~0.5.2",
"grunt-contrib-concat" : "~0.3.0",
"grunt-docco-multi" : "0.0.2",
"grunt-cssjanus" : "~0.1.1",
"karma-script-launcher" : "~0.1.0",
"karma-chrome-launcher" : "~0.1.0",
"karma-firefox-launcher" : "~0.1.0",
"karma-html2js-preprocessor" : "~0.1.0",
"karma-jasmine" : "~0.1.3",
"karma-requirejs" : "~0.1.0",
"karma-coffee-preprocessor" : "~0.1.0",
"karma-phantomjs-launcher" : "~0.1.0",
"karma" : "~0.10.2",
"grunt-karma" : "~0.6.2"
"grunt": "~0.4.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-cssmin": "~0.6.1",
"grunt-contrib-less": "~0.7.0",
"grunt-contrib-copy": "~0.4.1",
"grunt-docco": "~0.2.0",
"grunt-bower-task": "~0.3.1",
"grunt-css": "~0.5.4",
"grunt-contrib-compress": "~0.5.2",
"grunt-contrib-concat": "~0.3.0",
"grunt-docco-multi": "0.0.2",
"grunt-cssjanus": "~0.1.1",
"karma-script-launcher": "~0.1.0",
"karma-chrome-launcher": "~0.1.0",
"karma-firefox-launcher": "~0.1.0",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.3",
"karma-requirejs": "~0.1.0",
"karma-coffee-preprocessor": "~0.1.0",
"karma-phantomjs-launcher": "~0.1.0",
"karma": "~0.10.2",
"grunt-karma": "~0.6.2",
"karma-coverage": "~0.1.0",
"karma-spec-reporter": "0.0.5"
}
}

320
test/coverage/PhantomJS 1.9.2 (Linux)/index.html

@ -0,0 +1,320 @@
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for All files</title>
<meta charset="utf-8">
<link rel="stylesheet" href="prettify.css">
<style>
body, html {
margin:0; padding: 0;
}
body {
font-family: Helvetica Neue, Helvetica,Arial;
font-size: 10pt;
}
div.header, div.footer {
background: #eee;
padding: 1em;
}
div.header {
z-index: 100;
position: fixed;
top: 0;
border-bottom: 1px solid #666;
width: 100%;
}
div.footer {
border-top: 1px solid #666;
}
div.body {
margin-top: 10em;
}
div.meta {
font-size: 90%;
text-align: center;
}
h1, h2, h3 {
font-weight: normal;
}
h1 {
font-size: 12pt;
}
h2 {
font-size: 10pt;
}
pre {
font-family: Consolas, Menlo, Monaco, monospace;
margin: 0;
padding: 0;
line-height: 14px;
font-size: 14px;
-moz-tab-size: 2;
-o-tab-size: 2;
tab-size: 2;
}
div.path { font-size: 110%; }
div.path a:link, div.path a:visited { color: #000; }
table.coverage { border-collapse: collapse; margin:0; padding: 0 }
table.coverage td {
margin: 0;
padding: 0;
color: #111;
vertical-align: top;
}
table.coverage td.line-count {
width: 50px;
text-align: right;
padding-right: 5px;
}
table.coverage td.line-coverage {
color: #777 !important;
text-align: right;
border-left: 1px solid #666;
border-right: 1px solid #666;
}
table.coverage td.text {
}
table.coverage td span.cline-any {
display: inline-block;
padding: 0 5px;
width: 40px;
}
table.coverage td span.cline-neutral {
background: #eee;
}
table.coverage td span.cline-yes {
background: #b5d592;
color: #999;
}
table.coverage td span.cline-no {
background: #fc8c84;
}
.cstat-yes { color: #111; }
.cstat-no { background: #fc8c84; color: #111; }
.fstat-no { background: #ffc520; color: #111 !important; }
.cbranch-no { background: yellow !important; color: #111; }
.missing-if-branch {
display: inline-block;
margin-right: 10px;
position: relative;
padding: 0 4px;
background: black;
color: yellow;
xtext-decoration: line-through;
}
.missing-if-branch .typ {
color: inherit !important;
}
.entity, .metric { font-weight: bold; }
.metric { display: inline-block; border: 1px solid #333; padding: 0.3em; background: white; }
.metric small { font-size: 80%; font-weight: normal; color: #666; }
div.coverage-summary table { border-collapse: collapse; margin: 3em; font-size: 110%; }
div.coverage-summary td, div.coverage-summary table th { margin: 0; padding: 0.25em 1em; border-top: 1px solid #666; border-bottom: 1px solid #666; }
div.coverage-summary th { text-align: left; border: 1px solid #666; background: #eee; font-weight: normal; }
div.coverage-summary th.file { border-right: none !important; }
div.coverage-summary th.pic { border-left: none !important; text-align: right; }
div.coverage-summary th.pct { border-right: none !important; }
div.coverage-summary th.abs { border-left: none !important; text-align: right; }
div.coverage-summary td.pct { text-align: right; border-left: 1px solid #666; }
div.coverage-summary td.abs { text-align: right; font-size: 90%; color: #444; border-right: 1px solid #666; }
div.coverage-summary td.file { text-align: right; border-left: 1px solid #666; white-space: nowrap; }
div.coverage-summary td.pic { min-width: 120px !important; }
div.coverage-summary a:link { text-decoration: none; color: #000; }
div.coverage-summary a:visited { text-decoration: none; color: #333; }
div.coverage-summary a:hover { text-decoration: underline; }
div.coverage-summary tfoot td { border-top: 1px solid #666; }
div.coverage-summary .yui3-datatable-sort-indicator, div.coverage-summary .dummy-sort-indicator {
height: 10px;
width: 7px;
display: inline-block;
margin-left: 0.5em;
}
div.coverage-summary .yui3-datatable-sort-indicator {
background: url("http://yui.yahooapis.com/3.6.0/build/datatable-sort/assets/skins/sam/sort-arrow-sprite.png") no-repeat scroll 0 0 transparent;
}
div.coverage-summary .yui3-datatable-sorted .yui3-datatable-sort-indicator {
background-position: 0 -20px;
}
div.coverage-summary .yui3-datatable-sorted-desc .yui3-datatable-sort-indicator {
background-position: 0 -10px;
}
.high { background: #b5d592 !important; }
.medium { background: #ffe87c !important; }
.low { background: #fc8c84 !important; }
span.cover-fill, span.cover-empty {
display:inline-block;
border:1px solid #444;
background: white;
height: 12px;
}
span.cover-fill {
background: #ccc;
border-right: 1px solid #444;
}
span.cover-empty {
background: white;
border-left: none;
}
span.cover-full {
border-right: none !important;
}
pre.prettyprint {
border: none !important;
padding: 0 !important;
margin: 0 !important;
}
.com { color: #999 !important; }
</style>
</head>
<body>
<div class="header high">
<h1>Code coverage report for <span class="entity">All files</span></h1>
<h2>
Statements: <span class="metric">100% <small>(0 / 0)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Branches: <span class="metric">100% <small>(0 / 0)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Functions: <span class="metric">100% <small>(0 / 0)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Lines: <span class="metric">100% <small>(0 / 0)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
</h2>
<div class="path"></div>
</div>
<div class="body">
<div class="coverage-summary">
<table>
<thead>
<tr>
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="footer">
<div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Oct 14 2013 01:12:43 GMT-0400 (EDT)</div>
</div>
<script src="prettify.js"></script>
<script src="http://yui.yahooapis.com/3.6.0/build/yui/yui-min.js"></script>
<script>
YUI().use('datatable', function (Y) {
var formatters = {
pct: function (o) {
o.className += o.record.get('classes')[o.column.key];
try {
return o.value.toFixed(2) + '%';
} catch (ex) { return o.value + '%'; }
},
html: function (o) {
o.className += o.record.get('classes')[o.column.key];
return o.record.get(o.column.key + '_html');
}
},
defaultFormatter = function (o) {
o.className += o.record.get('classes')[o.column.key];
return o.value;
};
function getColumns(theadNode) {
var colNodes = theadNode.all('tr th'),
cols = [],
col;
colNodes.each(function (colNode) {
col = {
key: colNode.getAttribute('data-col'),
label: colNode.get('innerHTML') || ' ',
sortable: !colNode.getAttribute('data-nosort'),
className: colNode.getAttribute('class'),
type: colNode.getAttribute('data-type'),
allowHTML: colNode.getAttribute('data-html') === 'true' || colNode.getAttribute('data-fmt') === 'html'
};
col.formatter = formatters[colNode.getAttribute('data-fmt')] || defaultFormatter;
cols.push(col);
});
return cols;
}
function getRowData(trNode, cols) {
var tdNodes = trNode.all('td'),
i,
row = { classes: {} },
node,
name;
for (i = 0; i < cols.length; i += 1) {
name = cols[i].key;
node = tdNodes.item(i);
row[name] = node.getAttribute('data-value') || node.get('innerHTML');
row[name + '_html'] = node.get('innerHTML');
row.classes[name] = node.getAttribute('class');
//Y.log('Name: ' + name + '; Value: ' + row[name]);
if (cols[i].type === 'number') { row[name] = row[name] * 1; }
}
//Y.log(row);
return row;
}
function getData(tbodyNode, cols) {
var data = [];
tbodyNode.all('tr').each(function (trNode) {
data.push(getRowData(trNode, cols));
});
return data;
}
function replaceTable(node) {
if (!node) { return; }
var cols = getColumns(node.one('thead')),
data = getData(node.one('tbody'), cols),
table,
parent = node.get('parentNode');
table = new Y.DataTable({
columns: cols,
data: data,
sortBy: 'file'
});
parent.set('innerHTML', '');
table.render(parent);
}
Y.on('domready', function () {
replaceTable(Y.one('div.coverage-summary table'));
if (typeof prettyPrint === 'function') {
prettyPrint();
}
});
});
</script>
</body>
</html>

1
test/coverage/PhantomJS 1.9.2 (Linux)/prettify.css

@ -0,0 +1 @@
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}

1
test/coverage/PhantomJS 1.9.2 (Linux)/prettify.js
File diff suppressed because it is too large
View File

1
test/coverage/coverage-PhantomJS 1.9.2 (Linux)-20131014_005413.json

@ -0,0 +1 @@
{}

705
test/helpers/jasmine-jquery.js

@ -0,0 +1,705 @@
/*!
Jasmine-jQuery: a set of jQuery helpers for Jasmine tests.
Version 1.5.91
https://github.com/velesin/jasmine-jquery
Copyright (c) 2010-2013 Wojciech Zawistowski, Travis Jeffery
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+function (jasmine, $) { "use strict";
jasmine.spiedEventsKey = function (selector, eventName) {
return [$(selector).selector, eventName].toString()
}
jasmine.getFixtures = function () {
return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures()
}
jasmine.getStyleFixtures = function () {
return jasmine.currentStyleFixtures_ = jasmine.currentStyleFixtures_ || new jasmine.StyleFixtures()
}
jasmine.Fixtures = function () {
this.containerId = 'jasmine-fixtures'
this.fixturesCache_ = {}
this.fixturesPath = 'spec/javascripts/fixtures'
}
jasmine.Fixtures.prototype.set = function (html) {
this.cleanUp()
return this.createContainer_(html)
}
jasmine.Fixtures.prototype.appendSet= function (html) {
this.addToContainer_(html)
}
jasmine.Fixtures.prototype.preload = function () {
this.read.apply(this, arguments)
}
jasmine.Fixtures.prototype.load = function () {
this.cleanUp()
this.createContainer_(this.read.apply(this, arguments))
}
jasmine.Fixtures.prototype.appendLoad = function () {
this.addToContainer_(this.read.apply(this, arguments))
}
jasmine.Fixtures.prototype.read = function () {
var htmlChunks = []
, fixtureUrls = arguments
for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]))
}
return htmlChunks.join('')
}
jasmine.Fixtures.prototype.clearCache = function () {
this.fixturesCache_ = {}
}
jasmine.Fixtures.prototype.cleanUp = function () {
$('#' + this.containerId).remove()
}
jasmine.Fixtures.prototype.sandbox = function (attributes) {
var attributesToSet = attributes || {}
return $('<div id="sandbox" />').attr(attributesToSet)
}
jasmine.Fixtures.prototype.createContainer_ = function (html) {
var container = $('<div>')
.attr('id', this.containerId)
.html(html)
$(document.body).append(container)
return container
}
jasmine.Fixtures.prototype.addToContainer_ = function (html){
var container = $(document.body).find('#'+this.containerId).append(html)
if(!container.length){
this.createContainer_(html)
}
}
jasmine.Fixtures.prototype.getFixtureHtml_ = function (url) {
if (typeof this.fixturesCache_[url] === 'undefined') {
this.loadFixtureIntoCache_(url)
}
return this.fixturesCache_[url]
}
jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
var self = this
, url = this.makeFixtureUrl_(relativeUrl)
, request = $.ajax({
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
cache: false,
url: url,
success: function (data, status, $xhr) {
self.fixturesCache_[relativeUrl] = $xhr.responseText
},
error: function (jqXHR, status, errorThrown) {
throw new Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
}
})
}
jasmine.Fixtures.prototype.makeFixtureUrl_ = function (relativeUrl){
return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
}
jasmine.Fixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) {
return this[methodName].apply(this, passedArguments)
}
jasmine.StyleFixtures = function () {
this.fixturesCache_ = {}
this.fixturesNodes_ = []
this.fixturesPath = 'spec/javascripts/fixtures'
}
jasmine.StyleFixtures.prototype.set = function (css) {
this.cleanUp()
this.createStyle_(css)
}
jasmine.StyleFixtures.prototype.appendSet = function (css) {
this.createStyle_(css)
}
jasmine.StyleFixtures.prototype.preload = function () {
this.read_.apply(this, arguments)
}
jasmine.StyleFixtures.prototype.load = function () {
this.cleanUp()
this.createStyle_(this.read_.apply(this, arguments))
}
jasmine.StyleFixtures.prototype.appendLoad = function () {
this.createStyle_(this.read_.apply(this, arguments))
}
jasmine.StyleFixtures.prototype.cleanUp = function () {
while(this.fixturesNodes_.length) {
this.fixturesNodes_.pop().remove()
}
}
jasmine.StyleFixtures.prototype.createStyle_ = function (html) {
var styleText = $('<div></div>').html(html).text()
, style = $('<style>' + styleText + '</style>')
this.fixturesNodes_.push(style)
$('head').append(style)
}
jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache
jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read
jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_
jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_
jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_
jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_
jasmine.getJSONFixtures = function () {
return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures()
}
jasmine.JSONFixtures = function () {
this.fixturesCache_ = {}
this.fixturesPath = 'spec/javascripts/fixtures/json'
}
jasmine.JSONFixtures.prototype.load = function () {
this.read.apply(this, arguments)
return this.fixturesCache_
}
jasmine.JSONFixtures.prototype.read = function () {
var fixtureUrls = arguments
for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
this.getFixtureData_(fixtureUrls[urlIndex])
}
return this.fixturesCache_
}
jasmine.JSONFixtures.prototype.clearCache = function () {
this.fixturesCache_ = {}
}
jasmine.JSONFixtures.prototype.getFixtureData_ = function (url) {
if (!this.fixturesCache_[url]) this.loadFixtureIntoCache_(url)
return this.fixturesCache_[url]
}
jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
var self = this
, url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
$.ajax({
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
cache: false,
dataType: 'json',
url: url,
success: function (data) {
self.fixturesCache_[relativeUrl] = data
},
error: function (jqXHR, status, errorThrown) {
throw new Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
}
})
}
jasmine.JSONFixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) {
return this[methodName].apply(this, passedArguments)
}
jasmine.JQuery = function () {}
jasmine.JQuery.browserTagCaseIndependentHtml = function (html) {
return $('<div/>').append(html).html()
}
jasmine.JQuery.elementToString = function (element) {
var domEl = $(element).get(0)
if (domEl === undefined || domEl.cloneNode)
return $('<div />').append($(element).clone()).html()
else
return element.toString()
}
jasmine.JQuery.matchersClass = {}
!function (namespace) {
var data = {
spiedEvents: {}
, handlers: []
}
namespace.events = {
spyOn: function (selector, eventName) {
var handler = function (e) {
data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = jasmine.util.argsToArray(arguments)
}
$(selector).on(eventName, handler)
data.handlers.push(handler)
return {
selector: selector,
eventName: eventName,
handler: handler,
reset: function (){
delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
}
}
},
args: function (selector, eventName) {
var actualArgs = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
if (!actualArgs) {
throw "There is no spy for " + eventName + " on " + selector.toString() + ". Make sure to create a spy using spyOnEvent."
}
return actualArgs
},
wasTriggered: function (selector, eventName) {
return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
},
wasTriggeredWith: function (selector, eventName, expectedArgs, env) {
var actualArgs = jasmine.JQuery.events.args(selector, eventName).slice(1)
if (Object.prototype.toString.call(expectedArgs) !== '[object Array]') {
actualArgs = actualArgs[0]
}
return env.equals_(expectedArgs, actualArgs)
},
wasPrevented: function (selector, eventName) {
var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
, e = args ? args[0] : undefined
return e && e.isDefaultPrevented()
},
wasStopped: function (selector, eventName) {
var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
, e = args ? args[0] : undefined
return e && e.isPropagationStopped()
},
cleanUp: function () {
data.spiedEvents = {}
data.handlers = []
}
}
}(jasmine.JQuery)
!function (){
var jQueryMatchers = {
toHaveClass: function (className) {
return this.actual.hasClass(className)
},
toHaveCss: function (css){
for (var prop in css){
var value = css[prop]
// see issue #147 on gh
;if (value === 'auto' && this.actual.get(0).style[prop] === 'auto') continue
if (this.actual.css(prop) !== value) return false
}
return true
},
toBeVisible: function () {
return this.actual.is(':visible')
},
toBeHidden: function () {
return this.actual.is(':hidden')
},
toBeSelected: function () {
return this.actual.is(':selected')
},
toBeChecked: function () {
return this.actual.is(':checked')
},
toBeEmpty: function () {
return this.actual.is(':empty')
},
toExist: function () {
return this.actual.length
},
toHaveLength: function (length) {
return this.actual.length === length
},
toHaveAttr: function (attributeName, expectedAttributeValue) {
return hasProperty(this.actual.attr(attributeName), expectedAttributeValue)
},
toHaveProp: function (propertyName, expectedPropertyValue) {
return hasProperty(this.actual.prop(propertyName), expectedPropertyValue)
},
toHaveId: function (id) {
return this.actual.attr('id') == id
},
toHaveHtml: function (html) {
return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html)
},
toContainHtml: function (html){
var actualHtml = this.actual.html()
, expectedHtml = jasmine.JQuery.browserTagCaseIndependentHtml(html)
return (actualHtml.indexOf(expectedHtml) >= 0)
},
toHaveText: function (text) {
var trimmedText = $.trim(this.actual.text())
if (text && $.isFunction(text.test)) {
return text.test(trimmedText)
} else {
return trimmedText == text
}
},
toContainText: function (text) {
var trimmedText = $.trim(this.actual.text())
if (text && $.isFunction(text.test)) {
return text.test(trimmedText)
} else {
return trimmedText.indexOf(text) != -1
}
},
toHaveValue: function (value) {
return this.actual.val() === value
},
toHaveData: function (key, expectedValue) {
return hasProperty(this.actual.data(key), expectedValue)
},
toBe: function (selector) {
return this.actual.is(selector)
},
toContain: function (selector) {
return this.actual.find(selector).length
},
toBeMatchedBy: function (selector) {
return this.actual.filter(selector).length
},
toBeDisabled: function (selector){
return this.actual.is(':disabled')
},
toBeFocused: function (selector) {
return this.actual[0] === this.actual[0].ownerDocument.activeElement
},
toHandle: function (event) {
var events = $._data(this.actual.get(0), "events")
if(!events || !event || typeof event !== "string") {
return false
}
var namespaces = event.split(".")
, eventType = namespaces.shift()
, sortedNamespaces = namespaces.slice(0).sort()
, namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
if(events[eventType] && namespaces.length) {
for(var i = 0; i < events[eventType].length; i++) {
var namespace = events[eventType][i].namespace
if(namespaceRegExp.test(namespace)) {
return true
}
}
} else {
return events[eventType] && events[eventType].length > 0
}
},
toHandleWith: function (eventName, eventHandler) {
var normalizedEventName = eventName.split('.')[0]
, stack = $._data(this.actual.get(0), "events")[normalizedEventName]
for (var i = 0; i < stack.length; i++) {
if (stack[i].handler == eventHandler) return true
}
return false
}
}
var hasProperty = function (actualValue, expectedValue) {
if (expectedValue === undefined) return actualValue !== undefined
return actualValue == expectedValue
}
var bindMatcher = function (methodName) {
var builtInMatcher = jasmine.Matchers.prototype[methodName]
jasmine.JQuery.matchersClass[methodName] = function () {
if (this.actual
&& (this.actual instanceof $
|| jasmine.isDomNode(this.actual))) {
this.actual = $(this.actual)
var result = jQueryMatchers[methodName].apply(this, arguments)
, element
if (this.actual.get && (element = this.actual.get()[0]) && !$.isWindow(element) && element.tagName !== "HTML")
this.actual = jasmine.JQuery.elementToString(this.actual)
return result
}
if (builtInMatcher) {
return builtInMatcher.apply(this, arguments)
}
return false
}
}
for(var methodName in jQueryMatchers) {
bindMatcher(methodName)
}
}()
beforeEach(function () {
this.addMatchers(jasmine.JQuery.matchersClass)
this.addMatchers({
toHaveBeenTriggeredOn: function (selector) {
this.message = function () {
return [
"Expected event " + this.actual + " to have been triggered on " + selector,
"Expected event " + this.actual + " not to have been triggered on " + selector
]
}
return jasmine.JQuery.events.wasTriggered(selector, this.actual)
}
})
this.addMatchers({
toHaveBeenTriggered: function (){
var eventName = this.actual.eventName
, selector = this.actual.selector
this.message = function () {
return [
"Expected event " + eventName + " to have been triggered on " + selector,
"Expected event " + eventName + " not to have been triggered on " + selector
]
}
return jasmine.JQuery.events.wasTriggered(selector, eventName)
}
})
this.addMatchers({
toHaveBeenTriggeredOnAndWith: function () {
var selector = arguments[0]
, expectedArgs = arguments[1]
, wasTriggered = jasmine.JQuery.events.wasTriggered(selector, this.actual)
this.message = function () {
if (wasTriggered) {
var actualArgs = jasmine.JQuery.events.args(selector, this.actual, expectedArgs)[1]
return [
"Expected event " + this.actual + " to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs),
"Expected event " + this.actual + " not to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs)
]
} else {
return [
"Expected event " + this.actual + " to have been triggered on " + selector,
"Expected event " + this.actual + " not to have been triggered on " + selector
]
}
}
return wasTriggered && jasmine.JQuery.events.wasTriggeredWith(selector, this.actual, expectedArgs, this.env)
}
})
this.addMatchers({
toHaveBeenPreventedOn: function (selector) {
this.message = function () {
return [
"Expected event " + this.actual + " to have been prevented on " + selector,
"Expected event " + this.actual + " not to have been prevented on " + selector
]
}
return jasmine.JQuery.events.wasPrevented(selector, this.actual)
}
})
this.addMatchers({
toHaveBeenPrevented: function () {
var eventName = this.actual.eventName
, selector = this.actual.selector
this.message = function () {
return [
"Expected event " + eventName + " to have been prevented on " + selector,
"Expected event " + eventName + " not to have been prevented on " + selector
]
}
return jasmine.JQuery.events.wasPrevented(selector, eventName)
}
})
this.addMatchers({
toHaveBeenStoppedOn: function (selector) {
this.message = function () {
return [
"Expected event " + this.actual + " to have been stopped on " + selector,
"Expected event " + this.actual + " not to have been stopped on " + selector
]
}
return jasmine.JQuery.events.wasStopped(selector, this.actual)
}
})
this.addMatchers({
toHaveBeenStopped: function () {
var eventName = this.actual.eventName
, selector = this.actual.selector
this.message = function () {
return [
"Expected event " + eventName + " to have been stopped on " + selector,
"Expected event " + eventName + " not to have been stopped on " + selector
]
}
return jasmine.JQuery.events.wasStopped(selector, eventName)
}
})
jasmine.getEnv().addEqualityTester(function (a, b) {
if(a instanceof jQuery && b instanceof jQuery) {
if(a.size() != b.size()) {
return jasmine.undefined
}
else if(a.is(b)) {
return true
}
}
return jasmine.undefined
})
})
afterEach(function () {
jasmine.getFixtures().cleanUp()
jasmine.getStyleFixtures().cleanUp()
jasmine.JQuery.events.cleanUp()
})
}(window.jasmine, window.jQuery)
+function (jasmine, global) { "use strict";
global.readFixtures = function () {
return jasmine.getFixtures().proxyCallTo_('read', arguments)
}
global.preloadFixtures = function () {
jasmine.getFixtures().proxyCallTo_('preload', arguments)
}
global.loadFixtures = function () {
jasmine.getFixtures().proxyCallTo_('load', arguments)
}
global.appendLoadFixtures = function () {
jasmine.getFixtures().proxyCallTo_('appendLoad', arguments)
}
global.setFixtures = function (html) {
return jasmine.getFixtures().proxyCallTo_('set', arguments)
}
global.appendSetFixtures = function () {
jasmine.getFixtures().proxyCallTo_('appendSet', arguments)
}
global.sandbox = function (attributes) {
return jasmine.getFixtures().sandbox(attributes)
}
global.spyOnEvent = function (selector, eventName) {
return jasmine.JQuery.events.spyOn(selector, eventName)
}
global.preloadStyleFixtures = function () {
jasmine.getStyleFixtures().proxyCallTo_('preload', arguments)
}
global.loadStyleFixtures = function () {
jasmine.getStyleFixtures().proxyCallTo_('load', arguments)
}
global.appendLoadStyleFixtures = function () {
jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments)
}
global.setStyleFixtures = function (html) {
jasmine.getStyleFixtures().proxyCallTo_('set', arguments)
}
global.appendSetStyleFixtures = function (html) {
jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments)
}
global.loadJSONFixtures = function () {
return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
}
global.getJSONFixture = function (url) {
return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
}
}(jasmine, window);

32
test/karma.conf.js

@ -1,52 +1,53 @@
// Karma configuration
// Generated on Sun Oct 13 2013 15:14:38 GMT-0400 (EDT)
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: ['jasmine'],
frameworks: [
'jasmine'
],
// list of files / patterns to load in the browser
files: [
'**/*.js'
// require jquery
'../server/files/javascript/library/jquery.js',
// read css from compiled css
'../docs/build/**/*.css',
// read js from src js
'../src/**/*.js',
// require helpers
'helpers/*.js',
// require tests
'modules/*.js'
],
// list of files to exclude
exclude: [
'**/*.swp',
'karma.conf.js'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
reporters: ['spec', 'coverage'],
preprocessors: { '*.js': ['coverage'] },
// web server port
port: 9876,
port: 9999,
// 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: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
@ -61,7 +62,6 @@ module.exports = function(config) {
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false

7
test/modules/modal.js

@ -1,5 +1,10 @@
describe("A suite", function() {
describe("UI Modal", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
it("contains another spec with another expectation", function() {
expect(true).toBe(true);
});
});
Loading…
Cancel
Save