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

Commit

Permalink
Add coverage helpers and refine jshint.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-roemer committed Oct 19, 2014
1 parent eeef24e commit 3b0d9be
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .jshintrc-backend.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
// Turn on (relax):
"boss" : true, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"globalstrict" : true, // Allow global "use strict" (also enables 'strict').
"expr" : true, // Tolerate `ExpressionStatement` as Programs.

// Turn off (enforce):
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"multistr" : false, // Tolerate multi-line strings.
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
Expand Down
2 changes: 1 addition & 1 deletion .jshintrc-frontend.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
// Turn on (relax):
"boss" : true, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"globalstrict" : true, // Allow global "use strict" (also enables 'strict').
"expr" : true, // Tolerate `ExpressionStatement` as Programs.

// Turn off (enforce):
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"multistr" : false, // Tolerate multi-line strings.
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ See: [http://api.jquery.com/attr/](http://api.jquery.com/attr/)
* **message** (`String`) failure message (_optional_)
* **_returns_** current object or attribute string value

Asserts that the target has exactly the given named
data-attribute, or asserts the target contains a subset
Asserts that the target has exactly the given named
data-attribute, or asserts the target contains a subset
of the data-attribute when using the
`include` or `contain` modifiers.

Expand All @@ -223,7 +223,7 @@ expect($("<div data-id=\"hi\" data-foo=\"bar time\" />"))
.to.contain.$data("foo", "bar");
```

Changes context to data-attribute string *value* when no
Changes context to data-attribute string *value* when no
expected value is provided:

```js
Expand Down
9 changes: 5 additions & 4 deletions chai-jq.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
*/
var _containMethod = function (jqMeth, opts) {
// Unpack options.
opts || (opts = {});
opts = opts || {};
opts.hasArg = !!opts.hasArg;
opts.isProperty = !!opts.isProperty;
opts.hasContains = !!opts.hasContains;
Expand Down Expand Up @@ -327,8 +327,8 @@
chai.Assertion.addMethod("$attr", $attr);

/**
* Asserts that the target has exactly the given named
* data-attribute, or asserts the target contains a subset
* Asserts that the target has exactly the given named
* data-attribute, or asserts the target contains a subset
* of the data-attribute when using the
* `include` or `contain` modifiers.
*
Expand All @@ -338,7 +338,7 @@
* .to.contain.$data("foo", "bar");
* ```
*
* Changes context to data-attribute string *value* when no
* Changes context to data-attribute string *value* when no
* expected value is provided:
*
* ```js
Expand Down Expand Up @@ -486,6 +486,7 @@
chai.Assertion.addMethod("$css", $css);
}

/* istanbul ignore next */
/*!
* Wrap AMD, etc. using boilerplate.
*/
Expand Down
87 changes: 63 additions & 24 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var fs = require("fs"),
mocha = require("gulp-mocha"),
jade = require("gulp-jade"),
rename = require("gulp-rename"),
mdox = require("gulp-mdox");
mdox = require("gulp-mdox"),
rimraf = require("gulp-rimraf");

// ----------------------------------------------------------------------------
// Globals
Expand Down Expand Up @@ -58,6 +59,21 @@ var SAUCE_ENVS = {
var SAUCE_BRANCH = process.env.TRAVIS_BRANCH || "local";
var SAUCE_TAG = process.env.SAUCE_USERNAME + "@" + SAUCE_BRANCH;

// Karma coverage.
var KARMA_COV = {
reporters: ["mocha", "coverage"],
preprocessors: {
"chai-jq.js": ["coverage"]
},
coverageReporter: {
reporters: [
{ type: "json", file: "coverage.json" },
{ type: "lcov" }
],
dir: "coverage/"
}
};

// ----------------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------------
Expand All @@ -73,7 +89,6 @@ var _jshintCfg = function (name) {
gulp.task("jshint:frontend", function () {
gulp
.src([
"test/js/spec/**/*.js",
"test/js/adapters/karma.js",
"*.js",
"!gulpfile.js"
Expand All @@ -83,6 +98,18 @@ gulp.task("jshint:frontend", function () {
.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([
Expand All @@ -95,7 +122,7 @@ gulp.task("jshint:backend", function () {
.pipe(jshint.reporter("fail"));
});

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

// ----------------------------------------------------------------------------
// Test - Frontend
Expand All @@ -104,7 +131,7 @@ gulp.task("jshint", ["jshint:frontend", "jshint:backend"]);
process.env.PHANTOMJS_BIN = "./node_modules/.bin/phantomjs";

// Test wrapper.
var testFrontend = function (opts) {
var testFrontend = function () {
var files = [
// Libraries
"test/js/lib/sinon.js",
Expand All @@ -119,19 +146,21 @@ var testFrontend = function (opts) {
"test/js/spec/chai-jq.spec.js"
];

var opts = _.extend.apply(_, [{
frameworks: ["mocha"],
port: 9999,
reporters: ["mocha"],
client: {
mocha: {
ui: "bdd"
}
}
}].concat(_.toArray(arguments)));

return function () {
return gulp
.src(files)
.pipe(karma(_.extend({
frameworks: ["mocha"],
port: 9999,
reporters: ["mocha"],
client: {
mocha: {
ui: "bdd"
}
}
}, opts)))
.pipe(karma(opts))
.on("error", function (err) {
throw err;
});
Expand All @@ -143,17 +172,16 @@ gulp.task("test:frontend:dev", testFrontend({
browsers: ["PhantomJS"]
}));

gulp.task("test:frontend:dev-cov", testFrontend({
singleRun: true,
browsers: ["PhantomJS"]
}, KARMA_COV));

gulp.task("test:frontend:ci", testFrontend({
singleRun: true,
browsers: ["PhantomJS", "Firefox"],
reporters: ["mocha", "coverage", "coveralls"],
preprocessors: {
"chai-jq.js": ["coverage"]
},
coverageReporter: {
type: "lcov",
dir: "coverage/"
}
browsers: ["PhantomJS", "Firefox"]
}, KARMA_COV, {
reporters: ["mocha", "coverage", "coveralls"]
}));

gulp.task("test:frontend:sauce", testFrontend({
Expand Down Expand Up @@ -251,6 +279,17 @@ gulp.task("watch", function () {
], ["docs:api", "templates"]);
});

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

// ----------------------------------------------------------------------------
// Aggregated Tasks
// ----------------------------------------------------------------------------
Expand All @@ -261,4 +300,4 @@ gulp.task("check", ["check:dev"]);

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

gulp.task("default", ["check", "build"]);
gulp.task("default", ["clean", "check", "build"]);
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ <h3 id="-data-name-expected-message-"><code>$data(name, [expected], [message])</
<li><strong>message</strong> (<code>String</code>) failure message (<em>optional</em>)</li>
<li><strong><em>returns</em></strong> current object or attribute string value</li>
</ul>
<p>Asserts that the target has exactly the given named
data-attribute, or asserts the target contains a subset
<p>Asserts that the target has exactly the given named
data-attribute, or asserts the target contains a subset
of the data-attribute when using the
<code>include</code> or <code>contain</code> modifiers.</p>
<pre><code class="lang-js">expect($(&quot;&lt;div data-id=\&quot;hi\&quot; data-foo=\&quot;bar time\&quot; /&gt;&quot;))
.to.have.$data(&quot;id&quot;, &quot;hi&quot;).and
.to.contain.$data(&quot;foo&quot;, &quot;bar&quot;);</code></pre>
<p>Changes context to data-attribute string <em>value</em> when no
<p>Changes context to data-attribute string <em>value</em> when no
expected value is provided:</p>
<pre><code class="lang-js">expect($(&quot;&lt;div data-id=\&quot;hi\&quot; data-foo=\&quot;bar time\&quot; /&gt;&quot;))
.to.have.$data(&quot;foo&quot;).and
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"gulp-mdox": "0.0.2",
"gulp-mocha": "0.4.1",
"gulp-rename": "1.2.0",
"gulp-rimraf": "0.1.1",
"jquery": "1.8.3",
"jsdom": "0.8.8",
"karma": "0.11.14",
Expand Down

0 comments on commit 3b0d9be

Please sign in to comment.