<commit_before>
/*
 * grunt-qunit-amd
 * https://github.com/cedmax/grunt-qunit-amd
 *
 * Copyright (c) 2013 cedmax
 * Licensed under the MIT license.
 */

'use strict';

var phantom = require('node-phantom');
var fs = require('fs');

module.exports = function(grunt) {

	var callback = require('../libs/runner.js'), util = grunt.util;


	function cover(path){
		return function(file, coverage){
			if (coverage) {
				var reportSlug = file.substr(file.lastIndexOf("/")+1, file.length).replace(".js", "");
				fs.writeFileSync(path + '/'+ reportSlug+'.json', JSON.stringify(coverage, null, 4));
			}
		};
	}

	grunt.registerTask('qunit_amd_child', function () {
		var done = this.async();

		var data = grunt.config.get('qunit_amd_child');

		phantom.create(callback(grunt, data, done, cover(data.coverage.tmp)) , {
			phantomPath:require('phantomjs').path,
			parameters: {
				'local-storage-path': '/dev/null',
				'web-security': false
			}
		});
	});

	grunt.registerMultiTask('qunit_amd', function() {
		grunt.loadTasks(__dirname + '/../node_modules/grunt-istanbul/tasks');

		if (util._.isFunction(this.data)) {
			this.data = this.data.apply(grunt, [].slice.call(arguments, 0));
		}

		var data = this.data;

		function prepareCoverage(coverage){
			if (coverage){
				grunt.config.set('instrument', {
					files: [data.require.baseUrl + "/**//*.js"],
					options : {
						lazy : true,
						basePath : data.coverage.tmp
					}
				});
				grunt.task.run('instrument');
			}
		}

		prepareCoverage(data.coverage);

		data.require.baseUrl = data.coverage.tmp + '/' + data.require.baseUrl;

		grunt.config.set('qunit_amd_child', data);
		grunt.task.run('qunit_amd_child');

		grunt.config.set('makeReport', {
			src: data.coverage.tmp + '/*.json',
			options : {
				type : data.coverage.type || 'html',
				dir : data.coverage.out,
				print : 'detail'
			}
		});

		grunt.task.run('makeReport');
	});

};<commit_msg>a few fixes<commit_after>
/*
 * grunt-qunit-amd
 * https://github.com/cedmax/grunt-qunit-amd
 *
 * Copyright (c) 2013 cedmax
 * Licensed under the MIT license.
 */

'use strict';

var phantom = require('node-phantom');
var fs = require('fs');

module.exports = function(grunt) {

	var callback = require('../libs/runner.js'), util = grunt.util;


	function cover(path){
		return function(file, coverage){
			if (coverage) {
				var reportSlug = file.substr(file.lastIndexOf("/")+1, file.length).replace(".js", "");
				fs.writeFileSync(path + '/'+ reportSlug+'.json', JSON.stringify(coverage, null, 4));
			}
		};
	}

	grunt.registerTask('qunit_amd_child', function () {
		var done = this.async();

		var data = grunt.config.get('qunit_amd_child');

		var coverage = (data.coverage && data.coverage.tmp)? cover(data.coverage.tmp) : function(){};

		phantom.create(callback(grunt, data, done, coverage) , {
			phantomPath:require('phantomjs').path,
			parameters: {
				'local-storage-path': '/dev/null',
				'web-security': false
			}
		});
	});

	grunt.registerMultiTask('qunit_amd', function() {
		grunt.loadTasks(__dirname + '/../node_modules/grunt-istanbul/tasks');

		if (util._.isFunction(this.data)) {
			this.data = this.data.apply(grunt, [].slice.call(arguments, 0));
		}

		var data = this.data;

		function prepareCoverage(coverage){
			if (coverage){
				grunt.config.set('instrument', {
					files: [data.require.baseUrl + "/**//*.js"],
					options : {
						lazy : true,
						basePath : data.coverage.tmp
					}
				});
				grunt.task.run('instrument');
				data.require.baseUrl = data.coverage.tmp + '/' + data.require.baseUrl;
				if (data.coverage.pathsToCover){
					data.coverage.pathsToCover.forEach(function(path){
						data.require.paths[path] = data.coverage.tmp + data.require.paths[path];
					});
				}
			}
		}

		function reportCoverage(coverage){
			if (coverage){
				grunt.config.set('makeReport', {
					src: data.coverage.tmp + '/*.json',
					options : {
						type : data.coverage.type || 'html',
						dir : data.coverage.out,
						print : 'detail'
					}
				});

				grunt.task.run('makeReport');
			}
		}

		prepareCoverage(data.coverage);

		grunt.config.set('qunit_amd_child', data);
		grunt.task.run('qunit_amd_child');

		reportCoverage(data.coverage);
	});

};
{'fraction_non_alphanumeric': 0.1833215213796362, 'fraction_numerical': 0.003307347035199622, 'mean_word_length': 3.3336745138178094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5595504', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1482, 'n_words': 235}