Permalink
Browse files

Run test suite using karma

  • Loading branch information...
1 parent 89b1c58 commit f02ba1f47b983781952d3f2585be7db350a9a714 @megawac megawac committed Feb 18, 2015
Showing with 82 additions and 139 deletions.
  1. +13 −0 .travis.yml
  2. +54 −0 karma.conf.js
  3. +6 −4 package.json
  4. +3 −8 test/index.html
  5. +6 −0 test/setup/dom-setup.js
  6. 0 test/{ → setup}/environment.js
  7. +0 −127 test/vendor/runner.js
View
@@ -3,3 +3,16 @@ node_js:
- '0.10'
notifications:
email: false
+addons:
+ firefox: '31.0'
+install:
+ - sudo apt-get install chromium-browser
+ - npm install -g karma-cli
+ - npm install
+ - npm install karma-firefox-launcher karma-chrome-launcher
+before_install:
+ - export CHROME_BIN=chromium-browser
+ - export DISPLAY=:99.0
+ - sh -e /etc/init.d/xvfb start
+script:
+ - karma start --browsers Firefox,PhantomJS,Chrome_sandbox
View
@@ -0,0 +1,54 @@
+// Note some browser launchers should be installed before using karma start.
+// For example:
+// npm install karma-firefox-launcher
+// karma start --browsers=Firefox
+module.exports = function(config) {
+ config.set({
+ basePath: '',
+ frameworks: ['qunit'],
+
+ // list of files / patterns to load in the browser
+ files: [
+ 'test/vendor/jquery.js',
+ 'test/vendor/json2.js',
+ 'test/vendor/underscore.js',
+ 'backbone.js',
+ 'test/setup/*.js',
+ 'test/*.js'
+ ],
+
+ // test results reporter to use
+ // possible values: 'dots', 'progress'
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
+ reporters: ['progress'],
+
+ // web server port
+ port: 9877,
+
+ // 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: false,
+
+ // start these browsers
+ // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
+ browsers: ['PhantomJS'],
+
+ // Continuous Integration mode
+ // if true, Karma captures browsers, runs the tests and exits
+ singleRun: true,
+
+ // See http://stackoverflow.com/a/27873086/1517919
+ customLaunchers: {
+ Chrome_sandbox: {
+ base: 'Chrome',
+ flags: ['--no-sandbox']
+ }
+ }
+ });
+};
View
@@ -8,13 +8,15 @@
"underscore" : ">=1.6.0"
},
"devDependencies": {
- "phantomjs": "1.9.7-8",
+ "coffee-script": "1.7.1",
"docco": "0.6.3",
- "coffee-script": "1.7.1"
+ "karma": "^0.12.31",
+ "karma-phantomjs-launcher": "^0.1.4",
+ "karma-qunit": "^0.1.4"
},
"main": "backbone.js",
"scripts": {
- "test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true && coffee test/model.coffee",
+ "test": "./node_modules/karma/bin/karma start && coffee test/model.coffee",
"build": "uglifyjs backbone.js --mangle --source-map backbone-min.map -o backbone-min.js",
"doc": "docco backbone.js && docco examples/todos/todos.js examples/backbone.localStorage.js",
"lint": "jsl -nofilelisting -nologo -conf docs/jsl.conf -process backbone.js"
@@ -29,4 +31,4 @@
"files": [
"backbone.js", "backbone-min.js", "backbone-min.map", "LICENSE"
]
-}
+}
View
@@ -1,23 +1,18 @@
-<!doctype html>
+<!DOCTYPE html>
<html>
<head>
<meta charset='utf8'>
<title>Backbone Test Suite</title>
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen">
</head>
<body>
- <div id="qunit"></div>
- <div id="qunit-fixture">
- <div id='testElement'>
- <h1>Test</h1>
- </div>
- </div>
+ <script src="setup/dom-setup.js"></script>
<script src="vendor/json2.js"></script>
<script src="vendor/jquery.js"></script>
<script src="vendor/qunit.js"></script>
<script src="vendor/underscore.js"></script>
<script src="../backbone.js"></script>
- <script src="environment.js"></script>
+ <script src="setup/environment.js"></script>
<script src="noconflict.js"></script>
<script src="events.js"></script>
<script src="model.js"></script>
@@ -0,0 +1,6 @@
+$('body').append(
+ '<div id="qunit"></div>' +
+ '<div id="qunit-fixture">' +
+ '<div id="testElement"><h1>Test</h1></div>' +
+ '</div>'
+);
File renamed without changes.
View
@@ -1,127 +0,0 @@
-/*
- * QtWebKit-powered headless test runner using PhantomJS
- *
- * PhantomJS binaries: http://phantomjs.org/download.html
- * Requires PhantomJS 1.6+ (1.7+ recommended)
- *
- * Run with:
- * phantomjs runner.js [url-of-your-qunit-testsuite]
- *
- * e.g.
- * phantomjs runner.js http://localhost/qunit/test/index.html
- */
-
-/*jshint latedef:false */
-/*global phantom:false, require:false, console:false, window:false, QUnit:false */
-
-(function() {
- 'use strict';
-
- var args = require('system').args;
-
- // arg[0]: scriptName, args[1...]: arguments
- if (args.length !== 2) {
- console.error('Usage:\n phantomjs runner.js [url-of-your-qunit-testsuite]');
- phantom.exit(1);
- }
-
- var url = args[1],
- page = require('webpage').create();
-
- // Route `console.log()` calls from within the Page context to the main Phantom context (i.e. current `this`)
- page.onConsoleMessage = function(msg) {
- console.log(msg);
- };
-
- page.onInitialized = function() {
- page.evaluate(addLogging);
- };
-
- page.onCallback = function(message) {
- var result,
- failed;
-
- if (message) {
- if (message.name === 'QUnit.done') {
- result = message.data;
- failed = !result || result.failed;
-
- phantom.exit(failed ? 1 : 0);
- }
- }
- };
-
- page.open(url, function(status) {
- if (status !== 'success') {
- console.error('Unable to access network: ' + status);
- phantom.exit(1);
- } else {
- // Cannot do this verification with the 'DOMContentLoaded' handler because it
- // will be too late to attach it if a page does not have any script tags.
- var qunitMissing = page.evaluate(function() { return (typeof QUnit === 'undefined' || !QUnit); });
- if (qunitMissing) {
- console.error('The `QUnit` object is not present on this page.');
- phantom.exit(1);
- }
-
- // Do nothing... the callback mechanism will handle everything!
- }
- });
-
- function addLogging() {
- window.document.addEventListener('DOMContentLoaded', function() {
- var current_test_assertions = [];
-
- QUnit.log(function(details) {
- var response;
-
- // Ignore passing assertions
- if (details.result) {
- return;
- }
-
- response = details.message || '';
-
- if (typeof details.expected !== 'undefined') {
- if (response) {
- response += ', ';
- }
-
- response += 'expected: ' + details.expected + ', but was: ' + details.actual;
- if (details.source) {
- response += "\n" + details.source;
- }
- }
-
- current_test_assertions.push('Failed assertion: ' + response);
- });
-
- QUnit.testDone(function(result) {
- var i,
- len,
- name = result.module + ': ' + result.name;
-
- if (result.failed) {
- console.log('Test failed: ' + name);
-
- for (i = 0, len = current_test_assertions.length; i < len; i++) {
- console.log(' ' + current_test_assertions[i]);
- }
- }
-
- current_test_assertions.length = 0;
- });
-
- QUnit.done(function(result) {
- console.log('Took ' + result.runtime + 'ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.');
-
- if (typeof window.callPhantom === 'function') {
- window.callPhantom({
- 'name': 'QUnit.done',
- 'data': result
- });
- }
- });
- }, false);
- }
-})();

0 comments on commit f02ba1f

Please sign in to comment.