Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
Refactor client tests. Lots of WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-roemer committed Nov 12, 2015
1 parent 4cc7b4a commit 71544c1
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 170 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
@@ -1,7 +1,10 @@
language: node_js

node_js:
- 0.10
- "0.10"
- "0.12"

sudo: false

branches:
only:
Expand Down
21 changes: 11 additions & 10 deletions _templates/test/test.jade
Expand Up @@ -5,14 +5,19 @@ html
meta(http-equiv="X-UA-Compatible", content="IE=edge,chrome=1")

// Test styles and libraries.
link(rel="stylesheet", href="js/lib/mocha.css")
script(src="js/lib/mocha.js")
script(src="js/lib/sinon.js")
link(rel="stylesheet", href="../node_modules/mocha/mocha.css")

body
#mocha
#fixtures(style="position: absolute; bottom: 0;")

script(src="../node_modules/mocha/mocha.js")
script(src="../node_modules/sinon/pkg/sinon.js")

// Plugin deps and library.
block libs
script(src="js/lib/jquery.js")
script(src="js/lib/chai.js")
script(src="../node_modules/jquery/dist/jquery.js")
script(src="../node_modules/chai/chai.js")
script(src="../chai-jq.js")

// Test Setup
Expand All @@ -24,14 +29,10 @@ html

// Run tests on window load.
window.onload = function () {
(window.mochaPhantomJS || mocha).run();
mocha.run();
};
//-
// Tests.
block specs
script(src="js/spec/chai-jq.spec.js")

body
#mocha
#fixtures(style="position: absolute; bottom: 0;")
129 changes: 3 additions & 126 deletions gulpfile.js
Expand Up @@ -4,15 +4,10 @@
var fs = require("fs"),
_ = require("lodash"),
gulp = require("gulp"),
jshint = require("gulp-jshint"),
// TODO: Switch back to https://github.com/lazd/gulp-karma when
// https://github.com/lazd/gulp-karma/pull/22 is merged.
karma = require("gulp-karma"),
mocha = require("gulp-mocha"),
jade = require("gulp-jade"),
rename = require("gulp-rename"),
mdox = require("gulp-mdox"),
rimraf = require("gulp-rimraf");
mdox = require("gulp-mdox");

// ----------------------------------------------------------------------------
// Globals
Expand Down Expand Up @@ -74,56 +69,6 @@ var KARMA_COV = {
}
};

// ----------------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------------
// Strip comments from JsHint JSON files (naive).
var _jshintCfg = function (name) {
var raw = fs.readFileSync(name).toString();
return JSON.parse(raw.replace(/\/\/.*\n/g, ""));
};

// ----------------------------------------------------------------------------
// JsHint
// ----------------------------------------------------------------------------
gulp.task("jshint:frontend", function () {
gulp
.src([
"test/js/adapters/karma.js",
"*.js",
"!gulpfile.js"
])
.pipe(jshint(_jshintCfg(".jshintrc-frontend.json")))
.pipe(jshint.reporter("default"))
.pipe(jshint.reporter("fail"));
});

gulp.task("jshint:test", function () {
gulp
.src([
"test/js/spec/**/*.js"
])
.pipe(jshint(_.merge(_jshintCfg(".jshintrc-frontend.json"), {
expr: true
})))
.pipe(jshint.reporter("default"))
.pipe(jshint.reporter("fail"));
});

gulp.task("jshint:backend", function () {
gulp
.src([
"*.js",
"tasks/**/*.js",
"test/js/adapters/node.js"
])
.pipe(jshint(_jshintCfg(".jshintrc-backend.json")))
.pipe(jshint.reporter("default"))
.pipe(jshint.reporter("fail"));
});

gulp.task("jshint", ["jshint:frontend", "jshint:test", "jshint:backend"]);

// ----------------------------------------------------------------------------
// Test - Frontend
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -199,21 +144,6 @@ gulp.task("test:frontend:all", testFrontend({
browsers: ["PhantomJS", "Firefox", "Chrome", "Safari"]
}));

// ----------------------------------------------------------------------------
// Test - Backend
// ----------------------------------------------------------------------------
gulp.task("test:backend", function () {
gulp
.src("test/adapters/node.js")
.pipe(mocha({
ui: "bdd",
reporter: "spec"
}))
.on("error", function (err) {
throw err;
});
});

// ----------------------------------------------------------------------------
// Docs
// ----------------------------------------------------------------------------
Expand All @@ -238,61 +168,8 @@ gulp.task("templates", function () {
.pipe(gulp.dest("./"));
});

// ----------------------------------------------------------------------------
// Copy
// ----------------------------------------------------------------------------
gulp.task("copy", function () {
gulp
.src([
"bower_components/mocha/mocha.js",
"bower_components/mocha/mocha.css",
"bower_components/chai/chai.js",
"bower_components/jquery/dist/jquery.js",
"bower_components/requirejs/require.js",
"bower_components/pure/pure-min.css"
])
.pipe(gulp.dest("./test/js/lib"));

gulp
.src([
"bower_components/sinon/index.js"
])
.pipe(rename({
basename: "sinon"
}))
.pipe(gulp.dest("./test/js/lib"));
});

// ----------------------------------------------------------------------------
// Watch
// ----------------------------------------------------------------------------
gulp.task("watch", function () {
gulp.watch([
"_templates/**/*.jade",
"*.md",
"chai-jq.js"
], ["docs:api", "templates"]);
});

// ----------------------------------------------------------------------------
// Clean
// ----------------------------------------------------------------------------
gulp.task("clean", function () {
gulp
.src([
"coverage"
], { read: false })
.pipe(rimraf());
});

// ----------------------------------------------------------------------------
// Aggregated Tasks
// ----------------------------------------------------------------------------
gulp.task("check:dev", ["jshint", "test:backend", "test:frontend:dev"]);
gulp.task("check:ci", ["jshint", "test:backend", "test:frontend:ci"]);
gulp.task("check:all", ["jshint", "test:backend", "test:frontend:all"]);
gulp.task("check", ["check:dev"]);

gulp.task("build", ["copy", "docs:api", "templates"]);

gulp.task("default", ["clean", "check", "build"]);
gulp.task("build", ["docs:api", "templates"]);
gulp.task("default", ["build"]);
21 changes: 21 additions & 0 deletions karma.conf.coverage.js
@@ -0,0 +1,21 @@
"use strict";
/*
* Karma Configuration: "coverage" version.
*
* This configuration is the same as basic one-shot version, just with coverage.
*/
module.exports = function (config) {
/* eslint-disable global-require */
require("./karma.conf")(config);
config.set({
reporters: ["spec", "coverage"],
coverageReporter: {
reporters: [
{ type: "json", file: "coverage.json" },
{ type: "lcov" },
{ type: "text-summary" }
],
dir: "coverage/client"
}
});
};
33 changes: 33 additions & 0 deletions karma.conf.js
@@ -0,0 +1,33 @@
"use strict";
/*
* Karma Configuration: "full" version.
*/
module.exports = function (config) {
/* eslint-disable global-require */
config.set({
frameworks: ["mocha", "phantomjs-shim"],
reporters: ["spec"],
browsers: ["PhantomJS"],
basePath: ".", // repository root.
files: [
// Vendor files
require.resolve("sinon/pkg/sinon"),
require.resolve("jquery/dist/jquery"),
require.resolve("chai/chai"),

// The plugin.
"chai-jq.js",

// Test files.
"test/adapters/karma.js",
"test/js/spec/chai-jq.spec.js"
],
port: 9999,
singleRun: true,
client: {
mocha: {
ui: "bdd"
}
}
});
};
35 changes: 19 additions & 16 deletions package.json
Expand Up @@ -5,22 +5,21 @@
"main": "chai-jq.js",
"dependencies": {},
"devDependencies": {
"bower": "1.2.7",
"chai": "1.8.1",
"chai": "^3.4.1",
"coveralls": "^2.11.4",
"eslint": "^1.7.3",
"eslint-config-defaults": "^7.0.1",
"eslint-plugin-filenames": "^0.1.2",
"eslint-plugin-react": "^3.6.2",
"gulp": "3.5.2",
"gulp-jade": "0.4.2",
"gulp-jshint": "1.4.0",
"gulp-karma": "https://github.com/FormidableLabs/gulp-karma/tarball/9535488a28fdef909e7cc221e2d02a3cdf684c9d",
"gulp-mdox": "0.0.2",
"gulp-mocha": "0.4.1",
"gulp-rename": "1.2.0",
"gulp-rimraf": "0.1.1",
"jquery": "1.8.3",
"http-server": "^0.8.5",
"jquery": "^1.11.3",
"jsdom": "0.8.8",
"karma": "^0.13.9",
"karma-chrome-launcher": "^0.2.0",
"karma-coverage": "^0.5.2",
"karma-coveralls": "^0.1.4",
"karma-firefox-launcher": "^0.1.6",
"karma-ie-launcher": "^0.2.0",
"karma-mocha": "^0.2.0",
Expand All @@ -29,16 +28,20 @@
"karma-safari-launcher": "^0.1.1",
"karma-sauce-launcher": "^0.2.14",
"karma-spec-reporter": "0.0.20",
"lodash": "2.4.1",
"marked": "0.2.10",
"mocha": "1.14.0",
"phantomjs": "^1.9.18"
"mocha": "^2.2.5",
"phantomjs": "^1.9.18",
"sinon": "^1.16.1"
},
"scripts": {
"test": "gulp check",
"check": "npm run-script test && npm run-script coverage",
"coverage": "node_modules/karma-coverage/node_modules/.bin/istanbul check-coverage --statements 100 --branches 100 --lines 100 --functions 100 'coverage/**/coverage.json'",
"sauce-local": "gulp test:frontend:sauce"
"test-frontend": "node node_modules/karma/bin/karma start karma.conf.js",
"test-frontend-ci": "node node_modules/karma/bin/karma start --browsers PhantomJS,Firefox karma.conf.coverage.js",
"test-frontend-cov": "node node_modules/karma/bin/karma start karma.conf.coverage.js",
"test": "npm run test-frontend",
"test-ci": "npm run test-frontend-ci",
"test-cov": "npm run test-frontend-cov",
"test-dev": "npm run test-frontend-dev",
"server-test": "http-server -p 3030 ."
},
"repository": {
"type": "git",
Expand Down
14 changes: 7 additions & 7 deletions test/test-amd.html
Expand Up @@ -5,9 +5,13 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<!-- Test styles and libraries.-->
<link rel="stylesheet" href="js/lib/mocha.css"/>
<script src="js/lib/mocha.js"></script>
<script src="js/lib/sinon.js"></script>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css"/>
</head>
<body>
<div id="mocha"></div>
<div id="fixtures" style="position: absolute; bottom: 0;"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/sinon/pkg/sinon.js"></script>
<!-- Plugin deps and library.-->
<script src="js/lib/require.js"></script>
<!-- Test Setup-->
Expand Down Expand Up @@ -39,9 +43,5 @@
});
</script>
<!-- Tests.-->
</head>
<body>
<div id="mocha"></div>
<div id="fixtures" style="position: absolute; bottom: 0;"></div>
</body>
</html>
20 changes: 10 additions & 10 deletions test/test.html
Expand Up @@ -5,12 +5,16 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<!-- Test styles and libraries.-->
<link rel="stylesheet" href="js/lib/mocha.css"/>
<script src="js/lib/mocha.js"></script>
<script src="js/lib/sinon.js"></script>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css"/>
</head>
<body>
<div id="mocha"></div>
<div id="fixtures" style="position: absolute; bottom: 0;"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/sinon/pkg/sinon.js"></script>
<!-- Plugin deps and library.-->
<script src="js/lib/jquery.js"></script>
<script src="js/lib/chai.js"></script>
<script src="../node_modules/jquery/dist/jquery.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../chai-jq.js"></script>
<!-- Test Setup-->
<script>
Expand All @@ -20,14 +24,10 @@

// Run tests on window load.
window.onload = function () {
(window.mochaPhantomJS || mocha).run();
mocha.run();
};
</script>
<!-- Tests.-->
<script src="js/spec/chai-jq.spec.js"></script>
</head>
<body>
<div id="mocha"></div>
<div id="fixtures" style="position: absolute; bottom: 0;"></div>
</body>
</html>

0 comments on commit 71544c1

Please sign in to comment.