Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/package-manager/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
30 changes: 25 additions & 5 deletions lib/reporter/logger.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
'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) {
log[logType](chalk.yellow('version:'), module.version);
}
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) {
Expand Down
9 changes: 7 additions & 2 deletions lib/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down