From 6ce0afebaaa222da76d34b17bd0fbac640758d6a Mon Sep 17 00:00:00 2001 From: rickhanlonii Date: Thu, 15 Feb 2018 23:24:37 -0500 Subject: [PATCH] Don't skip configured matchers for exact file names --- .../cli-accepts-exact-filenames.test.js.snap | 29 -------- .../cli-handles-exact-filenames.test.js.snap | 19 +++++ .../cli-accepts-exact-filenames.test.js | 51 ------------- .../cli-handles-exact-filenames.test.js | 72 +++++++++++++++++++ packages/jest-cli/src/search_source.js | 39 ++-------- 5 files changed, 96 insertions(+), 114 deletions(-) delete mode 100644 integration-tests/__tests__/__snapshots__/cli-accepts-exact-filenames.test.js.snap create mode 100644 integration-tests/__tests__/__snapshots__/cli-handles-exact-filenames.test.js.snap delete mode 100644 integration-tests/__tests__/cli-accepts-exact-filenames.test.js create mode 100644 integration-tests/__tests__/cli-handles-exact-filenames.test.js diff --git a/integration-tests/__tests__/__snapshots__/cli-accepts-exact-filenames.test.js.snap b/integration-tests/__tests__/__snapshots__/cli-accepts-exact-filenames.test.js.snap deleted file mode 100644 index 14f0f7d5b8bc..000000000000 --- a/integration-tests/__tests__/__snapshots__/cli-accepts-exact-filenames.test.js.snap +++ /dev/null @@ -1,29 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`CLI accepts exact filenames 1`] = ` -"PASS ./bar.js - ● Console - - console.log bar.js:2 - Hey - -PASS foo/baz.js - ● Console - - console.log foo/baz.js:2 - Hey - - -" -`; - -exports[`CLI accepts exact filenames 2`] = ` -"Test Suites: 2 passed, 2 total -Tests: 2 passed, 2 total -Snapshots: 0 total -Time: <> -Ran all test suites matching /.\\\\/bar.js|.\\\\/foo\\\\/baz.js|.\\\\/foo/i. -" -`; - -exports[`CLI accepts exact filenames 3`] = `""`; diff --git a/integration-tests/__tests__/__snapshots__/cli-handles-exact-filenames.test.js.snap b/integration-tests/__tests__/__snapshots__/cli-handles-exact-filenames.test.js.snap new file mode 100644 index 000000000000..92cd0d16f554 --- /dev/null +++ b/integration-tests/__tests__/__snapshots__/cli-handles-exact-filenames.test.js.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CLI accepts exact file names if matchers matched 1`] = ` +"PASS ./bar.spec.js +PASS foo/bar.spec.js + +" +`; + +exports[`CLI accepts exact file names if matchers matched 2`] = ` +"Test Suites: 2 passed, 2 total +Tests: 2 passed, 2 total +Snapshots: 0 total +Time: <> +Ran all test suites matching /.\\\\/bar.spec.js|.\\\\/foo\\\\/bar.spec.js/i. +" +`; + +exports[`CLI accepts exact file names if matchers matched 3`] = `""`; diff --git a/integration-tests/__tests__/cli-accepts-exact-filenames.test.js b/integration-tests/__tests__/cli-accepts-exact-filenames.test.js deleted file mode 100644 index 083c6cc1b278..000000000000 --- a/integration-tests/__tests__/cli-accepts-exact-filenames.test.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * 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 - */ - -'use strict'; - -const path = require('path'); -const SkipOnWindows = require('../../scripts/SkipOnWindows'); -const {extractSummary, cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); - -const DIR = path.resolve(__dirname, '../cli_accepts_exact_filenames'); - -SkipOnWindows.suite(); - -beforeEach(() => cleanup(DIR)); -afterAll(() => cleanup(DIR)); - -test('CLI accepts exact filenames', () => { - writeFiles(DIR, { - 'bar.js': ` - test('bar', () => console.log('Hey')); - `, - 'foo/baz.js': ` - test('baz', () => console.log('Hey')); - `, - 'package.json': '{}', - }); - - const {stderr, stdout, status} = runJest(DIR, [ - '-i', - '--ci=false', - '--forceExit', - './bar.js', - './foo/baz.js', - './foo', - ]); - - expect(status).toBe(0); - - const {rest, summary} = extractSummary(stderr); - - expect(rest).toMatchSnapshot(); - expect(summary).toMatchSnapshot(); - expect(stdout).toMatchSnapshot(); -}); diff --git a/integration-tests/__tests__/cli-handles-exact-filenames.test.js b/integration-tests/__tests__/cli-handles-exact-filenames.test.js new file mode 100644 index 000000000000..af7aab41e49e --- /dev/null +++ b/integration-tests/__tests__/cli-handles-exact-filenames.test.js @@ -0,0 +1,72 @@ +/** + * 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 + */ + +'use strict'; + +const path = require('path'); +const SkipOnWindows = require('../../scripts/SkipOnWindows'); +const {extractSummary, cleanup, writeFiles} = require('../Utils'); +const runJest = require('../runJest'); + +const DIR = path.resolve(__dirname, '../cli_accepts_exact_filenames'); + +SkipOnWindows.suite(); + +beforeEach(() => cleanup(DIR)); +afterAll(() => cleanup(DIR)); + +test('CLI accepts exact file names if matchers matched', () => { + writeFiles(DIR, { + 'bar.spec.js': ` + test('bar', () => {}); + `, + 'foo/bar.spec.js': ` + test('foo', () => {}); + `, + 'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}), + }); + + const result = runJest(DIR, [ + '-i', + '--forceExit', + './bar.spec.js', + './foo/bar.spec.js', + ]); + + expect(result.status).toBe(0); + + const {rest, summary} = extractSummary(result.stderr); + + expect(rest).toMatchSnapshot(); + expect(summary).toMatchSnapshot(); + expect(result.stdout).toMatchSnapshot(); +}); + +test('CLI skips exact file names if no matchers matched', () => { + writeFiles(DIR, { + 'bar.js': ` + test('bar', () => {); + `, + 'foo/bar.js': ` + test('foo', () => {); + `, + 'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}), + }); + + const result = runJest(DIR, [ + '-i', + '--forceExit', + './bar.js', + './foo/bar.js', + ]); + + expect(result.status).toBe(1); + expect(result.stdout).toMatch(/No tests found([\S\s]*)3 files checked./); + expect(result.stderr).toEqual(''); +}); diff --git a/packages/jest-cli/src/search_source.js b/packages/jest-cli/src/search_source.js index efb39ba054a0..51fff5854b67 100644 --- a/packages/jest-cli/src/search_source.js +++ b/packages/jest-cli/src/search_source.js @@ -206,41 +206,12 @@ export default class SearchSource { return Promise.resolve(this.findTestsByPaths(paths)); } else if (globalConfig.findRelatedTests && paths && paths.length) { return Promise.resolve(this.findRelatedTestsFromPattern(paths)); + } else if (globalConfig.testPathPattern != null) { + return Promise.resolve( + this.findMatchingTests(globalConfig.testPathPattern), + ); } else { - const allFiles = new Set(this._context.hasteFS.getAllFiles()); - const validTestPaths = - paths && - paths.filter(name => { - const fullName = path.resolve(name); - - try { - if (!fs.lstatSync(fullName).isFile()) { - // It exists, but it is not a file. - return false; - } - } catch (e) { - // It does not exist. - return false; - } - - // The file exists, but it is explicitly blacklisted. - if (!this._testPathCases.testPathIgnorePatterns(fullName)) { - return false; - } - - // It exists and it is a file; return true if it's in the project. - return allFiles.has(fullName); - }); - - if (validTestPaths && validTestPaths.length) { - return Promise.resolve({tests: toTests(this._context, validTestPaths)}); - } else if (globalConfig.testPathPattern != null) { - return Promise.resolve( - this.findMatchingTests(globalConfig.testPathPattern), - ); - } else { - return Promise.resolve({tests: []}); - } + return Promise.resolve({tests: []}); } } }