Permalink
Browse files

add failing test for RequireJS coverage on node. see #23

  • Loading branch information...
1 parent 0fa6287 commit ae2b832198c50fd70d892593cd5081cef22b017f @millermedeiros millermedeiros committed Dec 18, 2012
View
@@ -36,7 +36,8 @@
"rimraf": "*",
"nodeunit": "*",
"jshint": "*",
- "yui-lint": "*"
+ "yui-lint": "*",
+ "requirejs": "2.x"
},
"TODO": [
"Need a legend for the HTML report + some explanation on how branch coverage is shown",
@@ -0,0 +1,11 @@
+define(function(){
+
+ function sum(a, b) {
+ return a + b;
+ }
+
+ return {
+ sum : sum
+ };
+
+});
@@ -0,0 +1,7 @@
+define(['./ipsum'], function (ipsum) {
+
+ return function exec(a, b, c){
+ return ipsum.sum(a, b) * c;
+ };
+
+});
@@ -0,0 +1,16 @@
+// RequireJS uses `vm.runInThisContext` see issue #23
+// make sure we add hooks for it as well
+
+var rjs = require('requirejs'),
+ assert = require('assert');
+
+rjs.config({
+ baseUrl : __dirname,
+ nodeRequire : require
+});
+
+rjs(['../amd/lorem'], function(lorem){
+ var result = lorem(1, 2, 3);
+ assert.equal(9, result);
+});
+
@@ -109,5 +109,21 @@ module.exports = {
test.ok(results.grepError(/Unable to resolve file/));
test.done();
});
+ },
+ "should work with RequireJS and AMD modules": function (test) {
+ helper.setOpts({ lazyHook : true });
+ run([ 'test/amd-run.js', '-v' ], function (results) {
+ test.ok(results.succeeded());
+ test.ok(results.grepError(/Module load hook:/));
+ test.ok(existsSync(path.resolve(OUTPUT_DIR, 'lcov.info')));
+ test.ok(existsSync(path.resolve(OUTPUT_DIR, 'lcov-report')));
+ test.ok(existsSync(path.resolve(OUTPUT_DIR, 'coverage.json')));
+ var coverage = JSON.parse(fs.readFileSync(path.resolve(OUTPUT_DIR, 'coverage.json'), 'utf8')),
+ filtered;
+ filtered = Object.keys(coverage).filter(function (k) { return k.match(/amd\/lorem/) || k.match(/amd\/ipsum/); });
+ test.ok(filtered.length === 2);
+ test.ok(filtered.length === Object.keys(coverage).length);
+ test.done();
+ });
}
-};
+};

0 comments on commit ae2b832

Please sign in to comment.