Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not run global hooks if there are no tests #7745

Merged
merged 3 commits into from Jan 29, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/jest-cli/src/runJest.js
Expand Up @@ -217,7 +217,9 @@ export default (async function runJest({
globalConfig = failedTestsCache.updateConfig(globalConfig);
}

if (!allTests.length) {
const hasTests = allTests.length > 0;

if (!hasTests) {
const noTestsFoundMessage = getNoTestsFoundMessage(
testRunData,
globalConfig,
Expand Down Expand Up @@ -250,7 +252,9 @@ export default (async function runJest({
collectHandles = collectNodeHandles();
}

await runGlobalHook({allTests, globalConfig, moduleName: 'globalSetup'});
if (hasTests) {
await runGlobalHook({allTests, globalConfig, moduleName: 'globalSetup'});
}

const results = await new TestScheduler(
globalConfig,
Expand All @@ -262,11 +266,9 @@ export default (async function runJest({

sequencer.cacheResults(allTests, results);

await runGlobalHook({
allTests,
globalConfig,
moduleName: 'globalTeardown',
});
if (hasTests) {
await runGlobalHook({allTests, globalConfig, moduleName: 'globalTeardown'});
}

return processResults(results, {
collectHandles,
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-cli/src/watch.js
Expand Up @@ -17,6 +17,7 @@ import chalk from 'chalk';
import getChangedFilesPromise from './getChangedFilesPromise';
import exit from 'exit';
import HasteMap from 'jest-haste-map';
import {formatExecError} from 'jest-message-util';
import isValidPath from './lib/is_valid_path';
import {isInteractive, specialChars} from 'jest-util';
import {print as preRunMessagePrint} from './preRunMessage';
Expand Down Expand Up @@ -280,7 +281,10 @@ export default function watch(
// continuous watch mode execution. We need to reprint them to the
// terminal and give just a little bit of extra space so they fit below
// `preRunMessagePrint` message nicely.
console.error('\n\n' + chalk.red(error)),
console.error(
'\n\n' +
formatExecError(error, contexts[0].config, {noStackTrace: false}),
),
);
};

Expand Down