diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index 6e7c69238..3c81f05df 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -52,7 +52,9 @@ function test(packageManager, context, next) { const options = createOptions(wd, context); let nodeBin = 'node'; if (context.options.testPath) { - options.env.PATH = `${context.options.testPath}${envSeparator}${process.env.PATH}`; + options.env.PATH = `${context.options.testPath}${envSeparator}${ + process.env.PATH + }`; nodeBin = which(nodeBinName, { path: options.env.PATH || process.env.PATH }); diff --git a/lib/reporter/logger.js b/lib/reporter/logger.js index 0b0eeb766..833769a23 100644 --- a/lib/reporter/logger.js +++ b/lib/reporter/logger.js @@ -1,9 +1,10 @@ 'use strict'; -const _ = require('lodash'); const chalk = require('chalk'); const util = require('./util'); +const outChunkSize = 10000; + function logModule(log, logType, module) { log[logType](chalk.yellow('module name:'), module.name); if (!module.skipped) { @@ -11,14 +12,33 @@ function logModule(log, logType, module) { } if (module.error) { log[logType]('error:', module.error.message); - log[logType]('error:', module.testOutput); + // If the output is not too big, just print it. + if (module.testOutput.length < outChunkSize) { + log[logType]('error:', module.testOutput); + return; + } + // If the output is too big the log formatter explodes, so we slice. + for (let i = 0; i < module.testOutput.length; ) { + // Slice the output to `outChunkSize` size chunks, + // from `i` to `i + outChunkSize`, and update `i`. + const rawChunk = module.testOutput.substring(i, (i += outChunkSize)); + // Align chunk to the last EOL: + // 1. Search for last EOL. + const lastEOL = rawChunk.lastIndexOf('\n') + 1; + // 2.1. If EOL found, trim the chunk of what comes after `lastEOL`. + const chunk = lastEOL > 0 ? rawChunk.substring(0, lastEOL) : rawChunk; + // 2.2. And push back `i` to `lastEOL`, but relative to original size. + if (lastEOL > 0) { + const eolDistanceFromEndOfChunk = outChunkSize - lastEOL; + i -= eolDistanceFromEndOfChunk; + } + log[logType]('error:', chunk); + } } } function logModules(log, logType, modules) { - _.each(modules, (module) => { - logModule(log, logType, module); - }); + modules.forEach((module) => logModule(log, logType, module)); } function logger(log, modules) { diff --git a/lib/spawn.js b/lib/spawn.js index 08428012e..8381ca508 100644 --- a/lib/spawn.js +++ b/lib/spawn.js @@ -3,8 +3,13 @@ const child = require('child_process'); function spawn(cmd, args, options) { if (process.platform === 'win32') { - args = ['/c', cmd].concat(args); - cmd = 'cmd'; + if (cmd.endsWith('js')) { + args = [cmd].concat(args); + cmd = process.execPath; + } else { + args = ['/c', cmd].concat(args); + cmd = 'cmd'; + } } return child.spawn(cmd, args, options); }