Skip to content

Commit

Permalink
Rename patternInfo to PathPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Mar 19, 2017
1 parent f1e4ccd commit 07acc0c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
30 changes: 8 additions & 22 deletions packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Options = {|
lastCommit?: boolean,
|};

export type PatternInfo = {|
export type PathPattern = {|
input?: string,
findRelatedTests?: boolean,
lastCommit?: boolean,
Expand Down Expand Up @@ -219,31 +219,17 @@ class SearchSource {
});
}

getTestPaths(patternInfo: PatternInfo): Promise<SearchResult> {
if (patternInfo.onlyChanged) {
return this.findChangedTests({lastCommit: patternInfo.lastCommit});
} else if (patternInfo.findRelatedTests && patternInfo.paths) {
return Promise.resolve(
this.findRelatedTestsFromPattern(patternInfo.paths),
);
} else if (patternInfo.testPathPattern != null) {
return Promise.resolve(
this.findMatchingTests(patternInfo.testPathPattern),
);
getTestPaths(pattern: PathPattern): Promise<SearchResult> {
if (pattern.onlyChanged) {
return this.findChangedTests({lastCommit: pattern.lastCommit});
} else if (pattern.findRelatedTests && pattern.paths) {
return Promise.resolve(this.findRelatedTestsFromPattern(pattern.paths));
} else if (pattern.testPathPattern != null) {
return Promise.resolve(this.findMatchingTests(pattern.testPathPattern));
} else {
return Promise.resolve({paths: []});
}
}

static getTestPathPattern(patternInfo: PatternInfo): string {
const pattern = patternInfo.testPathPattern;
const input = patternInfo.input;
const formattedPattern = `/${pattern || ''}/`;
const formattedInput = patternInfo.shouldTreatInputAsPattern
? `/${input || ''}/`
: `"${input || ''}"`;
return input === pattern ? formattedInput : formattedPattern;
}
}

module.exports = SearchSource;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
'use strict';

import type {PatternInfo} from '../SearchSource';
import type {PathPattern} from '../SearchSource';

const {clearLine} = require('jest-util');
const chalk = require('chalk');
Expand All @@ -33,7 +33,7 @@ const showTestPathPatternError = (testPathPattern: string) => {
);
};

module.exports = (argv: Object): PatternInfo => {
module.exports = (argv: Object): PathPattern => {
if (argv.onlyChanged) {
return {
input: '',
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/lib/setState.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
'use strict';

const getTestPathPatternInfo = require('./getTestPathPatternInfo');
const getTestPathPattern = require('./getTestPathPattern');

module.exports = (argv: Object, mode: 'watch' | 'watchAll', options?: {}) => {
options = options || {};
Expand All @@ -36,7 +36,7 @@ module.exports = (argv: Object, mode: 'watch' | 'watchAll', options?: {}) => {
}

argv.onlyChanged = false;
argv.onlyChanged = getTestPathPatternInfo(argv).input === '' &&
argv.onlyChanged = getTestPathPattern(argv).input === '' &&
!argv.watchAll &&
!argv.testNamePattern;

Expand Down
38 changes: 28 additions & 10 deletions packages/jest-cli/src/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import type {Context} from 'types/Context';
import type {Test} from 'types/TestRunner';
import type {PatternInfo} from './SearchSource';
import type {PathPattern} from './SearchSource';
import type TestWatcher from './TestWatcher';

const fs = require('graceful-fs');
Expand All @@ -20,21 +20,34 @@ const SearchSource = require('./SearchSource');
const TestRunner = require('./TestRunner');
const TestSequencer = require('./TestSequencer');

const getTestPathPatternInfo = require('./lib/getTestPathPatternInfo');
const getTestPathPattern = require('./lib/getTestPathPattern');
const chalk = require('chalk');
const {Console, formatTestResults} = require('jest-util');
const getMaxWorkers = require('./lib/getMaxWorkers');
const path = require('path');
const setState = require('./lib/setState');

const getTestSummary = (argv: Object, pattern: PatternInfo) => {
const testPathPattern = SearchSource.getTestPathPattern(pattern);
const formatTestPathPattern = pattern => {
const testPattern = pattern.testPathPattern;
const input = pattern.input;
const formattedPattern = `/${testPattern || ''}/`;
const formattedInput = pattern.shouldTreatInputAsPattern
? `/${input || ''}/`
: `"${input || ''}"`;
return input === testPattern ? formattedInput : formattedPattern;
};

const getTestSummary = (
pattern: PathPattern,
testPathPattern: string,
testNamePattern: string,
) => {
const testInfo = pattern.onlyChanged
? chalk.dim(' related to changed files')
: pattern.input !== '' ? chalk.dim(' matching ') + testPathPattern : '';

const nameInfo = argv.testNamePattern
? chalk.dim(' with tests matching ') + `"${argv.testNamePattern}"`
const nameInfo = testNamePattern
? chalk.dim(' with tests matching ') + `"${testNamePattern}"`
: '';

return chalk.dim('Ran all test suites') +
Expand All @@ -57,7 +70,7 @@ const getNoTestsFoundMessage = (testRunData, pattern) => {

const pluralize = (word: string, count: number, ending: string) =>
`${count} ${word}${count === 1 ? '' : ending}`;
const testPathPattern = SearchSource.getTestPathPattern(pattern);
const testPathPattern = formatTestPathPattern(pattern);
const individualResults = testRunData.map(testRun => {
const stats = testRun.matches.stats || {};
const config = testRun.context.config;
Expand Down Expand Up @@ -104,7 +117,7 @@ const getTestPaths = async (context, pattern, argv, pipe) => {
setState(argv, 'watchAll', {
noSCM: true,
});
pattern = getTestPathPatternInfo(argv);
pattern = getTestPathPattern(argv);
data = await source.getTestPaths(pattern);
} else {
localConsole.log(
Expand All @@ -130,7 +143,7 @@ const runJest = async (
onComplete: (testResults: any) => void,
) => {
const maxWorkers = getMaxWorkers(argv);
const pattern = getTestPathPatternInfo(argv);
const pattern = getTestPathPattern(argv);
// TODO
const context = contexts[0];
const testRunData = await Promise.all(
Expand Down Expand Up @@ -195,7 +208,12 @@ const runJest = async (
const results = await new TestRunner(
context.config,
{
getTestSummary: () => getTestSummary(argv, pattern),
getTestSummary: () =>
getTestSummary(
pattern,
formatTestPathPattern(pattern),
argv.testNamePattern,
),
maxWorkers,
},
startRun,
Expand Down

0 comments on commit 07acc0c

Please sign in to comment.