Skip to content

Commit e45571c

Browse files
authored
Use prettier 4/n. (#3128)
* Use prettier 4/n. * Fix Flow. * Fix lint errors. * More prettier/eslint fixes. * Pretty print jsonlint, because why the hell not.
1 parent ba8ae4d commit e45571c

File tree

64 files changed

+3687
-3073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3687
-3073
lines changed

packages/babel-jest/src/index.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,22 @@ const createTransformer = (options: any) => {
6464
configString: string,
6565
{instrument, watch}: TransformOptions,
6666
): string {
67-
return crypto
68-
.createHash('md5')
69-
.update(THIS_FILE)
70-
.update('\0', 'utf8')
71-
.update(fileData)
72-
.update('\0', 'utf8')
73-
.update(configString)
74-
.update('\0', 'utf8')
75-
// Don't use the in-memory cache in watch mode because the .babelrc
76-
// file may be modified.
77-
.update(getBabelRC(filename, {useCache: !watch}))
78-
.update('\0', 'utf8')
79-
.update(instrument ? 'instrument' : '')
80-
.digest('hex');
67+
return (
68+
crypto
69+
.createHash('md5')
70+
.update(THIS_FILE)
71+
.update('\0', 'utf8')
72+
.update(fileData)
73+
.update('\0', 'utf8')
74+
.update(configString)
75+
.update('\0', 'utf8')
76+
// Don't use the in-memory cache in watch mode because the .babelrc
77+
// file may be modified.
78+
.update(getBabelRC(filename, {useCache: !watch}))
79+
.update('\0', 'utf8')
80+
.update(instrument ? 'instrument' : '')
81+
.digest('hex')
82+
);
8183
},
8284
process(
8385
src: string,

packages/eslint-config-fb-strict/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = Object.assign({}, fbjsConfig, {
3939
'computed-property-spacing': [2, 'never'],
4040
'eol-last': [2],
4141
'flowtype/object-type-delimiter': [2, 'comma'],
42+
'indent': [0],
4243
'jest/no-focused-tests': [2],
4344
'jest/no-identical-title': [2],
4445
'jest/valid-expect': [2],

packages/jest-cli/src/SearchSource.js

Lines changed: 67 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,11 @@ export type PatternInfo = {|
6161
const git = changedFiles.git;
6262
const hg = changedFiles.hg;
6363

64-
const determineSCM = path => Promise.all([
65-
git.isGitRepository(path),
66-
hg.isHGRepository(path),
67-
]);
64+
const determineSCM = path =>
65+
Promise.all([git.isGitRepository(path), hg.isHGRepository(path)]);
6866
const pathToRegex = p => replacePathSepForRegex(p);
69-
const pluralize = (
70-
word: string,
71-
count: number,
72-
ending: string,
73-
) => `${count} ${word}${count === 1 ? '' : ending}`;
67+
const pluralize = (word: string, count: number, ending: string) =>
68+
`${count} ${word}${count === 1 ? '' : ending}`;
7469

7570
const globsToMatcher = (globs: ?Array<Glob>) => {
7671
if (globs == null || globs.length === 0) {
@@ -114,22 +109,20 @@ class SearchSource {
114109
skipNodeResolution: false,
115110
};
116111

117-
this._rootPattern =
118-
new RegExp(config.roots.map(
119-
dir => escapePathForRegex(dir),
120-
).join('|'));
112+
this._rootPattern = new RegExp(
113+
config.roots.map(dir => escapePathForRegex(dir)).join('|'),
114+
);
121115

122116
const ignorePattern = config.testPathIgnorePatterns;
123-
this._testIgnorePattern =
124-
ignorePattern.length ? new RegExp(ignorePattern.join('|')) : null;
117+
this._testIgnorePattern = ignorePattern.length
118+
? new RegExp(ignorePattern.join('|'))
119+
: null;
125120

126121
this._testPathCases = {
127122
roots: path => this._rootPattern.test(path),
128123
testMatch: globsToMatcher(config.testMatch),
129-
testPathIgnorePatterns: path => (
130-
!this._testIgnorePattern ||
131-
!this._testIgnorePattern.test(path)
132-
),
124+
testPathIgnorePatterns: path =>
125+
!this._testIgnorePattern || !this._testIgnorePattern.test(path),
133126
testRegex: regexToMatcher(config.testRegex),
134127
};
135128
}
@@ -153,37 +146,35 @@ class SearchSource {
153146
const testCasesKeys = Object.keys(testCases);
154147

155148
data.paths = allPaths.filter(path => {
156-
return testCasesKeys.reduce((flag, key) => {
157-
if (testCases[key](path)) {
158-
data.stats[key] = ++data.stats[key] || 1;
159-
return flag && true;
160-
}
161-
data.stats[key] = data.stats[key] || 0;
162-
return false;
163-
}, true);
149+
return testCasesKeys.reduce(
150+
(flag, key) => {
151+
if (testCases[key](path)) {
152+
data.stats[key] = ++data.stats[key] || 1;
153+
return flag && true;
154+
}
155+
data.stats[key] = data.stats[key] || 0;
156+
return false;
157+
},
158+
true,
159+
);
164160
});
165161

166162
return data;
167163
}
168164

169-
_getAllTestPaths(
170-
testPathPattern: StrOrRegExpPattern,
171-
): SearchResult {
165+
_getAllTestPaths(testPathPattern: StrOrRegExpPattern): SearchResult {
172166
return this._filterTestPathsWithStats(
173167
this._hasteContext.hasteFS.getAllFiles(),
174168
testPathPattern,
175169
);
176170
}
177171

178172
isTestFilePath(path: Path): boolean {
179-
return Object.keys(this._testPathCases).every(key => (
180-
this._testPathCases[key](path)
181-
));
173+
return Object.keys(this._testPathCases).every(key =>
174+
this._testPathCases[key](path));
182175
}
183176

184-
findMatchingTests(
185-
testPathPattern: StrOrRegExpPattern,
186-
): SearchResult {
177+
findMatchingTests(testPathPattern: StrOrRegExpPattern): SearchResult {
187178
return this._getAllTestPaths(testPathPattern);
188179
}
189180

@@ -203,9 +194,7 @@ class SearchSource {
203194
};
204195
}
205196

206-
findRelatedTestsFromPattern(
207-
paths: Array<Path>,
208-
): SearchResult {
197+
findRelatedTestsFromPattern(paths: Array<Path>): SearchResult {
209198
if (Array.isArray(paths) && paths.length) {
210199
const resolvedPaths = paths.map(p => path.resolve(process.cwd(), p));
211200
return this.findRelatedTests(new Set(resolvedPaths));
@@ -214,22 +203,24 @@ class SearchSource {
214203
}
215204

216205
findChangedTests(options: Options): Promise<SearchResult> {
217-
return Promise.all(this._config.roots.map(determineSCM))
218-
.then(repos => {
219-
if (!repos.every(([gitRepo, hgRepo]) => gitRepo || hgRepo)) {
220-
return {
221-
noSCM: true,
222-
paths: [],
223-
};
224-
}
225-
return Promise.all(Array.from(repos).map(([gitRepo, hgRepo]) => {
206+
return Promise.all(this._config.roots.map(determineSCM)).then(repos => {
207+
if (!repos.every(([gitRepo, hgRepo]) => gitRepo || hgRepo)) {
208+
return {
209+
noSCM: true,
210+
paths: [],
211+
};
212+
}
213+
return Promise.all(
214+
Array.from(repos).map(([gitRepo, hgRepo]) => {
226215
return gitRepo
227216
? git.findChangedFiles(gitRepo, options)
228217
: hg.findChangedFiles(hgRepo, options);
229-
})).then(changedPathSets => this.findRelatedTests(
218+
}),
219+
).then(changedPathSets =>
220+
this.findRelatedTests(
230221
new Set(Array.prototype.concat.apply([], changedPathSets)),
231222
));
232-
});
223+
});
233224
}
234225

235226
getNoTestsFoundMessage(
@@ -238,40 +229,40 @@ class SearchSource {
238229
data: SearchResult,
239230
): string {
240231
if (patternInfo.onlyChanged) {
241-
return (
242-
chalk.bold(
243-
'No tests found related to files changed since last commit.\n',
244-
) +
232+
return chalk.bold(
233+
'No tests found related to files changed since last commit.\n',
234+
) +
245235
chalk.dim(
246-
patternInfo.watch ?
247-
'Press `a` to run all tests, or run Jest with `--watchAll`.' :
248-
'Run Jest without `-o` to run all tests.',
249-
)
250-
);
236+
patternInfo.watch
237+
? 'Press `a` to run all tests, or run Jest with `--watchAll`.'
238+
: 'Run Jest without `-o` to run all tests.',
239+
);
251240
}
252241

253242
const testPathPattern = SearchSource.getTestPathPattern(patternInfo);
254243
const stats = data.stats || {};
255-
const statsMessage = Object.keys(stats).map(key => {
256-
const value = key === 'testPathPattern' ? testPathPattern : config[key];
257-
if (value) {
258-
const matches = pluralize('match', stats[key], 'es');
259-
return ` ${key}: ${chalk.yellow(value)} - ${matches}`;
260-
}
261-
return null;
262-
}).filter(line => line).join('\n');
244+
const statsMessage = Object.keys(stats)
245+
.map(key => {
246+
const value = key === 'testPathPattern' ? testPathPattern : config[key];
247+
if (value) {
248+
const matches = pluralize('match', stats[key], 'es');
249+
return ` ${key}: ${chalk.yellow(value)} - ${matches}`;
250+
}
251+
return null;
252+
})
253+
.filter(line => line)
254+
.join('\n');
263255

264-
return (
265-
chalk.bold('No tests found') + '\n' +
256+
return chalk.bold('No tests found') +
257+
'\n' +
266258
(data.total
267259
? ` ${pluralize('file', data.total || 0, 's')} checked.\n` +
268-
statsMessage
260+
statsMessage
269261
: `No files found in ${config.rootDir}.\n` +
270-
`Make sure Jest's configuration does not exclude this directory.\n` +
271-
`To set up Jest, make sure a package.json file exists.\n` +
272-
`Jest Documentation: facebook.github.io/jest/docs/configuration.html`
273-
)
274-
);
262+
`Make sure Jest's configuration does not exclude this directory.` +
263+
`\nTo set up Jest, make sure a package.json file exists.\n` +
264+
`Jest Documentation: ` +
265+
`facebook.github.io/jest/docs/configuration.html`);
275266
}
276267

277268
getTestPaths(patternInfo: PatternInfo): Promise<SearchResult> {
@@ -297,9 +288,8 @@ class SearchSource {
297288
const formattedInput = patternInfo.shouldTreatInputAsPattern
298289
? `/${input || ''}/`
299290
: `"${input || ''}"`;
300-
return (input === pattern) ? formattedInput : formattedPattern;
291+
return input === pattern ? formattedInput : formattedPattern;
301292
}
302-
303293
}
304294

305295
module.exports = SearchSource;

packages/jest-cli/src/TestNamePatternPrompt.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ module.exports = (
115115

116116
const matchedTests = [];
117117

118-
this._cachedTestResults.forEach(({testResults}) => testResults.forEach(({
119-
title,
120-
}) => {
121-
if (regex.test(title)) {
122-
matchedTests.push(title);
123-
}
124-
}));
118+
this._cachedTestResults.forEach(({testResults}) =>
119+
testResults.forEach(({
120+
title,
121+
}) => {
122+
if (regex.test(title)) {
123+
matchedTests.push(title);
124+
}
125+
}));
125126

126127
return matchedTests;
127128
}

packages/jest-cli/src/TestRunner.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ class TestRunner {
218218
);
219219
aggregatedResults.snapshot.filesRemoved += status.filesRemoved;
220220
aggregatedResults.snapshot.didUpdate = config.updateSnapshot;
221-
aggregatedResults.snapshot.failure =
222-
!!(!aggregatedResults.snapshot.didUpdate &&
221+
aggregatedResults.snapshot.failure = !!(!config.updateSnapshot &&
223222
(aggregatedResults.snapshot.unchecked ||
224223
aggregatedResults.snapshot.unmatched ||
225224
aggregatedResults.snapshot.filesRemoved));
@@ -269,17 +268,19 @@ class TestRunner {
269268
) {
270269
const mutex = throat(1);
271270
return testPaths.reduce(
272-
(promise, path) => mutex(() => promise
273-
.then(() => {
274-
if (watcher.isInterrupted()) {
275-
throw new CancelRun();
276-
}
277-
278-
this._dispatcher.onTestStart(this._config, path);
279-
return runTest(path, this._config, this._hasteContext.resolver);
280-
})
281-
.then(result => onResult(path, result))
282-
.catch(err => onFailure(path, err))),
271+
(promise, path) =>
272+
mutex(() =>
273+
promise
274+
.then(() => {
275+
if (watcher.isInterrupted()) {
276+
throw new CancelRun();
277+
}
278+
279+
this._dispatcher.onTestStart(this._config, path);
280+
return runTest(path, this._config, this._hasteContext.resolver);
281+
})
282+
.then(result => onResult(path, result))
283+
.catch(err => onFailure(path, err))),
283284
Promise.resolve(),
284285
);
285286
}
@@ -305,19 +306,20 @@ class TestRunner {
305306

306307
// Send test suites to workers continuously instead of all at once to track
307308
// the start time of individual tests.
308-
const runTestInWorker = ({config, path}) => mutex(() => {
309-
if (watcher.isInterrupted()) {
310-
return Promise.reject();
311-
}
312-
this._dispatcher.onTestStart(config, path);
313-
return worker({
314-
config,
315-
path,
316-
rawModuleMap: watcher.isWatchMode()
317-
? this._hasteContext.moduleMap.getRawModuleMap()
318-
: null,
309+
const runTestInWorker = ({config, path}) =>
310+
mutex(() => {
311+
if (watcher.isInterrupted()) {
312+
return Promise.reject();
313+
}
314+
this._dispatcher.onTestStart(config, path);
315+
return worker({
316+
config,
317+
path,
318+
rawModuleMap: watcher.isWatchMode()
319+
? this._hasteContext.moduleMap.getRawModuleMap()
320+
: null,
321+
});
319322
});
320-
});
321323

322324
const onError = (err, path) => {
323325
onFailure(path, err);

0 commit comments

Comments
 (0)