Permalink
Browse files

working on #11

  • Loading branch information...
1 parent f133936 commit 9a60ef68cacde6a93ca6867cbd1fac9d99d5c9af @maenu committed May 26, 2013
Showing with 37 additions and 29 deletions.
  1. +2 −16 Gruntfile.js
  2. +7 −5 src/main/js/template.js
  3. +28 −8 src/test/js/template.js
View
@@ -150,20 +150,6 @@ module.exports = function(grunt) {
});
reporter.writeReport(collector, true);
});
-
- var path = require('path');
-
- var NAME = grunt.file.readJSON('package.json').name;
- var MODULE = path.join('node_modules', NAME);
- var REPORTER_SOURCE = path.normalize('src/main/js/reporter.js');
- var REPORTER_DESTINATION = path.join(MODULE, REPORTER_SOURCE);
-
- grunt.registerTask('mock:template:install', 'Pretend installation', function () {
- grunt.file.copy(REPORTER_SOURCE, REPORTER_DESTINATION);
- });
- grunt.registerTask('mock:template:uninstall', 'Pretend uninstallation', function () {
- grunt.file.delete(MODULE);
- });
var WARN = grunt.warn;
@@ -180,8 +166,8 @@ module.exports = function(grunt) {
grunt.registerTask('doc', 'yuidoc');
grunt.registerTask('test:template', ['nodeunit:template']);
grunt.registerTask('test:reporter', ['nodeunit:reporter']);
- grunt.registerTask('test:integration', ['clean:temp', 'mock:template:install', 'jasmine:integration', 'nodeunit:integration', 'mock:template:uninstall']);
- grunt.registerTask('test:threshold', ['clean:temp', 'mock:template:install', 'mock:warn:install', 'jasmine:threshold', 'nodeunit:threshold', 'mock:warn:uninstall', 'mock:template:uninstall']);
+ grunt.registerTask('test:integration', ['clean:temp', 'jasmine:integration', 'nodeunit:integration']);
+ grunt.registerTask('test:threshold', ['clean:temp', 'mock:warn:install', 'jasmine:threshold', 'nodeunit:threshold', 'mock:warn:uninstall']);
grunt.registerTask('test', ['test:template', 'test:reporter', 'test:integration', 'test:threshold']);
grunt.registerTask('test:coverage', ['clean:bin', 'test', 'report']);
@@ -9,10 +9,10 @@ var path = require('path');
var istanbul = require('istanbul');
var grunt = require('grunt');
-var REPORTER = './node_modules/grunt-template-jasmine-istanbul/src/main/js/'
- + 'reporter.js';
-var DEFAULT_TEMPLATE = './node_modules/grunt-contrib-jasmine/tasks/jasmine/'
- + 'templates/DefaultRunner.tmpl';
+var REPORTER = __dirname + '/reporter.js';
+var TMP_REPORTER = 'grunt-template-jasmine-istanbul/reporter.js';
+var DEFAULT_TEMPLATE = __dirname + '/../../../../grunt-contrib-jasmine/tasks/'
+ + 'jasmine/templates/DefaultRunner.tmpl';
/**
* Instruments the specified sources and moves the instrumented sources to the
@@ -169,7 +169,9 @@ var processMixedInTemplate = function (grunt, task, context) {
*/
exports.process = function (grunt, task, context) {
// prepend coverage reporter
- context.scripts.reporters.unshift(REPORTER);
+ var tmpReporter = path.join(context.temp, TMP_REPORTER);
+ grunt.file.copy(REPORTER, tmpReporter);
+ context.scripts.reporters.unshift(tmpReporter);
// instrument sources
var instrumentedSources = instrument(context.scripts.src, context.temp);
// replace sources
@@ -9,8 +9,7 @@ var istanbul = require('istanbul');
var TEMP = '.grunt/temp';
var SRC = 'src/test/js/Generator.js';
var SPEC = 'src/test/js/GeneratorTest.js';
-var REPORTER = './node_modules/grunt-template-jasmine-istanbul/src/main/js/'
- + 'reporter.js';
+var REPORTER = '../../main/js/reporter.js';
var DEFAULT_TEMPLATE = './node_modules/grunt-contrib-jasmine/tasks/jasmine/'
+ 'templates/DefaultRunner.tmpl';
@@ -32,7 +31,9 @@ function getContext () {
},
options: {
report: 'g',
- coverage: 'h'
+ coverage: 'h',
+ // set template since jasmine is not installed as a peer-dependency
+ template: DEFAULT_TEMPLATE
}
};
}
@@ -210,8 +211,9 @@ exports['template'] = {
test.equal(this.context.scripts.reporters.length, 2,
'should have added 1 reporter');
test.equal(path.normalize(this.context.scripts.reporters[0]),
- path.normalize(REPORTER),
- 'should be the coverage reporter');
+ path.join(TEMP,
+ 'grunt-template-jasmine-istanbul/reporter.js'),
+ 'should be the temporary coverage reporter');
test.done();
},
'shouldInstrumentSource': function (test) {
@@ -350,15 +352,33 @@ exports['template'] = {
},
'defaultTemplate': {
'setUp': function (callback) {
- this.processed = this.template.process(grunt, this.task,
- this.context);
+ delete this.context.options.template;
callback();
},
- 'shouldRender': function (test) {
+ 'shouldReadPeerDependency': function (test) {
+ var redirected = false;
+ // backup mocks
+ var read = grunt.file.read;
+ // install mocks
+ grunt.file.read = function (file) {
+ if (path.resolve(file) == path.resolve(
+ '../grunt-contrib-jasmine/tasks/jasmine/templates/'
+ + 'DefaultRunner.tmpl')) {
+ redirected = true;
+ return read.apply(this, [DEFAULT_TEMPLATE]);
+ }
+ return read.apply(this, arguments);
+ };
+ // process
+ this.processed = this.template.process(grunt, this.task,
+ this.context);
this.expected = grunt.util._.template(
grunt.file.read(DEFAULT_TEMPLATE), this.context);
test.equal(this.processed, this.expected,
'should render default template');
+ test.ok(redirected, 'should have redirected the template');
+ // uninstall mocks
+ grunt.file.read = read;
test.done();
}
},

0 comments on commit 9a60ef6

Please sign in to comment.