Skip to content

Commit 8a109bf

Browse files
committed
Don't skip configured matchers for exact file names
1 parent 966aab6 commit 8a109bf

6 files changed

Lines changed: 98 additions & 115 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Fixes
44

5+
* `[jest-cli]` Don't skip matchers for exact files ([#5582](https://github.com/facebook/jest/pull/5582))
56
* `[jest-runtime]` Align handling of testRegex on Windows between searching for
67
tests and instrumentation checks
78
([#5560](https://github.com/facebook/jest/pull/5560))
@@ -1601,4 +1602,4 @@ See https://facebook.github.io/jest/blog/2016/12/15/2016-in-jest.html
16011602

16021603
## <=0.4.0
16031604

1604-
* See commit history for changes in previous versions of jest.
1605+
* See commit history for changes in previous versions of jest.

integration-tests/__tests__/__snapshots__/cli-accepts-exact-filenames.test.js.snap

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`CLI accepts exact file names if matchers matched 1`] = `
4+
"PASS ./bar.spec.js
5+
PASS foo/bar.spec.js
6+
7+
"
8+
`;
9+
10+
exports[`CLI accepts exact file names if matchers matched 2`] = `
11+
"Test Suites: 2 passed, 2 total
12+
Tests: 2 passed, 2 total
13+
Snapshots: 0 total
14+
Time: <<REPLACED>>
15+
Ran all test suites matching /.\\\\/bar.spec.js|.\\\\/foo\\\\/bar.spec.js/i.
16+
"
17+
`;
18+
19+
exports[`CLI accepts exact file names if matchers matched 3`] = `""`;

integration-tests/__tests__/cli-accepts-exact-filenames.test.js

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
'use strict';
11+
12+
const path = require('path');
13+
const SkipOnWindows = require('../../scripts/SkipOnWindows');
14+
const {extractSummary, cleanup, writeFiles} = require('../Utils');
15+
const runJest = require('../runJest');
16+
17+
const DIR = path.resolve(__dirname, '../cli_accepts_exact_filenames');
18+
19+
SkipOnWindows.suite();
20+
21+
beforeEach(() => cleanup(DIR));
22+
afterAll(() => cleanup(DIR));
23+
24+
test('CLI accepts exact file names if matchers matched', () => {
25+
writeFiles(DIR, {
26+
'bar.spec.js': `
27+
test('bar', () => {});
28+
`,
29+
'foo/bar.spec.js': `
30+
test('foo', () => {});
31+
`,
32+
'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}),
33+
});
34+
35+
const result = runJest(DIR, [
36+
'-i',
37+
'--forceExit',
38+
'./bar.spec.js',
39+
'./foo/bar.spec.js',
40+
]);
41+
42+
expect(result.status).toBe(0);
43+
44+
const {rest, summary} = extractSummary(result.stderr);
45+
46+
expect(rest).toMatchSnapshot();
47+
expect(summary).toMatchSnapshot();
48+
expect(result.stdout).toMatchSnapshot();
49+
});
50+
51+
test('CLI skips exact file names if no matchers matched', () => {
52+
writeFiles(DIR, {
53+
'bar.js': `
54+
test('bar', () => {);
55+
`,
56+
'foo/bar.js': `
57+
test('foo', () => {);
58+
`,
59+
'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}),
60+
});
61+
62+
const result = runJest(DIR, [
63+
'-i',
64+
'--forceExit',
65+
'./bar.js',
66+
'./foo/bar.js',
67+
]);
68+
69+
expect(result.status).toBe(1);
70+
expect(result.stdout).toMatch(/No tests found([\S\s]*)3 files checked./);
71+
expect(result.stderr).toEqual('');
72+
});

packages/jest-cli/src/search_source.js

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -206,41 +206,12 @@ export default class SearchSource {
206206
return Promise.resolve(this.findTestsByPaths(paths));
207207
} else if (globalConfig.findRelatedTests && paths && paths.length) {
208208
return Promise.resolve(this.findRelatedTestsFromPattern(paths));
209+
} else if (globalConfig.testPathPattern != null) {
210+
return Promise.resolve(
211+
this.findMatchingTests(globalConfig.testPathPattern),
212+
);
209213
} else {
210-
const allFiles = new Set(this._context.hasteFS.getAllFiles());
211-
const validTestPaths =
212-
paths &&
213-
paths.filter(name => {
214-
const fullName = path.resolve(name);
215-
216-
try {
217-
if (!fs.lstatSync(fullName).isFile()) {
218-
// It exists, but it is not a file.
219-
return false;
220-
}
221-
} catch (e) {
222-
// It does not exist.
223-
return false;
224-
}
225-
226-
// The file exists, but it is explicitly blacklisted.
227-
if (!this._testPathCases.testPathIgnorePatterns(fullName)) {
228-
return false;
229-
}
230-
231-
// It exists and it is a file; return true if it's in the project.
232-
return allFiles.has(fullName);
233-
});
234-
235-
if (validTestPaths && validTestPaths.length) {
236-
return Promise.resolve({tests: toTests(this._context, validTestPaths)});
237-
} else if (globalConfig.testPathPattern != null) {
238-
return Promise.resolve(
239-
this.findMatchingTests(globalConfig.testPathPattern),
240-
);
241-
} else {
242-
return Promise.resolve({tests: []});
243-
}
214+
return Promise.resolve({tests: []});
244215
}
245216
}
246217
}

0 commit comments

Comments
 (0)