Skip to content

Commit

Permalink
Upgrade to prettier 1.1.0. (#3314)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer authored Apr 18, 2017
1 parent e94ea05 commit 5f72d73
Show file tree
Hide file tree
Showing 91 changed files with 1,114 additions and 1,054 deletions.
6 changes: 4 additions & 2 deletions integration_tests/__tests__/snapshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ describe('Snapshot', () => {
expect(extractSummary(stderr).summary).toMatchSnapshot();

// Write the second snapshot
const testData = `test('escape strings two', () => expect('two: \\\'\"').` +
const testData =
`test('escape strings two', () => expect('two: \\\'\"').` +
`toMatchSnapshot());`;
const newTestData = initialTestData + testData;
fs.writeFileSync(snapshotEscapeTestFile, newTestData, 'utf8');
Expand Down Expand Up @@ -280,7 +281,8 @@ describe('Snapshot', () => {
expect(Object.keys(beforeRemovingSnapshot).length - 1).toBe(
Object.keys(afterRemovingSnapshot).length,
);
const keyToCheck = 'snapshot works with plain objects and the ' +
const keyToCheck =
'snapshot works with plain objects and the ' +
'title has `escape` characters 2';
expect(beforeRemovingSnapshot[keyToCheck]).not.toBe(undefined);
expect(afterRemovingSnapshot[keyToCheck]).toBe(undefined);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"lerna": "2.0.0-beta.38",
"micromatch": "^2.3.11",
"mkdirp": "^0.5.1",
"prettier": "0.22.0",
"prettier": "1.2.0",
"progress": "^1.1.8",
"react": "^15.4.1",
"react-test-renderer": "^15.4.1",
Expand Down
10 changes: 6 additions & 4 deletions packages/babel-plugin-jest-hoist/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ FUNCTIONS.mock = args => {
FUNCTIONS.unmock = args => args.length === 1 && args[0].isStringLiteral();
FUNCTIONS.deepUnmock = args => args.length === 1 && args[0].isStringLiteral();

FUNCTIONS.disableAutomock = (FUNCTIONS.enableAutomock = args =>
args.length === 0);
FUNCTIONS.disableAutomock = FUNCTIONS.enableAutomock = args =>
args.length === 0;

module.exports = babel => {
const isJest = callee =>
Expand All @@ -148,11 +148,13 @@ module.exports = babel => {
const callee = expr.get('callee');
const object = callee.get('object');
const property = callee.get('property');
return property.isIdentifier() &&
return (
property.isIdentifier() &&
FUNCTIONS[property.node.name] &&
(object.isIdentifier(JEST_GLOBAL) ||
(callee.isMemberExpression() && shouldHoistExpression(object))) &&
FUNCTIONS[property.node.name](expr.get('arguments'));
FUNCTIONS[property.node.name](expr.get('arguments'))
);
};
return {
visitor: {
Expand Down
30 changes: 13 additions & 17 deletions packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ const DependencyResolver = require('jest-resolve-dependencies');

const changedFiles = require('jest-changed-files');
const path = require('path');
const {
escapePathForRegex,
replacePathSepForRegex,
} = require('jest-regex-util');
const {escapePathForRegex, replacePathSepForRegex} = require('jest-regex-util');

type SearchResult = {|
noSCM?: boolean,
Expand Down Expand Up @@ -137,17 +134,14 @@ class SearchSource {

const testCasesKeys = Object.keys(testCases);
data.tests = allPaths.filter(test => {
return testCasesKeys.reduce(
(flag, key) => {
if (testCases[key](test.path)) {
data.stats[key] = ++data.stats[key] || 1;
return flag && true;
}
data.stats[key] = data.stats[key] || 0;
return false;
},
true,
);
return testCasesKeys.reduce((flag, key) => {
if (testCases[key](test.path)) {
data.stats[key] = ++data.stats[key] || 1;
return flag && true;
}
data.stats[key] = data.stats[key] || 0;
return false;
}, true);
});

return data;
Expand All @@ -162,7 +156,8 @@ class SearchSource {

isTestFilePath(path: Path): boolean {
return Object.keys(this._testPathCases).every(key =>
this._testPathCases[key](path));
this._testPathCases[key](path),
);
}

findMatchingTests(testPathPattern: StrOrRegExpPattern): SearchResult {
Expand Down Expand Up @@ -215,7 +210,8 @@ class SearchSource {
).then(changedPathSets =>
this.findRelatedTests(
new Set(Array.prototype.concat.apply([], changedPathSets)),
));
),
);
});
}

Expand Down
9 changes: 4 additions & 5 deletions packages/jest-cli/src/TestNamePatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const stringLength = require('string-length');
const Prompt = require('./lib/Prompt');
const formatTestNameByPattern = require('./lib/formatTestNameByPattern');

const pluralizeTest = (total: number) => total === 1 ? 'test' : 'tests';
const pluralizeTest = (total: number) => (total === 1 ? 'test' : 'tests');

const usage = () =>
`\n ${chalk.bold('Pattern Mode Usage')}\n` +
Expand Down Expand Up @@ -117,13 +117,12 @@ module.exports = class TestNamePatternPrompt {
const matchedTests = [];

this._cachedTestResults.forEach(({testResults}) =>
testResults.forEach(({
title,
}) => {
testResults.forEach(({title}) => {
if (regex.test(title)) {
matchedTests.push(title);
}
}));
}),
);

return matchedTests;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-cli/src/TestPathPatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type SearchSources = Array<{|
searchSource: SearchSource,
|}>;

const pluralizeFile = (total: number) => total === 1 ? 'file' : 'files';
const pluralizeFile = (total: number) => (total === 1 ? 'file' : 'files');

const usage = () =>
`\n ${chalk.bold('Pattern Mode Usage')}\n` +
Expand Down Expand Up @@ -109,7 +109,8 @@ module.exports = class TestPathPatternPrompt {
return highlight(path, filePath, pattern, context.config.rootDir);
})
.forEach(filePath =>
this._pipe.write(`\n ${chalk.dim('\u203A')} ${filePath}`));
this._pipe.write(`\n ${chalk.dim('\u203A')} ${filePath}`),
);

if (total > max) {
const more = total - max;
Expand Down
35 changes: 20 additions & 15 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class TestRunner {
// Run in band if we only have one test or one worker available.
// If we are confident from previous runs that the tests will finish quickly
// we also run in band to reduce the overhead of spawning workers.
const runInBand = this._options.maxWorkers <= 1 ||
const runInBand =
this._options.maxWorkers <= 1 ||
tests.length <= 1 ||
(tests.length <= 20 &&
timings.length > 0 &&
Expand Down Expand Up @@ -200,7 +201,8 @@ class TestRunner {
);
})
.then(result => onResult(test, result))
.catch(err => onFailure(test, err))),
.catch(err => onFailure(test, err)),
),
Promise.resolve(),
);
}
Expand Down Expand Up @@ -263,7 +265,8 @@ class TestRunner {
tests.map(test =>
runTestInWorker(test)
.then(testResult => onResult(test, testResult))
.catch(error => onError(error, test))),
.catch(error => onError(error, test)),
),
);

const cleanup = () => workerFarm.end(farm);
Expand Down Expand Up @@ -350,7 +353,8 @@ const addResult = (
testResult: TestResult,
): void => {
aggregatedResults.testResults.push(testResult);
aggregatedResults.numTotalTests += testResult.numPassingTests +
aggregatedResults.numTotalTests +=
testResult.numPassingTests +
testResult.numFailingTests +
testResult.numPendingTests;
aggregatedResults.numFailedTests += testResult.numFailingTests;
Expand Down Expand Up @@ -388,7 +392,8 @@ const addResult = (
aggregatedResults.snapshot.unchecked += testResult.snapshot.unchecked;
aggregatedResults.snapshot.unmatched += testResult.snapshot.unmatched;
aggregatedResults.snapshot.updated += testResult.snapshot.updated;
aggregatedResults.snapshot.total += testResult.snapshot.added +
aggregatedResults.snapshot.total +=
testResult.snapshot.added +
testResult.snapshot.matched +
testResult.snapshot.unmatched +
testResult.snapshot.updated;
Expand Down Expand Up @@ -444,7 +449,8 @@ class ReporterDispatcher {

onTestResult(test, testResult, results) {
this._reporters.forEach(reporter =>
reporter.onTestResult(test, testResult, results));
reporter.onTestResult(test, testResult, results),
);
}

onTestStart(test) {
Expand All @@ -453,23 +459,22 @@ class ReporterDispatcher {

onRunStart(config, results, options) {
this._reporters.forEach(reporter =>
reporter.onRunStart(config, results, options));
reporter.onRunStart(config, results, options),
);
}

onRunComplete(contexts, config, results) {
this._reporters.forEach(reporter =>
reporter.onRunComplete(contexts, config, results));
reporter.onRunComplete(contexts, config, results),
);
}

// Return a list of last errors for every reporter
getErrors(): Array<Error> {
return this._reporters.reduce(
(list, reporter) => {
const error = reporter.getLastError();
return error ? list.concat(error) : list;
},
[],
);
return this._reporters.reduce((list, reporter) => {
const error = reporter.getLastError();
return error ? list.concat(error) : list;
}, []);
}

hasErrors(): boolean {
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-cli/src/TestSequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class TestSequencer {
});

this._cache.forEach((cache, context) =>
fs.writeFileSync(this._getCachePath(context), JSON.stringify(cache)));
fs.writeFileSync(this._getCachePath(context), JSON.stringify(cache)),
);
}
}

Expand Down
27 changes: 18 additions & 9 deletions packages/jest-cli/src/__tests__/SearchSource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ describe('SearchSource', () => {
});
return findMatchingTests(config).then(data => {
const relPaths = toPaths(data.tests).map(absPath =>
path.relative(rootDir, absPath));
path.relative(rootDir, absPath),
);
expect(relPaths.sort()).toEqual([
path.normalize('__testtests__/test.js'),
path.normalize('__testtests__/test.jsx'),
Expand All @@ -169,7 +170,8 @@ describe('SearchSource', () => {
});
return findMatchingTests(config).then(data => {
const relPaths = toPaths(data.tests).map(absPath =>
path.relative(rootDir, absPath));
path.relative(rootDir, absPath),
);
expect(relPaths.sort()).toEqual([
path.normalize('__testtests__/test.js'),
path.normalize('__testtests__/test.jsx'),
Expand All @@ -186,7 +188,8 @@ describe('SearchSource', () => {
});
return findMatchingTests(config).then(data => {
const relPaths = toPaths(data.tests).map(absPath =>
path.relative(rootDir, absPath));
path.relative(rootDir, absPath),
);
expect(relPaths.sort()).toEqual([
path.normalize('__testtests__/test.js'),
path.normalize('__testtests__/test.jsx'),
Expand All @@ -203,7 +206,8 @@ describe('SearchSource', () => {
});
return findMatchingTests(config).then(data => {
const relPaths = toPaths(data.tests).map(absPath =>
path.relative(rootDir, absPath));
path.relative(rootDir, absPath),
);
expect(relPaths.sort()).toEqual([
path.normalize('__testtests__/test.js'),
path.normalize('__testtests__/test.jsx'),
Expand All @@ -220,7 +224,8 @@ describe('SearchSource', () => {
});
return findMatchingTests(config).then(data => {
const relPaths = toPaths(data.tests).map(absPath =>
path.relative(rootDir, absPath));
path.relative(rootDir, absPath),
);
expect(relPaths).toEqual([path.normalize('__testtests__/test.jsx')]);
});
});
Expand All @@ -234,7 +239,8 @@ describe('SearchSource', () => {
});
return findMatchingTests(config).then(data => {
const relPaths = toPaths(data.tests).map(absPath =>
path.relative(rootDir, absPath));
path.relative(rootDir, absPath),
);
expect(relPaths).toEqual([path.normalize('__testtests__/test.foobar')]);
});
});
Expand All @@ -248,7 +254,8 @@ describe('SearchSource', () => {
});
return findMatchingTests(config).then(data => {
const relPaths = toPaths(data.tests).map(absPath =>
path.relative(rootDir, absPath));
path.relative(rootDir, absPath),
);
expect(relPaths.sort()).toEqual([
path.normalize('__testtests__/test.js'),
path.normalize('__testtests__/test.jsx'),
Expand All @@ -265,7 +272,8 @@ describe('SearchSource', () => {
});
return findMatchingTests(config).then(data => {
const relPaths = toPaths(data.tests).map(absPath =>
path.relative(rootDir, absPath));
path.relative(rootDir, absPath),
);
expect(relPaths.sort()).toEqual([
path.normalize('__testtests__/test.js'),
path.normalize('__testtests__/test.jsx'),
Expand All @@ -282,7 +290,8 @@ describe('SearchSource', () => {
});
return findMatchingTests(config).then(data => {
const relPaths = toPaths(data.tests).map(absPath =>
path.relative(rootDir, absPath));
path.relative(rootDir, absPath),
);
expect(relPaths.sort()).toEqual([
path.normalize('__testtests__/test.js'),
path.normalize('__testtests__/test.jsx'),
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-cli/src/__tests__/TestRunner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jest.mock('worker-farm', () => {
const mock = jest.fn(
(options, worker) =>
workerFarmMock = jest.fn((data, callback) =>
require(worker)(data, callback)),
require(worker)(data, callback),
),
);
mock.end = jest.fn();
return mock;
Expand Down
Loading

0 comments on commit 5f72d73

Please sign in to comment.