Skip to content

Commit abaea37

Browse files
mbelskySimenB
authored andcommittedJan 17, 2020
Normalize --findRelatedTests paths on win32 platforms (#8961)
1 parent c8c4c4e commit abaea37

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- `[jest-config]` Merge preset globals with project globals ([#9027](https://github.com/facebook/jest/pull/9027))
1414
- `[jest-config]` Support `.cjs` config files ([#9291](https://github.com/facebook/jest/pull/9291))
1515
- `[jest-core]` Support reporters as default exports ([#9161](https://github.com/facebook/jest/pull/9161))
16+
- `[jest-core]` Support `--findRelatedTests` paths case insensitivity on Windows ([#8900](https://github.com/facebook/jest/issues/8900))
1617
- `[jest-diff]` Add options for colors and symbols ([#8841](https://github.com/facebook/jest/pull/8841))
1718
- `[jest-diff]` [**BREAKING**] Export as ECMAScript module ([#8873](https://github.com/facebook/jest/pull/8873))
1819
- `[jest-diff]` Add `includeChangeCounts` and rename `Indicator` options ([#8881](https://github.com/facebook/jest/pull/8881))

‎e2e/__tests__/findRelatedFiles.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ describe('--findRelatedTests flag', () => {
3838
expect(stderr).toMatch(summaryMsg);
3939
});
4040

41+
test('runs tests related to uppercased filename on case-insensitive os', () => {
42+
if (process.platform !== 'win32') {
43+
// This test is Windows specific, skip it on other platforms.
44+
return;
45+
}
46+
47+
writeFiles(DIR, {
48+
'.watchmanconfig': '',
49+
'__tests__/test.test.js': `
50+
const a = require('../a');
51+
test('a', () => {});
52+
`,
53+
'a.js': 'module.exports = {};',
54+
'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}),
55+
});
56+
57+
const {stdout} = runJest(DIR, ['A.JS']);
58+
expect(stdout).toMatch('');
59+
60+
const {stderr} = runJest(DIR, ['--findRelatedTests', 'A.JS']);
61+
expect(stderr).toMatch('PASS __tests__/test.test.js');
62+
63+
const summaryMsg = 'Ran all test suites related to files matching /A.JS/i.';
64+
expect(stderr).toMatch(summaryMsg);
65+
});
66+
4167
test('runs tests related to filename with a custom dependency extractor', () => {
4268
writeFiles(DIR, {
4369
'.watchmanconfig': '',

‎packages/jest-core/src/SearchSource.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import * as os from 'os';
89
import * as path from 'path';
910
import micromatch = require('micromatch');
1011
import {Context} from 'jest-runtime';
@@ -252,8 +253,6 @@ export default class SearchSource {
252253
globalConfig: Config.GlobalConfig,
253254
changedFiles?: ChangedFiles,
254255
): SearchResult {
255-
const paths = globalConfig.nonFlagArgs;
256-
257256
if (globalConfig.onlyChanged) {
258257
if (!changedFiles) {
259258
throw new Error('Changed files must be set when running with -o.');
@@ -263,7 +262,21 @@ export default class SearchSource {
263262
changedFiles,
264263
globalConfig.collectCoverage,
265264
);
266-
} else if (globalConfig.runTestsByPath && paths && paths.length) {
265+
}
266+
267+
let paths = globalConfig.nonFlagArgs;
268+
269+
if (globalConfig.findRelatedTests && 'win32' === os.platform()) {
270+
const allFiles = this._context.hasteFS.getAllFiles();
271+
const options = {nocase: true, windows: false};
272+
273+
paths = paths
274+
.map(p => path.resolve(this._context.config.cwd, p))
275+
.map(p => micromatch(allFiles, p.replace(/\\/g, '\\\\'), options)[0])
276+
.filter(p => p);
277+
}
278+
279+
if (globalConfig.runTestsByPath && paths && paths.length) {
267280
return this.findTestsByPaths(paths);
268281
} else if (globalConfig.findRelatedTests && paths && paths.length) {
269282
return this.findRelatedTestsFromPattern(

0 commit comments

Comments
 (0)
Please sign in to comment.