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

Don't skip configured matchers for exact file names #5582

Merged
merged 3 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Fixes

* `[jest-cli]` Don't skip matchers for exact files ([#5582](https://github.com/facebook/jest/pull/5582))
* `[docs]` Update discord links ([#5586](https://github.com/facebook/jest/pull/5586))
* `[jest-runtime]` Align handling of testRegex on Windows between searching for
tests and instrumentation checks
Expand Down

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 foo/bar.spec.js
✓ foo

"
`;

exports[`CLI accepts exact file names if matchers matched 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /.\\\\/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.

56 changes: 56 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,56 @@
/**
* 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, {
'foo/bar.spec.js': `
test('foo', () => {});
`,
'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}),
});

const result = runJest(DIR, ['-i', '--forceExit', './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, {
'foo/bar.js': `
test('foo', () => {);
`,
'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}),
});

const result = runJest(DIR, ['-i', '--forceExit', './foo/bar.js']);

expect(result.status).toBe(1);
expect(result.stdout).toMatch(/No tests found([\S\s]*)2 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: []});
}
}
}