From be47f7bfea13fef7303364a6f40791ee68457955 Mon Sep 17 00:00:00 2001 From: Aaron Abramov Date: Thu, 27 Jul 2017 10:12:49 -0700 Subject: [PATCH] --findRelatedFiles (#4131) --- .../__tests__/find_related_files.test.js | 42 +++++++++++++++++++ packages/jest-config/src/index.js | 1 + packages/jest-config/src/normalize.js | 1 + types/Config.js | 2 + 4 files changed, 46 insertions(+) create mode 100644 integration_tests/__tests__/find_related_files.test.js diff --git a/integration_tests/__tests__/find_related_files.test.js b/integration_tests/__tests__/find_related_files.test.js new file mode 100644 index 000000000000..190bb69c4cf7 --- /dev/null +++ b/integration_tests/__tests__/find_related_files.test.js @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow + */ + +'use strict'; + +import runJest from '../runJest'; +import {cleanup, writeFiles} from '../utils'; +import os from 'os'; +import path from 'path'; + +const skipOnWindows = require('../../scripts/skip_on_windows'); +const DIR = path.resolve(os.tmpdir(), 'force_exit_test'); + +skipOnWindows.suite(); + +beforeEach(() => cleanup(DIR)); +afterEach(() => cleanup(DIR)); + +test('runs tests related to filename', () => { + writeFiles(DIR, { + '.watchmanconfig': '', + '__tests__/test.test.js': ` + const a = require('../a'); + test('a', () => {}); + `, + 'a.js': 'module.exports = {};', + 'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}), + }); + + const {stdout} = runJest(DIR, ['a.js']); + expect(stdout).toMatch(/no tests found/i); + + const {stderr} = runJest(DIR, ['--findRelatedTests', 'a.js']); + expect(stderr).toMatch('PASS __tests__/test.test.js'); +}); diff --git a/packages/jest-config/src/index.js b/packages/jest-config/src/index.js index 406408843011..d8de6a214aff 100644 --- a/packages/jest-config/src/index.js +++ b/packages/jest-config/src/index.js @@ -72,6 +72,7 @@ const getConfigs = ( coverageReporters: options.coverageReporters, coverageThreshold: options.coverageThreshold, expand: options.expand, + findRelatedTests: options.findRelatedTests, forceExit: options.forceExit, json: options.json, lastCommit: options.lastCommit, diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 82315d6fe6dc..a7f8aa68257a 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -455,6 +455,7 @@ function normalize(options: InitialOptions, argv: Argv) { case 'coverageThreshold': case 'expand': case 'globals': + case 'findRelatedTests': case 'forceExit': case 'listTests': case 'logHeapUsage': diff --git a/types/Config.js b/types/Config.js index 136e7aa3e3c1..7184b28a29b7 100644 --- a/types/Config.js +++ b/types/Config.js @@ -77,6 +77,7 @@ export type InitialOptions = {| coverageReporters?: Array, coverageThreshold?: {global: {[key: string]: number}}, expand?: boolean, + findRelatedTests?: boolean, forceExit?: boolean, json: boolean, globals?: ConfigGlobals, @@ -144,6 +145,7 @@ export type GlobalConfig = {| coverageReporters: Array, coverageThreshold: {global: {[key: string]: number}}, expand: boolean, + findRelatedTests: boolean, forceExit: boolean, json: boolean, lastCommit: boolean,