Skip to content

Commit

Permalink
Merge b0e6f4e into f23df06
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Dec 14, 2018
2 parents f23df06 + b0e6f4e commit 02d9321
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/build/bin/run-mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ function run(argv, options) {
!utils.mochaOptsFileProjectExists();

// Add default options
// Keep it backward compatible as dryRun
if (typeof options === 'boolean') options = {dryRun: options};
options = options || {};
if (setMochaOpts) {
const mochaOptsFile = utils.getConfigFile('mocha.opts');
mochaOpts.unshift('--opts', mochaOptsFile);
}

const allowConsoleLogsIx = mochaOpts.indexOf('--allow-console-logs');
if (allowConsoleLogsIx === -1) {
// Disable node.js warnings
options.nodeArgs = ['--no-warnings'];
// Fail any tests that are printing to console.
mochaOpts.unshift(
'--require',
Expand Down
5 changes: 5 additions & 0 deletions packages/build/bin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function resolveCLI(cli) {
* @param {string} cli Path of the cli command
* @param {string[]} args The arguments
* @param {object} options Options to control dryRun and spawn
* - nodeArgs An array of args for `node`
* - dryRun Controls if the cli will be executed or not. If set
* to true, the command itself will be returned without running it
*/
Expand All @@ -125,6 +126,10 @@ function runCLI(cli, args, options) {
if (options.dryRun) {
return util.format('%s %s', process.execPath, args.join(' '));
}
if (options.nodeArgs) {
// For example, [--no-warnings]
args = options.nodeArgs.concat(args);
}
var child = spawn(
process.execPath, // Typically '/usr/local/bin/node'
args,
Expand Down
10 changes: 10 additions & 0 deletions packages/build/src/fail-on-console-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ console.warn = recordForbiddenCall('warn');
console.error = recordForbiddenCall('error');

const problems = [];
const warnings = [];

function recordForbiddenCall(methodName) {
return function recordForbiddenConsoleUsage(...args) {
Expand All @@ -40,7 +41,16 @@ function recordForbiddenCall(methodName) {
};
}

process.on('warning', warning => {
warnings.push(warning);
});

process.on('exit', code => {
if (!warnings.length) {
for (w of warnings) {
originalConsole.warn(w);
}
}
if (!problems.length) return;
const log = originalConsole.log;

Expand Down

0 comments on commit 02d9321

Please sign in to comment.