Skip to content

Commit

Permalink
extract formatting of why-running
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed May 4, 2018
1 parent 8ba227e commit fbf5350
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
44 changes: 44 additions & 0 deletions packages/jest-cli/src/format_why_node_running.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import util from 'util';

export default function formatWhyRunning(whyRunning) {
const whyRunningArray = [];
const fakeLogger = {
error(...args) {
whyRunningArray.push(util.format(...args));
},
};

whyRunning(fakeLogger);

return whyRunningArray
.join('\n')
.split('\n\n')
.filter(entry => {
if (entry.startsWith('There are') || !entry) {
return false;
}

return entry.split('\n').some(l => l.includes('this._execModule('));
})
.map(entry => {
const [title, ...lines] = entry.split('\n');

const entries = lines
.map(line => line.split(/\s+-\s+/))
.map(([file, line]) => ({file, line}));

return {
entries,
title: title.replace('# ', ''),
};
});
}
36 changes: 1 addition & 35 deletions packages/jest-cli/src/run_jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type TestWatcher from './test_watcher';
import micromatch from 'micromatch';
import chalk from 'chalk';
import path from 'path';
import util from 'util';
import {Console, formatTestResults} from 'jest-util';
import exit from 'exit';
import fs from 'graceful-fs';
Expand All @@ -27,6 +26,7 @@ import TestSequencer from './test_sequencer';
import {makeEmptyAggregatedTestResult} from './test_result_helpers';
import FailedTestsCache from './failed_tests_cache';
import JestHooks, {type JestHookEmitter} from './jest_hooks';
import formatWhyRunning from './format_why_node_running';

const setConfig = (contexts, newConfig) =>
contexts.forEach(
Expand Down Expand Up @@ -68,40 +68,6 @@ const getTestPaths = async (
});
};

function formatWhyRunning(whyRunning) {
const whyRunningArray = [];
const fakeLogger = {
error(...args) {
whyRunningArray.push(util.format(...args));
},
};

whyRunning(fakeLogger);

return whyRunningArray
.join('\n')
.split('\n\n')
.filter(entry => {
if (entry.startsWith('There are') || !entry) {
return false;
}

return entry.split('\n').some(l => l.includes('this._execModule('));
})
.map(entry => {
const [title, ...lines] = entry.split('\n');

const entries = lines
.map(line => line.split(/\s+-\s+/))
.map(([file, line]) => ({file, line}));

return {
entries,
title: title.replace('# ', ''),
};
});
}

const processResults = (runResults, options) => {
const {
outputFile,
Expand Down

0 comments on commit fbf5350

Please sign in to comment.