Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
var expected = fs.readFileSync(
__dirname + '/../../expected/reporters/default.txt'
).toString();
// Execute method under test
try {
reporter(errors);
} catch(e) {
hooker.unhook(process.stdout, 'write');
console.log(e);
console.log(e.stack);
}
hooker.unhook(process.stdout, 'write');
expect(actual).to.equal(expected);
done();
});
it('should not output anything if there are no errors', function() {
var actual = '';
hooker.hook(process.stdout, 'write', {
pre: function(out) {
actual += out;
return hooker.preempt();
}
});
// Execute
reporter([]);
hooker.unhook(process.stdout, 'write');
});
});
run(function(error, failureCount) {
// close the file if it was opened
if (fd) {
fs.closeSync(fd);
}
// Restore process.stdout.write to its original value
hooker.unhook(process.stdout, 'write');
// Actually test the actually-logged stdout string to the expected value
done(error, failureCount);
});
};
var stdoutEqual = function(callback, done) {
var actual = '';
// Hook process.stdout.write
hooker.hook(grunt.log, ['error', 'ok'], {
// This gets executed before the original process.stdout.write.
pre: function(result) {
// Concatenate uncolored result onto actual.
actual += grunt.log.uncolor(result);
// Prevent the original process.stdout.write from executing.
return hooker.preempt();
}
});
// Execute the logging code to be tested.
callback();
// Restore process.stdout.write to its original value.
hooker.unhook(grunt.log, ['error', 'ok']);
// Actually test the actually-logged stdout string to the expected value.
done(actual);
};
hooker.hook(process.stdout, 'write', {
pre: function(out) {
actual += stripAnsi(out);
return hooker.preempt();
}
});
var expected = fs.readFileSync(
__dirname + '/../../expected/reporters/json.txt'
).toString();
// Execute method under test
reporter(errors);
hooker.unhook(process.stdout, 'write');
expect(actual).to.equal(expected);
// Test that valid json is output
expect(JSON.stringify.bind(JSON, actual)).not.to.throw.error;
done();
});
process.once('timegruntexit', function (exitCode) {
clearInterval(interval);
process.exit = originalExit;
hooker.unhook(grunt.log, 'header');
var diff = Date.now() - prevTime;
if (prevTaskName) {
tableData.push([prevTaskName, diff]);
}
// `grunt.log.header` should be unhooked above, but in some cases it's not
log('\n\n' + chalk.underline('Execution Time') + chalk.gray(' (' + startTimePretty + ')'));
log(formatTable(tableData) + '\n');
if (cb) {
cb(tableData, function () {
process.exit(exitCode);
});
return memo + (result.error ? 1 : 0);
}, 0);
var numFiles = data.length;
grunt.log.error(numErrors + ' ' + grunt.util.pluralize(numErrors, 'error/errors') + ' in ' +
numFiles + ' ' + grunt.util.pluralize(numFiles, 'file/files'));
}
} else {
if (jshint.usingGruntReporter === true && data.length > 0) {
grunt.log.ok(data.length + ' ' + grunt.util.pluralize(data.length, 'file/files') + ' lint free.');
}
}
// Write the output of the reporter if wanted
if (reporterOutput) {
hooker.unhook(process.stdout, 'write');
reporterOutput = grunt.template.process(reporterOutput);
var destDir = path.dirname(reporterOutput);
if (!grunt.file.exists(destDir)) {
grunt.file.mkdir(destDir);
}
grunt.file.write(reporterOutput, output);
grunt.log.ok('Report "' + reporterOutput + '" created.');
}
done(failed);
});
});
return memo + (result.error ? 1 : 0);
}, 0);
var numFiles = data.length;
grunt.log.error(numErrors + ' ' + grunt.util.pluralize(numErrors, 'error/errors') + ' in ' +
numFiles + ' ' + grunt.util.pluralize(numFiles, 'file/files'));
}
} else {
if (jshint.usingGruntReporter === true && data.length > 0) {
grunt.log.ok(data.length + ' ' + grunt.util.pluralize(data.length, 'file/files') + ' lint free.');
}
}
// Write the output of the reporter if wanted
if (reporterOutput) {
hooker.unhook(process.stdout, 'write');
reporterOutput = grunt.template.process(reporterOutput);
var destDir = path.dirname(reporterOutput);
if (!grunt.file.exists(destDir)) {
grunt.file.mkdir(destDir);
}
grunt.file.write(reporterOutput, output);
grunt.log.ok('Report "' + reporterOutput + '" created.');
}
done(failed);
});
});
DB_PASSWORD: 'generator_test'
};
prompts.forEach(function(prompt) {
if (answers[prompt.name]) {
return;
}
if (prompt.default instanceof Function) {
answers[prompt.name] = prompt.default(answers);
} else {
answers[prompt.name] = prompt.default;
}
});
hooker.unhook(this.app, 'prompt');
done(answers);
return hooker.preempt(answers);
}.bind(this));
};
process.on("exit", function () {
logCurrent();
if (deferLogs) {
logDeferred();
}
logTotal();
hooker.unhook(grunt.log, "header");
});
};