Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (options.reporterOutput) {
// Hook into stdout to capture report
var unhook = hook_stdout(function(string) {
output += string;
return '';
});
}
// if reporterOutput has a directory destination make sure to create it.
// See: https://github.com/caolan/nodeunit/issues/262
if (options.reporterOptions.output) {
grunt.file.mkdir(path.normalize(options.reporterOptions.output));
}
// Run test(s).
nodeunit.reporters[options.reporter].run(this.filesSrc, options.reporterOptions, function(err) {
// Write the output of the reporter if wanted
if (options.reporterOutput) {
// no longer hook stdout so we can grunt.log
if (unhook) {
unhook();
}
// save all of the output we saw up to this point
grunt.file.write(options.reporterOutput, output);
grunt.log.ok('Report "' + options.reporterOutput + '" created.');
}
done(err);
});
});
function logFailedAssertions() {
var assertion;
// Print each assertion error + stack.
while (assertion = failedAssertions.shift()) {
betterErrors(assertion);
cleanStack(assertion.error);
grunt.verbose.or.error(assertion.testName);
if (assertion.error.name === 'AssertionError' && assertion.message) {
grunt.log.error('Message: ' + assertion.message.magenta);
}
grunt.log.error(assertion.error.stack).writeln();
}
}
// Define our own Nodeunit reporter.
nodeunit.reporters.grunt = {
info: 'Grunt reporter',
run: function(files, options, callback) {
var opts = {
// No idea.
testspec: undefined,
// Executed when the first test in a file is run. If no tests exist in
// the file, this doesn't execute.
moduleStart: function(name) {
// Keep track of this so that moduleDone output can be suppressed in
// cases where a test file contains no tests.
currentModule = name;
grunt.verbose.subhead('Testing ' + name).or.write('Testing ' + name);
},
// Executed after a file is done being processed. This executes whether
// tests exist in the file or not.
moduleDone: function(name) {
grunt.warn('0/0 assertions ran (' + assertions.duration + 'ms)');
} else {
grunt.verbose.writeln();
grunt.log.ok(assertions.length + ' assertions passed (' +
assertions.duration + 'ms)');
}
// Tell the task manager we're all done.
callback(); // callback(assertions.failures() === 0);
}
};
// Nodeunit needs absolute paths.
var paths = files.map(function(filepath) {
return path.resolve(filepath);
});
nodeunit.runFiles(paths, opts);
}
};