Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
extract formatting of why-running
  • Loading branch information
SimenB committed May 6, 2018
commit dc55ef1fb9f67742c9e95c69b3c1af6c60a5a9e8
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