Skip to content

Commit

Permalink
Don't skip configured matchers for exact file names
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Feb 16, 2018
1 parent 966aab6 commit 6ce0afe
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 114 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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: <<REPLACED>>
Ran all test suites matching /.\\\\/bar.spec.js|.\\\\/foo\\\\/bar.spec.js/i.
"
`;
exports[`CLI accepts exact file names if matchers matched 3`] = `""`;
51 changes: 0 additions & 51 deletions integration-tests/__tests__/cli-accepts-exact-filenames.test.js

This file was deleted.

72 changes: 72 additions & 0 deletions integration-tests/__tests__/cli-handles-exact-filenames.test.js
Original file line number Diff line number Diff line change
@@ -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('');
});
39 changes: 5 additions & 34 deletions packages/jest-cli/src/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: []});
}
}
}

0 comments on commit 6ce0afe

Please sign in to comment.